solr配置文件之schema.xml

2019-03-27 00:22|来源: 网路

 以下是针对schema.xml 配置文件的剖析:


              1.  <types></types>这个标签和它的意义一样,是用来表示数据有哪些类型,这些类型当然是solr内部定义的类型和自定义类型。

               2.    <!-- The StrField type is not analyzed, but indexed/stored verbatim. -->

                   和他上面解释一样,string类型是不分词的,要建索引,要存储

                 <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>

              3.数值类型,有如下几个类型是默认数值类型,如果想用于排序请用   tint/tfloat/tlong/tdouble类型

       <!--
      Default numeric field types. For faster range queries, consider the tint/tfloat/tlong/tdouble types.
    -->
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>

    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>


   <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>


        4.时间类型:如果想用于快速排序查询,用tdate(看到这里我的排序没用tdate,得改啊。。)

     Note: For faster range queries, consider the tdate type

    <fieldType name="date" class="solr.TrieDateField" omitNorms="true" precisionStep="0" positionIncrementGap="0"/>

    <!-- A Trie based date field for faster date range queries and date faceting. -->
    <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0"/>


    5.专门用于分词的字段。在里面包含了定义使用什么分词器,可以手工定制。

<fieldType name="text" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">

         <!--建索引用到的分词器,我用的是IKTokenizerFactory,中文分词-->

        <analyzer type="index">
        <!--<tokenizer class="solr.WhitespaceTokenizerFactory"/>-->
        <tokenizer class="org.wltea.analyzer.solr.IKTokenizerFactory"/>
        <!-- in this example, we will only use synonyms at query time
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
        <!-- Case insensitive stop word removal.
          add enablePositionIncrements=true in both the index and query
          analyzers to leave a 'gap' for more accurate phrase queries.
        -->
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="stopwords.txt"
                enablePositionIncrements="true"
                />
        <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"/>-->
        <tokenizer class="org.wltea.analyzer.solr.IKTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="stopwords.txt"
                enablePositionIncrements="true"
                />
        <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>

     <!--查询用到的分词器IKTokenizerFactory,为了支持中文查询,这是必须的。-->

      <analyzer type="query">
       <!-- <tokenizer class="solr.WhitespaceTokenizerFactory"/>-->
        <tokenizer class="org.wltea.analyzer.solr.IKTokenizerFactory"/>
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.StopFilterFactory"
                ignoreCase="true"
                words="stopwords.txt"
                enablePositionIncrements="true"
                />
        <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>


其他几个类别都是不常用的,也是通过分词器来定义不同的类别。和第五个类似。

6.索引字段名称定义。

   <fields>
   <!-- Valid attributes for fields:
     name: mandatory - the name for the field
     type: mandatory - the name of a previously defined type from the 
       <types> section
     indexed: true if this field should be indexed (searchable or sortable)
     stored: true if this field should be retrievable
     multiValued: true if this field may contain multiple values per document
     omitNorms: (expert) set to true to omit the norms associated with
       this field (this disables length normalization and index-time
       boosting for the field, and saves some memory).  Only full-text
       fields or fields that need an index-time boost need norms.
     termVectors: [false] set to true to store the term vector for a
       given field.
       When using MoreLikeThis, fields used for similarity should be
       stored for best performance.
     termPositions: Store position information with the term vector.  
       This will increase storage costs.
     termOffsets: Store offset information with the term vector. This 
       will increase storage costs.
     default: a value that should be used if no value is specified
       when adding a document.
   -->

   <field name="id" type="string" indexed="true" stored="true" required="true" /> 
   <field name="sku" type="textTight" indexed="true" stored="true" omitNorms="true"/>
<!--   <field name="name" type="textgen" indexed="true" stored="true"/>-->
   <field name="alphaNameSort" type="alphaOnlySort" indexed="true" stored="false"/>
   <field name="manu" type="textgen" indexed="true" stored="true" omitNorms="true"/>
   <field name="cat" type="string" indexed="true" stored="true" multiValued="true"/>
   <field name="features" type="text" indexed="true" stored="true" multiValued="true"/>
   <field name="includes" type="text" 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" />
 </fields>


  id:是索引字段的唯一标识。

termVectors="true"属性主要用于相关搜索。

multiValued="true"属性,一般用于多个字段组成一个字段的情况。

   <field name="content_type" type="text" indexed="true" stored="true" multiValued="true"/>

