SOLR and. NET Series courses (ii) SOLR's configuration file and its implications

Source: Internet
Author: User
Tags solr

SOLR and. NET Series courses (ii) SOLR's configuration file and its implications

This section will not cover the contents of. NET and database, but do not worry, this is the school hours SOLR must learn what to master, SOLR is not like other DLL files, just need to refer to the method and data can be recalled, you do not configure is not used, the first two sections are mainly for the role of the cushion, It's going to be boring.

This chapter is for the next section to connect to the database to prepare, a single take out to see, it will make people very confused, it's okay, when the preview, know that there is such a thing on the line, and so the next section of the database after the good understanding

In the previous section we have completed the basic configuration of SOLR, here we come to the SOLR configuration file, mentioned before, SOLR's main step is to configure, direct configuration files, many people do not touch the look will be very difficult, this need to combine the link database speak to understand, but the article to step by step write, For those who have been in touch with SOLR, then there is no problem, here will provide you with as much detail as possible to explain the configuration, new people can first understand, and so the next section began to explain the link database is easy to understand.

(i) First list several important configuration file names for SOLR

1.solr.xml (multiple)

2.server.xml (Tomcat file)

3. Schema.xml

4. Solrconfig.xml

5. Data-config.xml (Link database configuration file, you need to create it yourself)

So let's start by explaining the configuration files.

(1) Solr.xml

This file mainly has two places, the first place is created manually in the previous section of our configuration in Solr, the forgotten friends can go back to see, this file is mainly to establish the relationship between Tomcat and SOLR, its role is to let Tomcat find your configured SOLR. The code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><context docbase= "C:\Program files\apache software Foundation\tomcat 7.0\webapps\solr.war "debug=" 0 "crosscontext=" true ">  <environment name=" Solr/home "type=" Java.lang.String "value=" C:\Program files\apache software foundation\tomcat 7.0\solr "override=" true "/></ Context>

The second solr.xml is located in C:\Program files\apache software Foundation\tomcat 7.0\SOLR, which comes with the Solr file (which is the folder we copied to Tomcat under the previous section), Let's take a look at his code.

<solr>  <solrcloud>    <str name= "host" >${host:}</str>    <int name= "Hostport" >${jetty.port:8983}</int>    <str name= "Hostcontext" >${hostContext:solr}</str>    < int name= "Zkclienttimeout" >${zkClientTimeout:30000}</int>    <bool name= "Genericcorenodenames" >$ {genericcorenodenames:true}</bool>  </solrcloud>  <shardhandlerfactory name= " Shardhandlerfactory "    class=" httpshardhandlerfactory ">    <int name=" Sockettimeout ">${ sockettimeout:0}</int>    <int name= "conntimeout" >${connTimeout:0}</int>  </ Shardhandlerfactory></solr>

This file is used to configure SOLR single core and multicore mode (multi-core mode means to configure multiple SOLR under the same server), the above is the single core mode, no need to make any changes (multi-core needs to be modified), he default to match the folder under the Collection1 folder, The other configuration files are in this folder, this section we mainly explain the single core mode, the single core mode understanding, multi-core mode is easy to understand. (Multicore in the next section, after all, is a tutorial, need to start from a simple beginning)

(2) Server.xml

This file is a configuration file under Tomcat, located in C:\Program files\apache software foundation\tomcat 7.0\conf, check the file under this code:

  <connector port= "8080" protocol= "http/1.1"               connectiontimeout= "20000"               redirectport= "                8443" uriencoding= "UTF-8"/>

If there is no uriencoding= "UTF-8", SOLR in the query may appear garbled, it may lead to find things.

(3) Schema.xml

This file is SOLR in the more important files, SOLR in the index configuration is written in this file, the contents of the file because too many, can not be shown in the article, learning to open their own this file and the article to learn, s on the previous section of SOLR is copied here, Let's take a look at some of the code that comes with it.

1.types Node

  <types>    <fieldtype name= "string" class= "SOLR. Strfield "sortmissinglast=" true "/>    <fieldtype name=" boolean "class=" SOLR. Boolfield "sortmissinglast=" true "/>    <fieldtype name=" binary "class=" SOLR. Binaryfield "/>    <fieldtype name=" int "class=" SOLR. Trieintfield "precisionstep=" 0 "positionincrementgap=" 0 "/>    <fieldtype name=" float "class=" SOLR. Triefloatfield "precisionstep=" 0 "positionincrementgap=" 0 "/>    <fieldtype name=" Long "class=" SOLR. Trielongfield "precisionstep=" 0 "positionincrementgap=" 0 "/>    <fieldtype name=" Double "class=" SOLR. Triedoublefield "precisionstep=" 0 "positionincrementgap=" 0 "/>   ......................<!--omitted-- </type>  

This is the data type supported in SOLR, which matches most of the types contained in the database, which we use when we configure the index, which defines some parameters such as the FieldType child node, including Name,class,positionincrementgap.

Name: This is the FieldType.

class: Refers to the class name in the Org.apache.solr.analysis package that defines the behavior of this type (the parser that corresponds to that name).

Optional properties:

The sortmissinglast and Sortmissingfirst Two properties are used on types that can be sorted internally using string (including: String,boolean,sint,slong, Sfloat,sdouble,pdate).

sortmissinglast= "true", no data for the field is queued after the data for that field, regardless of the collation of the request. Value is set to False by default

