Configure the IK tokenizer and solrik tokenization in SOLR.
It's another day. Today, let's write about how to configure the IK tokenizer in SOLR. If you don't talk much about it, let's go to the text below.
As we all know, the support of foreigners for Chinese is more or less complicated, and solr is no exception. But even in the dark era, SOLR is just a tool, therefore, solr still has a solution to support Chinese characters, that is, to configure our own word divider. The one I want to configure is the IK word divider, there are many other word splitters on the Internet, but I have never used them. I used IK word splitters in my exercises. So let's write down how to configure IK word splitters.
First, you need to download the compression package of the IK tokenizer. I downloaded this version. If it is another version, you can try it by yourself. After the download is complete, the decompressed directory is as follows:
Next, add the decompressed IKAnalyzer2012FF_u1.jar to the apache-tomcat-7.0.63 \ webapps \ solr \ WEB-INF \ lib folder, and then create the classes folder under the WEB-INF directory, if yes, you do not need to create a new one. cfg. xml and stopword. copy the dic file to the classes folder as follows:, log4j. properties is the log file of solr, regardless of it.
Step 3: Open the SOLR_HOME \ collection1 \ conf directory, open the shema. xml file, and add the following code:
Step 4: Modify the field that requires a word divider and change its type to text_ik, as shown below:
Pay attention to the two places I circled and wait for a comparison to see the effect of the word generator.
Step 5: start tomcat and go to the http: // localhost: 8080/solr/#/collection1 page. Click the Analysis button under collection1. The following page is displayed:
Enter "People's Republic of China" in the Field Value box and select the userName Field of the word divider. The effect of Word Segmentation is as follows:
Then let's take a look at the userAddress field that does not use the word divider. The test result is as follows:
In the above example, we can see the gap between configuring a word divider and not configuring a word divider?
Step 6: Configure custom keywords.
After all, the word divider is a machine. It cannot be so sensitive or highly intelligent. Sometimes the words you want are not what you want, for example, the crime of "decisive water, why can't I tell what I want? What should I do at this time? Easy to do, first open your IKAnalyzer. cfg. xml file and remove the comments in the circled part:
Then add ext. dic file, and put the words you want in it, but pay attention to the format problem here, ext. dic files need to be encoded in UTF-8 without BOM format, you can use Notepad ++ to save it. The created file is as follows:
After creation, put it in the directory mentioned above, restart tomcat, or use the above two fields for testing. First, configure the userName field of the word divider. Test Result:
There is no userAddress field configured for the word divider. The test result is as follows:
It is obvious that the difference between the configuration tokenizer and the configuration tokenizer is not configured. Then someone will say that you are here to test the analyzer. What is the relationship with solr? Yes. After you configure the tokenizer for the field to be segmented, solr will automatically split your field content during your query, for example, if you want to query userName, solr will first split the three words, for example, three words, for example, three words, then, solr uses the separated three words to perform a fuzzy query on the username field in the index you created, and finally returns all the results that meet the conditions.
OK. Let's talk about the word divider today. Tomorrow we will start to talk about how solr creates indexes for multiple tables, including non-associated tables and associated tables. Well, that's it today.