一般用于查询的字段定义为multiValued。

7.  <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>表示动态字段,暂时没用到。

本文出自 “无证程序猿” 博客,请务必保留此出处http://yjflinchong.blog.51cto.com/6851233/1164962


转自:http://yjflinchong.blog.51cto.com/6851233/1164962

相关问答

更多
  • slor schema.xml没有bigdecimalfield。solr 所有的filed 定义在 solr-core.jar package org.apache.solr.schema 下面,自己可以看一下 ,真的没有的。
  • 当您想从前面搜索时, Edge N-Gram Tokenizer会逐字逐句地执行您想要的操作。 为了减小索引大小,我还要在分析器中添加一个小写过滤器 。 您将需要一个自定义fieldType - 请参见下文 - 然后您需要在所选文档的字段中使用该字段。
  • 这些真的是多个问题伪装成一个。 然而: 如何将弹性搜索设置+映射存储在一个文件中(如Solr的schema.xml)? 首先,请注意,您不必为许多类型(如日期,整数或甚至字符串)指定映射(当默认分析程序适合您时)。 您可以用各种方式存储设置和映射,在ElasticSearch < 1.7 : 在主要的elasticsearch.yml文件中 在索引模板文件中 在具有映射的单独文件中 目前,当我想对我的映射进行更改时,我必须删除我的索引设置并重新开始。 我错过了什么吗? 当您更改现有字段的映射时,您必须重新索 ...
  • 首先:在publisher_id中存储了什么样的数据? 如果它是一个数字(int,log),则添加一个具有相应类型的字段,如: 在schema.xml中添加一个字段后,必须重新启动solr-instance并重建索引。 First of all: what kind of data is stored in publisher_id? If it is a numbe ...
  • 从过去的Solr问题 - SOLR-3087开始 ,看起来是正确的语法,您只需要在内联中包含xi命名空间引用。 id
  • 问题是solrconfig.xml中预先配置的所有其他内容。 我刚刚推出了一个用于培训项目的最小例子 。 它适用于Solr 5.5,而不是6.0,但它应该给你一个非常好的方向。 这使用静态模式方法,而不是托管模式方法,这是Solr 6中的默认方法。因此,这是要记住的差异之一。 The problem is all the other stuff preconfigured in the solrconfig.xml. I have just pushed a minimal example I used f ...
  • 每次更改数据的存储方式时都必须重新编制索引。 当您使用太阳黑子宝石时,您可以在两个主要位置更改数据的存储方式: 1-你提到的schema.xml 2-可搜索的块看起来类似于下面 class Post < ActiveRecord::Base searchable do text :title, :body text :comments do comments.map { |comment| comment.body } end end end You have ...
  • 正如在这个SO中所写的那样,Solr的Schemaless模式可以帮助你 Solr支持Schemaless模式 。 以这种方式启动Solr时,您最初并未绑定到架构。 当您向Solr提供第一个文档时,它将猜测相应的字段类型并生成包含这些字段类型的模式。 然后修复这些字段。 您仍然可以通过这种方式添加新字段。 你还需要做的是从你的mongodb到Solr创建某种导入路线。 谷歌搜索后,你可能会偶然发现SO问题 - MongoDB的solr数据导入处理程序 - 这也可能对你有帮助。 可能更简单的是创建一个mong ...
  • 这就是它的建造方式。 Lucene是一个库,所以你可以将你的代码与它联系起来。 另一方面,Solr是一个服务器,在某些情况下,你可以使用它很少的编码(例如使用DataImportHandler索引和Velocity插件浏览和搜索)。 该模式允许您声明性地定义每个字段的分析和查询方式。 如果您想要基于Lucene的无模式服务器,请查看ElasticSearch 。 That's just the way it was built. Lucene is a library, so you link your c ...
  • 在云模式下,每个集合都有一个模式。 此架构不会自动添加。 您不必从头开始创建文件。 您可以在example目录中找到随时可用的configset,然后您可以修改它以供自己使用。 在云模式下,您的所有配置文件都存储在zookeeper上。 您可以使用solr安装提供的zkcli.sh脚本连接到它。 对于6.x,您可以在${SOLR_HOME}/server/scripts/cloud-scripts/zkcli.sh下找到它 要上传模式集: server/scripts/cloud-scripts/zkcli ...