Sortmissingfirst= "true", followed by the upside-down chant. Value is set to False by default

2. Fieldsnode

(1) Field sub-node

<fields> <field name= "_version_" type= "Long" indexed= "true" stored= "true"/> <!--points to the RO OT document of a block of nested documents. Required for nested document support, could be removed otherwise-to <field name= "_root_" type= "string" index Ed= "true" stored= "false"/> <!--only remove the ' id ' field if you had a very good reason to. While isn't strictly required, it is highly recommended. A <uniqueKey> is present in almost all SOLR installations.   See the <uniqueKey> declaration below where <uniqueKey> was set to "id".            --<field name= "id" type= "string" indexed= "true" stored= "true" required= "true" multivalued= "false"/> <field name= "SKU" type= "Text_en_splitting_tight" indexed= "true" stored= "true" omitnorms= "true"/> <field n Ame= "name" type= "Text_general" indexed= "true" stored= "true"/> <field name= "Manu" type= "Text_general" indexed= " True "stored=" true "omitnorms=" trUE "/>.........................<!----omitted-></fields>     

Define a specific field (a database-like field) that contains the following properties:

name: Field name

type: Various FieldType that have been previously defined

indexed: whether it is indexed

stored: Whether it is stored (set to False if you do not need to store the corresponding field value)

multivalued: If there are multiple values (set to True for fields that may have multiple values, avoid throwing an error when indexing is being built)

This is the place to configure the index , what the meaning of the data stored in the database is under the existence of the field , such as Id,name, in SOLR also need to have a field to store it ah , the above name is stored name , can be casually up , in the Data-conf.xml (next session) file will have a database and SOLR mapping table.

(2)Copy fields sub-bytes

  <copyfield source= "Cat" dest= "text"/>   <copyfield source= "name" dest= "text"/>   <copyfield Source= "Manu" dest= "text"/>

This code is also in <types></types>, copy the field, is to combine two fields into a field, for example:

<schema name= "eshequn.post.db_post.0" version= "1.1" xmlns:xi= "Http://www.w3.org/2001/XInclude"      >       <fields>          <!--for title---          <field name= "T" type= "text" indexed= "true" stored= "false"/>          <!--for abstract-          <field name= "A" type= "text" indexed= "true" stored= "false"/>          <!-- For title and abstract-          <field name= "ta" type= "text" indexed= "true" stored= "false" multivalued= "true"/ >      </fields>      <copyfield source= "T" dest= "ta"/>      <copyfield source= "a" dest= "ta"/ >  </schema>

Paragraph T is the title of the article, field A is a summary of the article, the field TA is the article title and summary of the Union. When you add an indexed document, you only need to pass in the contents of the T and a fields, and SOLR automatically indexes the TA fields. This is not much of an advanced feature, but what would you do if you were to implement it? I took over the search system originally has a similar function, it is the practice of the T and a field of the text merge, plug into the TA field, it is understandable practice. However, it has been noted that Lucene's document class provides a public final field[] GetFields (String name) like a function? That is, a name in Lucene can correspond to more than one field. When Solr adds an index, it checks that field name is the source in the Copyfield collection, and then constructs the Dest field with its value. If the dest is composed of more than one source, it needs to be specified as multivalued.

For queries, if the query field is to come from more than one field, one option is to use Copyfield to make multiple fields a field, and the disadvantage is that the difference in the importance of each field cannot be distinguished. For example, the title and abstract of the article, the title is more important than the summary, if there is such a requirement, you can choose the practice of querying multiple fields.

(3) DynamicField

  <dynamicfield name= "*_i"  type= "int"    indexed= "true"  stored= "true"/>   <dynamicfield name= " *_is "type=" int "    indexed=" true "  stored=" true "  multivalued=" true "/>   <dynamicfield name=" *_s "  type=" string "  indexed=" true "  stored=" true "/>   <dynamicfield name=" *_ss "type=" string "  indexed= "true"  stored= "true" multivalued= "true"/>

Dynamic fields allows SOLR indexes to have no fields that are explicitly defined in the schema. This is useful when you forget to define some fields. Dynamic fields can make the system more flexible and more versatile. A dynamic field is similar to a regular field, except that it contains a wildcard character that, when indexed, matches a field in a dynamic field if there is no match in the regular field. Suppose the schema defines a dynamic dynamic field called *_i, if you want to index a field called cost_i, but there is no cost_i field in the schema, so cost_i is indexed into the *_i field. The dynamic field is also defined in the Schema.xml file, and as with other fields, it also has a noun, field type, and attributes. It is recommended to define some basic dynamic fields in schema.xml for extension purposes.

(4) Some other tags

< UniqueKey > ID </uniquekey >

The unique identification of the document (that is, the primary key, SOLR is to store the data in a file, of course, must have a primary key), must fill in this field (unless the field is marked Required= "false"), otherwise SOLR indexed error.

< Defaultsearchfield > text </Defaultsearchfield >

If no specific field is specified in the search parameters, this is the default domain.

< Solrqueryparser Defaultoperator = " OR "/>

Configures the logic between search parameter phrases, which can be "and|or".

solrconfig.xml and data-config.xml are linked database files, next lesson we will explain, SOLR connection Sqlsevrer database, these two files we will explain together in the next section,

The above content is to link the database to do the preparation work, the next section, we will explain what we really care about the SOLR actual stage

SOLR and. NET Series courses (ii) SOLR's configuration file and its implications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.