Solr analyzer and business fields, solr Analyzer
This article uses Centos6.5 64-bit solr4.10.3 IK-Analyzer Chinese Analyzer
1. Configure the Chinese Analyzer
The default solr analyzer is a Chinese analyzer and needs to be manually configured. Configure a FieldType and specify the Chinese analyzer in FieldType.
1. Use the IK-Analyzer Chinese Analyzer to upload the Analyzer file to the server/opt/tools/IK Analyzer 2012FF_hf1
2. Add the jar package (IKAnalyzer2012FF_u1.jar) of the analyzer to the solr project.
[Root @ localhost IK Analyzer 2012FF_hf1] # cp IKAnalyzer2012FF_u1.jar/usr/local/solr4/tomcat 7/webapps/solr/WEB-INF/lib/
3. Copy the extended dictionary and deprecated word dictionary and configuration file required by IKAnalyzer to the classpath of the solr project.
(1) Create the classes directory in usr/local/solr4/tomcat7/webapps/solr/WEB-INF/directory [root @ localhost WEB-INF] # mkdir classes
(2) copy the file [root @ localhost IK Analyzer 2012FF_hf1] # cp IKAnalyzer. cfg. xml ext_stopword.dic mydict. dic/usr/local/solr4/tomcat7/webapps/solr/WEB-INF/classes
Ext_stopword.dic: Extended Word Dictionary
Mydict. dic: deprecated Word Dictionary
Note: The character set of extended dictionary and deprecated dictionary must be UTF-8. Cannot be edited using windows notepad.
4. Configure fieldType. It must be configured in solrhome/collection1/conf/schema. xml. Tip: Use vi and vim to jump to the beginning of the document gg. Jump to the end of the document: G
Add fieldType at the end of the file
<fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/></fieldType>
Name = "text_ik": an identifier can be written at will.
Class = "solr. TextField": Analyzer
2. Configure business fields
The fields in Solr must be defined first and then used. This configuration should be associated with our actual business.
Criteria for determining business fields:
1. Do you need to search for this field during search. For example: product name, selling point, product description
2. Do you need this field for future businesses. For example, the product id.
Fields required for this project:
1. Product id
2. Product title
3. selling point sell_point
4. price
5. product image
6. product category name category_name
7. Item Description item_des
Add the business field in Solr to solrhome/collection1/conf/schema. xml:
Id -- Item id
Create solr fields for other fields.
<Field name = "item_title" type = "text_ik" indexed = "true" stored = "true"/> <field name = "item_sell_point" type = "text_ik" indexed = "true ""stored =" true "/> <field name =" item_price "type =" long "indexed =" true "stored =" true "/> <field name =" item_image "type = "string" indexed = "false" stored = "true"/> <field name = "item_category_name" type = "string" indexed = "true" stored = "true"/> <field name = "item_desc" type = "text_ik" I Ndexed = "true" stored = "false"/> <! -- Create a replication domain and copy the search keywords from other domains to one domain. This is solr's optimization for search. -->
<Field name = "item_keywords" type = "text_ik" indexed = "true" stored = "false" multiValued = "true"/> <copyField source = "item_title" dest = "item_keywords "/> <copyField source =" item_sell_point "dest =" item_keywords "/> <copyField source =" item_category_name "dest =" item_keywords "/> <copyField source =" item_desc "dest = "item_keywords"/>
The fields that write data to the index database must be the same as the configuration.
Restart tomcat