Running SOLR is a simple task. It is not easy to make SOLR run your project efficiently. There are too many factors to consider. It is important to understand SOLR configurations. Understand the meaning of each configuration item in the configuration file!
In SOLR, schema. xml and solrconfig. xml under the SOLR main directory are used. If you have read the first two articlesArticleYou should know where the SOLR home directory is (C: \ SOLR-Tomcat \ SOLR \ conf \).
In this article, we will first talk about this schema. xml.
Schema. XML, which is equivalent to the data table configuration file, which defines the data type of the data to be indexed. It mainly includes types, fields, and other default settings.
1. Define a fieldtype subnode in the types node, including parameters such as name, class, and positionincrementgap. Name is the name of fieldtype, and class points to Org. apache. SOLR. the class name corresponding to the analysis package, used to define this type of behavior. When fieldtype is defined, the most important thing is to define the analyzer used to index and query data of this type, including word segmentation and filtering. In this example, the fieldtype text is defined and SOLR is used in the index analyzer. whitespacetokenizerfactory is a space word segmentation package, and then SOLR is used. stopfilterfactory, SOLR. worddelimiterfilterfactory, SOLR. lowercasefilterfactory, SOLR. englishporterfilterfactory, SOLR. removeduplicatestokenfilterfactory filters. When a text index is added to the index library, SOLR first uses spaces for word segmentation, and then filters the word segmentation results using the specified filter in sequence, the remaining results will be added to the index database for query. The analysis package of SOLR does not contain a package that supports Chinese characters. The second article details how to add a paoding Chinese Word divider. For more information, see http://lianj-lee.javaeye.com/blog/424474.
2. The next step is to define a specific field (similar to a field in a database) in the fields node, that is, filed. The filed definition includes name, type (defined previously), indexed (indexed or not), stored (stored or not), multivalued (whether there are multiple values), and so on.
Example: XML Code
- <Fields>
-
- <Field Name="ID" Type="Integer" Indexed="True" Stored="True" Required="True" />
- Field name = "name" type = "text" indexed = " true " stored = "true" />
- Field name = "summary" type = "text" indexed = " true " stored = "true" />
- Field name = "author" type = "string" indexed = " true " stored = "true" />
- Field name = "date" type = "date" indexed = " false " stored = "true" />
- Field name = "content" type = "text" indexed = " true " stored = "false" />
- Field name = "keywords" type = "keyword_text" indexed = " true " stored = "false" multivalued = "true" />
- <Field Name="All" Type="Text" Indexed="True" Stored="False" Multivalued="True"/>
-
- </Fields>
<Fields> <field name = "ID" type = "integer" indexed = "true" stored = "true" required = "true"/> <field name = "name" Type = "text" indexed = "true" stored = "true"/> <field name = "summary" type = "text" indexed = "true" stored = "true"/> <field name = "author" type = "string" indexed = "true" stored = "true"/> <field name = "date" type = "date" indexed = "false "Stored =" true "/> <field name =" content "type =" text "indexed =" true "stored =" false "/> <field name =" keywords "Type = "keyword_text" indexed = "true" stored = "false" multivalued = "true"/> <field name = "all" type = "text" indexed = "true" stored = "false" multivalued = "true"/> </fields>
Field definition is very important. There are several tips to note that you should try to set the multivalued attribute to true for multiple worthwhile fields to avoid index creation errors; if you do not need to store the corresponding field values, set the stored attribute to false.
3 "it is recommended that a copy field be created to copy all full-text fields to one field for unified search: XML Code
- <Field Name="All" Type="Text" Indexed="True" Stored="False" Multivalued="True"/>
<Field name = "all" type = "text" indexed = "true" stored = "false" multivalued = "true"/>
complete the copy settings at the copy field node: XML Code
- <Copyfield Source="Name" Dest="All"/>
- <Copyfield Source="Summary" Dest="All"/>
<Copyfield source = "name" DEST = "all"/> <copyfield source = "summary" DEST = "all"/>
4. Dynamic fields can also be defined. Dynamic fields do not need to be specified. As long as the rules for field names are defined, for example, a dynamicfield with name * _ I, define its type as text, so when using this field, any field ending with _ I is considered to comply with this definition, for example: name_ I, gender_ I, school_ I.
The schema. xml configuration file is basically like this. For more details, see SOLR wiki http://wiki.apache.org/solr/schemaxml. If you have time later, I will update this article on a regular basis to facilitate more beginners.