solr6.x配置文件managed-schema说明

solr6.x配置文件managed-schema说明

标签(空格分隔): solr


solr6.x配置文件managed-schema说明
参考博客

一、field

定义Solr索引的document里的字段,这个一般是根据具体的搜索应用来定义需要有什么字段。有三个特殊一点的字段,分别是:”version“, “root” 和 “id”

  1. <field>中的属性
属性默认值说明
name必须
type必须,值为定义的<fieldType>
indexedtrue是否进行索引。 true的时候进行索引
storedtrue是否存储。如果此字段的值需要显示在搜索结果中,则需要进行存储。
docValuesfalse是否需要存储docValues。true为设置。docValues用于提升sorting, faceting, grouping, function queries等性能,现在仅支持StrField, UUIDFiel和所有的Trie*Field,此值为true的字段要求此字段multiValued=false,并且 (required=true或设置了default的值).
multiValuedfalse是否有多个值
omitNorms如果你的大部分的document的长度大小都差不多,则设置成true。如果此字段在索引时需要boost,则设置为false.
termVectorsfalse设置为true,使More Like This特性生效,会极大的增加索引文件的大小
termPositionsfalse通常用于提高高亮搜索结果这一功能的性能。设置为true,会增加索引文件的大小
termOffsetsfasle通常用于提高高亮搜索结果这一功能的性能。设置为true,会增加索引文件的大小
termPayloadsfasle通常用于提高高亮搜索结果这一功能的性能。设置为true,会增加索引文件的大小
requiredfasle如果设置为true,则索引时,如果此字段值为null,则会报错
default此字段是默认字段

2. 对一些属性说明:

  • omitNorms:

        norm是基于document length norm,document boost和field boost计算出的浮点(float)值。这里的boost可以理解为权重。document length norm用于为较小的document增加权重(权重较大的话,计算搜索结果的score值会更高一点)。也就是说如果有一个比较小的document和一个比较长的document都符合搜索条件,Lucene会认为那个较小的document相对于较长的document更新符合搜索条件。omitNorms是指忽略norm,所以设为false时,较小的document和较长的document有相同的权重。因此如果我们需要为某个字段在索引时进行加权(boost),则应该设置为false。当字段类型为基本类型(比如:int, float,date,bool. string)时此默认值是true。
    
  • termVectors, termPositions, termOffsets 和 termPayloads

    此四个属性通常用于 hl.useFastVectorHighlighter为true时的情况。
    

二、 <dynamicField>

    为满足前辍或后辍的一些字段提供统一的定义。如<dynamicField name="*_s" index="true" stored="true" type="string" /> 表示所有以“_s”为后辍的field都具有index="true" stored="true" type="string" 这些属性。dynamicField通常用于以下情形:
  1. document模型具有较多的字段

    想要索引PDF文件,Solr提供了一个简单的requestHandler--/update/extract,最终会调用Apache的另外开源项目Tika去解析pdf文件,Solr返回的解析后的document里包含了很多field,我们只想要其中的某些field,如果我们在<field>里只配置了我们想要的field,那么进行索引的时候会报错,错误消息大体为没有定义什么什么field,这时,我们可以配置一个<dynamicField name="ignore_*" type="ignored" multiValued="true">,然后在solrconfig.xml里相应的requestHandler里配置<str name="uprefix">ignore_</str>,这样对于在managed-schema里没定义的field都会被忽略掉。
    
  2. 支持来自不同来源的文档

    //比如索引的时候想要增加标注其来源的field,可以进行如下的配置:
    
             <field name="source1_field1" type="string" index="true" stored="true" />
    
             <field name="source1_field2" type="string" index="true" stored="true" />
            ...
             <field name="source2_field1" type="string" index="true" stored="true" />
    
             <field name="source2_field2" type="string" index="true" stored="true" />
    
    //但是如果有很多来源的话,这种配置就太多了。我们只须配置
    //<dynamicField name="*_s" index="true" stored="true"     
    //type="string" />,然后索引的时候改成:
    
            <doc>
                <field name="id">hello</field>
                <field name="source1_field1_s">hello</field>
            </doc>
    
    //这样,索引时的field名既可以保留来源的信息,又不需要在配置文件里配置很多的field定义。
  3. 增加新的文档来源

     还是上面的例子,如果将来有新的文档来源,我们可以不必在配置文件里增加诸如 <field name="source5_field1" type="string" index="true" stored="true" />这样的配置,就可以直接在索引的时候添加“source5_field1_s”这样的字段。
    

