solr 7.2.1版本managed-schema文件示例
<uniqueKey>id</uniqueKey>
唯一键字段,solr对每一个文档都赋予一个唯一标识符字段,避免产生重复索引,
我们可以将不重复且不变的字段设置为solr索引文档的主键
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <!-- docValues are enabled by default for long type so we don't need to index the version field --> <field name="_version_" type="plong" indexed="false" stored="false"/> <field name="_root_" type="string" indexed="true" stored="false" docValues="false" /> <field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field></field>代表索引文档的字段, name属性为字段名称(该名称唯一), type字段为该字段索引解析所用的分词器,
indexed为是否进行索引, stored为是否储存该字段的值用于日后的查询, multiValued为该字段是否有多个值
<dynamicField name="*_i" type="pint" indexed="true" stored="true"/> <dynamicField name="*_is" type="pints" indexed="true" stored="true"/> <dynamicField name="*_s" type="string" indexed="true" stored="true" /> <dynamicField name="*_ss" type="strings" indexed="true" stored="true"/> <dynamicField name="*_l" type="plong" indexed="true" stored="true"/>
<dynamicField>与field意义相同,但其代表的是动态字段
动态字段:如果几个字段的属性处理name值不同,type indexed stored 等属性完全相同,
则可以只配置一个动态字段以减少配置,动态字段以*_开头或以_*结尾,例如*_s s_*
当配置了
<dynamicField name="*_s" type="string" indexed="true" stored="true" />
时传入 name1_s 和 name2_s 两个字段的名称则都会匹配
但其在查询时必须明确指定字符串的字段
<field name="queryFieldCopy" type="text_en" indexed="true" stored="false" multiValued="true" /> <copyField source="_text_" dest="queryFieldCopy"/> <copyField source="_root_" dest="queryFieldCopy"/>
<copyField> 复制字段,solr的复制字段允许将一个或多个字段值填充到一个字段中
将多个字段内容填充到一个字段
对同一字段内容进行不同的文本分析,创建一个新的可搜索字段
source为源字段 dest为目标字段
即将_text_字段和_root_字段复制到了queryFieldCopy字段,那么在对queryFieldCopy字段的搜索就相当于搜索了_text_和_root_两个字段
<fieldType name="text_en" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory"/> <!-- in this example, we will only use synonyms at query time <filter class="solr.SynonymGraphFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/> <filter class="solr.FlattenGraphFilterFactory"/> --> <!-- Case insensitive stop word removal. --> <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" /> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.EnglishPossessiveFilterFactory"/> <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/> <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory: <filter class="solr.EnglishMinimalStemFilterFactory"/> --> <filter class="solr.PorterStemFilterFactory"/> </analyzer>
<analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.SynonymGraphFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt" /> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.EnglishPossessiveFilterFactory"/> <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/> <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory: <filter class="solr.EnglishMinimalStemFilterFactory"/> --> <filter class="solr.PorterStemFilterFactory"/> </analyzer> </fieldType>
Solr 分析器被指定为 schema.xml 配置文件中的<fieldType>元素的子元素(在与 solrconfig. xml 相同的 conf/ 目录中)。