三、<uniqueKey>

     一般情况下需要配置<uniqueKey>id</uniqueKey>,虽然目录不是必须的,但是强烈建议设置此值。就好像数据库设计时,虽然不强制每个表有主键,但是一般情况下还是会设置一个主键的。

四、<copyField>

     用百度或google搜索时,我们可能想要搜索一个人名,或者书名,或者网站的名字,其后台索引文件里分别由不同的field去保存那些值,那它是如何用一个输入框去搜索不同的field的内容的呢?答案就是<copyField>
 <field name="text" type="string" index="true" stored="true" multiValues="true" />

<copyField source="man_name" dest="text" />

<copyField source="book_name" dest="text" />

<copyField source="web_address" dest="text" />

//这样我们就只需要搜索text里的内容就可以了。

五、<fieldType>

     fieldType主要定义了一些字段类型,其name属性值用于前面<field>中的type属性的值。e.g. <fieldType name="string" class="solr.StrField" sortMissingLast="true" /> 其中class属性中"solr"是org.apache.solr.schema这个包名的缩写。

fieldType的属性:

    1)name  由字母、数字和下划线组成。不能以数字开头。此值用于前面<field>中的type属性的值。

    2)class  此值表明索引并存储此fieldType的数据的类型(e.g 字符类型,数字类型,日期类型...)。如果此类不是solr提供的(自定义的或第三方的类),则不能用"solr.",需要写类的全路径名。

    3)positionIncrementGap 值为整数,用于multiValued="true"的字段,指定多个值之间的距离,以防出现假的短语匹配。

  比如描述书本作者的字段是有多个值的,假设有两个作者:John Smith 和 Mike Jackson,我们搜索"Smith Mike"这个作者,如果positionIncrementGap值设成0,则此记录就会被认为是匹配搜索条件的,实际上是不匹配的。对于这种情况,我们应该把此值设置成一个较大的值,比如100。

    4) autoGeneratePhaseQueries 值为布尔类型。默认值为false。设为true时,会自动生成短语查询。

  例如:索引中的文本内容为:春花秋月何时了...一江春水向东流。    我们在搜索的输入框里输入"春花"(注意不输入两个双引号),如果autoGeneratePhaseQueries 为true,我们加上highlight的话,返回的匹配结果为: <em>春花</em>春花秋月何时了...一江春水向东流。     如果值为false,则返回结果为<em>春</em><em>花</em>春花秋月何时了...一江<em>春</em>水向东流。

  如果值为false,我们还是想要进行短语查询,可在输入框里输入"春花"(注意需要加上两个双引号)。

     5)docValuesFormat 自定义docValues的格式。设置此值的话,必须在solrconfig.xml里配置Schema codecFactory。如:

    <codecFactory class="solr.SchemaCodecFactory" />

     6)postingsFormat 对该种域类型定义种类自定义的postingsFormat数据类型。设置此值的话,必须在solrconfig.xml里配置SchemacodecFactory。

    以下的属性也同时存在于<field>里,如果<field>里的值会覆盖<fieldType>里的值。

    7)indexed 布尔值。true表示进行索引。

    8)stored 布尔值。true表示进行存储。

    9)docValues 布尔值。true表示field的值将会被存储于面向列的数据结构中。

    10)sortMissingFirst 布尔值。true表示排序的时候,此field值为空的记录排在此field值不为空的记录的前面。

    11)sortMissingLast 布尔值 。意思和sortMissingFirst相反。

    12)multiValues 布尔值。

    13)omitNorms 布尔值。

    14)omitTermFreqAndPositions 布尔值。忽略term frequency, positions 和 payloads。所有非文本类型字段,此默认值是true。

    15)omitPositions 布尔值。布尔值。忽略positions。

    16)termVectors, termPositions, termOffsets 和 termPayloads 布尔值。

    17)required 布尔值。

    18)useDocValuesAsStored 布尔值。

样例

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="example" version="1.6">
  <!-- 字段名由字母数字和下划线组成,不能以数字开头。以下划线开头并且以下划线结尾的字段名是保留字段名(e.g. _version_)-->

   <!-- 如果去除此字段,必须同时去掉solrconfig.xml中的update log。
    _version_ and update log 在SolrCloud中是必须的。
    作用类似于hibernate中的version字段,用于乐观锁。--> 

   <field name="_version_" type="long" indexed="true" stored="false" />

   <!-- 如果document中内嵌document,此需要此字段。用于内嵌的document指向其父document. -->

   <field name="_root_" type="string" indexed="true" stored="false" docValues="false" />

   <!-- 除非你有很充足的理由,否则不要去除"id"字段.不要改变type属性, 不要对<uniqueKey>对应的字段进行索引时分析。 -->

   <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 

   <!-- 以下定义了一些sample字段 -->
   <field name="pre" type="preanalyzed" indexed="true" stored="true"/>
   <field name="sku" type="text_en_splitting_tight" indexed="true" stored="true" omitNorms="true"/>
   <field name="name" type="text_general" indexed="true" stored="true"/>
   <field name="manu" type="text_general" indexed="true" stored="true" omitNorms="true"/>
   <field name="cat" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="features" type="text_general" indexed="true" stored="true" multiValued="true"/>
   <field name="includes" type="text_general" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />
   <field name="weight" type="float" indexed="true" stored="true"/>
   <field name="price"  type="float" indexed="true" stored="true"/>
   <field name="popularity" type="int" indexed="true" stored="true" />
   <field name="inStock" type="boolean" indexed="true" stored="true" />

   <field name="store" type="location" indexed="true" stored="true"/>

   <!-- 以下字段为解析word,PDF此类富文本所需要的字段。一些multiValued="true"的字段是因为Tika返回就是多个值。一些字段来自于客户端的上下文: 
   "content_type": 来自 HTTP headers of incoming stream
   "resourcename": From SolrCell request param resource.name
     如果你的应用不需要解析诸如此类的文本,则这些字段定义都不需要 -->

   <field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
   <field name="subject" type="text_general" indexed="true" stored="true"/>
   <field name="description" type="text_general" indexed="true" stored="true"/>
   <field name="comments" type="text_general" indexed="true" stored="true"/>
   <field name="author" type="text_general" indexed="true" stored="true"/>
   <field name="keywords" type="text_general" indexed="true" stored="true"/>
   <field name="category" type="text_general" indexed="true" stored="true"/>
   <field name="resourcename" type="text_general" indexed="true" stored="true"/>
   <field name="url" type="text_general" indexed="true" stored="true"/>
   <field name="content_type" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="last_modified" type="date" indexed="true" stored="true"/>
   <field name="links" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="_src_" type="string" indexed="false" stored="true"/>

   <!-- 以下为SolrCell解析出的word,PDF等文件的主体内容.如下定义,可用于高亮显示搜索匹配的内容 -->
   <field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/>

   <!-- 定义一个字段来包含所有可搜索的字段 (通过copyField 实现)  -->
   <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

   <!-- 定义一个字段用于正反向索引分词,有利于提高通配符搜索. -->
   <field name="text_rev" type="text_general_rev" indexed="true" stored="false" multiValued="true"/>

   <!--  不进行分词的 manufacturer, 为了更容易地对manufacturer进行排序或分组 -->
   <field name="manu_exact" type="string" indexed="true" stored="false" docValues="false" />

   <field name="payloads" type="payloads" indexed="true" stored="true"/>

   <!-- 动态字段定义,用于方便地配置所有匹配pattern的字段. 
       例如:  name="*_i" 将匹配所有以 _i 结尾的字段(如:myid_i, z_i)
       限制: "*" 必须只出现在开始或结尾 -->

   <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"/>
   <dynamicField name="*_l"  type="long"   indexed="true"  stored="true"/>
   <dynamicField name="*_ls" type="long"   indexed="true"  stored="true"  multiValued="true"/>
   <dynamicField name="*_t"  type="text_general"    indexed="true"  stored="true"/>
   <dynamicField name="*_txt" type="text_general"   indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_en"  type="text_en"    indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_b"  type="boolean" indexed="true" stored="true"/>
   <dynamicField name="*_bs" type="boolean" indexed="true" stored="true"  multiValued="true"/>
   <dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>
   <dynamicField name="*_fs" type="float"  indexed="true"  stored="true"  multiValued="true"/>
   <dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>
   <dynamicField name="*_ds" type="double" indexed="true"  stored="true"  multiValued="true"/>

   <!-- 用于索引"位置"字段类型的经度和纬度-->
   <dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false" useDocValuesAsStored="false" />

   <dynamicField name="*_dt"  type="date"    indexed="true"  stored="true"/>
   <dynamicField name="*_dts" type="date"    indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_p"  type="location" indexed="true" stored="true"/>

   <!-- 用于加快范围查询 -->
   <dynamicField name="*_ti" type="tint"    indexed="true"  stored="true"/>
   <dynamicField name="*_tl" type="tlong"   indexed="true"  stored="true"/>
   <dynamicField name="*_tf" type="tfloat"  indexed="true"  stored="true"/>
   <dynamicField name="*_td" type="tdouble" indexed="true"  stored="true"/>
   <dynamicField name="*_tdt" type="tdate"  indexed="true"  stored="true"/>

   <dynamicField name="*_c"   type="currency" indexed="true"  stored="true"/>

   <dynamicField name="ignored_*" type="ignored" multiValued="true"/>
   <dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/>

   <dynamicField name="random_*" type="random" />

   <!-- 去掉下面的注释,将会忽略所有未定义或者不匹配动态字段的字段。否则会抛错。 
   如果想把未知字段自动索引或/并存储,把type="ignored" 改成其它的类型(e.g. "text"), --> 
   <!--dynamicField name="*" type="ignored" multiValued="true" /-->

 <!-- 标识document唯一的字段   -->
 <uniqueKey>id</uniqueKey>

  <!-- copyField 用于在把documnet添加到索引时,copy一个字段的内容到另外一个字段。这样可以对相同的字段进行不同的索引,或者把多个字段copy到同一个字段以简化/加快搜索  -->

   <copyField source="cat" dest="text"/>
   <copyField source="name" dest="text"/>
   <copyField source="manu" dest="text"/>
   <copyField source="features" dest="text"/>
   <copyField source="includes" dest="text"/>
   <copyField source="manu" dest="manu_exact"/>

   <!-- 复制price到一个启用字段 (default USD) -->
   <copyField source="price" dest="price_c"/>

   <!--搜索的字段默认在我们所有配置的字段中进行搜索-->
   <copyField source="title" dest="text"/>
   <copyField source="author" dest="text"/>
   <copyField source="description" dest="text"/>
   <copyField source="keywords" dest="text"/>
   <copyField source="content" dest="text"/>
   <copyField source="content_type" dest="text"/>
   <copyField source="resourcename" dest="text"/>
   <copyField source="url" dest="text"/>

   <!-- 创建一个 string 版本的author 用于分组(facet)。例如:作者是"Mike Jackson", 则索引时,会进行分词,即把 Mike 和 Jackson 分开进行索引,但是我们进行facet搜索时,需要把Mike和Jackson作为一个整体进行搜索,这就需要把它们做为一个整体进行索引,type="string"的字段类型会对内容作为整体进行索引。 -->
   <copyField source="author" dest="author_s"/>


    <!-- "name" 属性值用于field 定义里的 type 属性值
         "class" 属性值决定了fieldType的真正行为.
        Class 以"solr"开头,表示的是java类所在包的包名缩写(比如: org.apache.solr.analysis) -->

    <!-- StrField类型的field,其值会做为一个整体进行存储或索引。如果设置了docValues为true, 则必须确保此field是单值的并且不为空。-->
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" />

    <!-- boolean type: "true" or "false" -->
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>

    <!-- 默认的数字类型。想要更快的范围搜索,考虑使用 tint/tfloat/tlong/tdouble。支持docValues,但是必须确保其单值并且不为空。      
    -->
    <fieldType name="int" class="solr.TrieIntField" docValues="true" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="float" class="solr.TrieFloatField" docValues="true" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="long" class="solr.TrieLongField" docValues="true" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="double" class="solr.TrieDoubleField" docValues="true" precisionStep="0" positionIncrementGap="0"/>

    <!-- 以下数字类型的field,将在各个精度等级保存其值,用于加快范围搜索。详见NumericRangeQuery的javadoc较小的precisionStep值意味着更细粒度的精度等级,会少量增加索引文件大小,便是范围搜索会更快precisionStep 为 0 的话,不会生成精度等级。-->
    <fieldType name="tint" class="solr.TrieIntField" docValues="true" precisionStep="8" positionIncrementGap="0"/>
    <fieldType name="tfloat" class="solr.TrieFloatField" docValues="true" precisionStep="8" positionIncrementGap="0"/>
    <fieldType name="tlong" class="solr.TrieLongField" docValues="true" precisionStep="8" positionIncrementGap="0"/>
    <fieldType name="tdouble" class="solr.TrieDoubleField" docValues="true" precisionStep="8" positionIncrementGap="0"/>

    <!-- 日期字段的格式是 1995-12-31T23:59:59Z, 这是日期时间类型更加严格和权威的表示方法
        结尾的"Z" 表示 UTC 时间,这是必须的。
        秒可以有小数部分: 1995-12-31T23:59:59.999Z
        表达示可以用来相对于"NOW"的计算值, 如...

           NOW/HOUR :精确到小时
           NOW-1DAY :比现在少一天的时间
           NOW/DAY+6MONTHS+3DAYS:现在以后的6个月再加上3天 
    -->
    <fieldType name="date" class="solr.TrieDateField" docValues="true" precisionStep="0" positionIncrementGap="0"/>

    <!-- 类似于数字类型中的说明 -->
    <fieldType name="tdate" class="solr.TrieDateField" docValues="true" precisionStep="6" positionIncrementGap="0"/>


    <!--数据必须以Base64 编码进行发送/接收 -->
    <fieldType name="binary" class="solr.BinaryField"/>


    <!-- solr.TextField 允许自定义分词器和过滤器。索引时和查询时的分词器可以不同。
      详见 http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters
     -->

    <!-- 仅使用空格分词器的fieldType -->
    <fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      </analyzer>
    </fieldType>

    <!-- 具有stopwords 和 synonyms 过滤器的标准分词器的fieldType -->
    <fieldType name="managed_en" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.ManagedStopFilterFactory" managed="english" />
        <filter class="solr.ManagedSynonymFilterFactory" managed="english" />
      </analyzer>
    </fieldType>

    <!-- 普通的文本 fieldType StandardTokenizer,移除"stopwords.txt"中指定的词(忽略大小写)-->
    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />

        <!-- 本例中,我们只在查询时应用同义词
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

    <!-- 适用于英文的field类型: StandardTokenizer, 去除英文 stop words(lang/stopwords_en.txt),转换成小写,进行词根化处理(如:stopping会被转化成stop进行索引),但是 protwords.txt中指定的词不会被转化。  -->
    <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.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <!-- 删除不区分大小写的停用词-->
        <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"/>
  <!-- 不太“狠”的方式,可以使用:PorterStemFilterFactory:
        <filter class="solr.EnglishMinimalStemFilterFactory"/>
  -->
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" 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"/>
  <!-- 不太“狠”的方式,可以使用:PorterStemFilterFactory:
        <filter class="solr.EnglishMinimalStemFilterFactory"/>
  -->
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>

    <!-- 下面的fieldType只是比上面的"text_en"多加了一个WordDelimiterFilter。WordDelimiterFilter的作用是把大小写有变化的词、数字和字母组合的词分开索引。这样的话,如果我们搜索"wifi","WiFi" 和 "wi-fi"都会认为是匹配的。-->
    <fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
      <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <!--在这个例子中,我们将只在查询时使用同义词
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <!--  删除不区分大小写的停用词 -->
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="lang/stopwords_en.txt"
                />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" 
                catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="lang/stopwords_en.txt"  />
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" 
                catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>

    <!-- Less flexible matching, but less false matches.  Probably not ideal for product names,
         but may be good for SKUs.  Can insert dashes in the wrong place and still match. -->
    <fieldType name="text_en_splitting_tight" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
      <analyzer>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="false"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_en.txt"/>
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="0" catenateWords="1" catenateNumbers="1" catenateAll="0"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
        <filter class="solr.EnglishMinimalStemFilterFactory"/>
        <!-- this filter can remove any duplicate tokens that appear at the same position - sometimes
             possible with WordDelimiterFilter in conjuncton with stemming. -->
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>

    <!-- 与text_general 相似,另外增加了一个功能:把每个分词进行反转,这样会使以通配符开头的查询会更快. -->
    <fieldType name="text_general_rev" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
           maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

    <!-- charFilter + WhitespaceTokenizer  -->
    <!--
    <fieldType name="text_char_norm" class="solr.TextField" positionIncrementGap="100" >
      <analyzer>
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      </analyzer>
    </fieldType>
    -->

    <!-- 使用 KeywordTokenizer 和各种 TokenFilterFactories的fieldType, 对可排序的字段,在排序时去掉一些内容
        比如: field内容为 123test, 排序时,去掉前面的数字进行排序
      -->
    <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="true">
      <analyzer>
        <!-- KeywordTokenizer 不进行实际的分词,即输入的字符串将被认为是单个分词-->
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <!-- The LowerCase TokenFilter does what you expect, which can be
             when you want your sorting to be case insensitive
          -->
        <filter class="solr.LowerCaseFilterFactory" />
        <!-- The TrimFilter removes any leading or trailing whitespace -->
        <filter class="solr.TrimFilterFactory" />
        <!-- PatternReplaceFilter 用正则表达示去替换文本中的内容              
             详见 http://docs.oracle.com/javase/8/docs/api/java/util/regex/package-summary.html
          -->
        <filter class="solr.PatternReplaceFilterFactory"
                pattern="([^a-z])" replacement="" replace="all" />
      </analyzer>
    </fieldType>

    <fieldType name="phonetic" stored="false" indexed="true" class="solr.TextField" >
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.DoubleMetaphoneFilterFactory" inject="false"/>
      </analyzer>
    </fieldType>

    <fieldType name="payloads" stored="false" indexed="true" class="solr.TextField" >
      <analyzer>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <!--
        DelimitedPayloadTokenFilter 能够给分词加权重。比如:
        "foo|1.4"  会给"foo"索引加上权重值1.4f
        DelimitedPayloadTokenFilterFactory 的属性: 
         "delimiter" - 分割符, Default is | (pipe)
         "encoder" - 如何将值转成权重的编码器。可能的值:
               float -> org.apache.lucene.analysis.payloads.FloatEncoder,
               integer -> o.a.l.a.p.IntegerEncoder
               identity -> o.a.l.a.p.IdentityEncoder            
         -->
        <filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float"/>
      </analyzer>
    </fieldType>

    <!-- lowercases the entire field value, keeping it as a single token.  -->
    <fieldType name="lowercase" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory" />
      </analyzer>
    </fieldType>

    <!-- 
      Example of using PathHierarchyTokenizerFactory at index time, so
      queries for paths match documents at that path, or in descendent paths
    -->
    <fieldType name="descendent_path" class="solr.TextField">
      <analyzer type="index">
  <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/" />
      </analyzer>
      <analyzer type="query">
  <tokenizer class="solr.KeywordTokenizerFactory" />
      </analyzer>
    </fieldType>
    <!-- 
      Example of using PathHierarchyTokenizerFactory at query time, so
      queries for paths match documents at that path, or in ancestor paths
    -->
    <fieldType name="ancestor_path" class="solr.TextField">
      <analyzer type="index">
  <tokenizer class="solr.KeywordTokenizerFactory" />
      </analyzer>
      <analyzer type="query">
  <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/" />
      </analyzer>
    </fieldType>

    <!-- 定义被忽略的fieldType  --> 
    <fieldType name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" />

    <fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>

    <!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->
    <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

    <!-- An alternative geospatial field type new to Solr 4.  It supports multiValued and polygon shapes.
      For more information about this and other Spatial fields new to Solr 4, see:
      http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
    -->
    <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
        geo="true" distErrPct="0.025" maxDistErr="0.001" distanceUnits="kilometers" />

    <!-- Spatial rectangle (bounding box) field. It supports most spatial predicates, and has
     special relevancy modes: score=overlapRatio|area|area2D (local-param to the query).  DocValues is recommended for
     relevancy. -->
    <fieldType name="bbox" class="solr.BBoxField"
               geo="true" distanceUnits="kilometers" numberType="_bbox_coord" />
    <fieldType name="_bbox_coord" class="solr.TrieDoubleField" precisionStep="8" docValues="true" useDocValuesAsStored="false" stored="false" />

    <fieldType name="currency" class="solr.CurrencyField" precisionStep="8" defaultCurrency="USD" currencyConfig="currency.xml" />

    <!-- CJK bigram (see text_ja for a Japanese configuration using morphological analysis) -->
    <fieldType name="text_cjk" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <!-- normalize width before bigram, as e.g. half-width dakuten combine  -->
        <filter class="solr.CJKWidthFilterFactory"/>
        <!-- for any non-CJK -->
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.CJKBigramFilterFactory"/>
      </analyzer>
    </fieldType>


    <!-- 与分析字段类型 -->
    <fieldType name="preanalyzed" class="solr.PreAnalyzedField">
      <!-- PreAnalyzedField的内置索引分析器只解码预分析的令牌流。 -->
      <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
      </analyzer>
    </fieldType>
</schema>
  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值