[搜索] Solr (二) 配置文件

Solr配置文件

Solr包含两个主要配置:solr的主目录solr\collection1\conf下面的schema.xml,solrConfig.xml

  • solrconfig.xml:主要定义solr的处理程序(handler)和一些扩展程序;
  • schema.xml:主要定义索引的字段和字段类型。

schema.xml

  1. field 字段节点
      <field name="id"        type="string"   indexed="true"  stored="true"  multiValued="false" required="true"/>
      <field name="type"      type="string"   indexed="true"  stored="true"  multiValued="false" /> 
      <field name="name"      type="string"   indexed="true"  stored="true"  multiValued="false" /> 
      <field name="core0"     type="string"   indexed="true"  stored="true"  multiValued="false" /> 
      <field name="_version_" type="long"     indexed="true"  stored="true"/> <!-- _version_ field是必需的,不能注掉 -->
    • type:字段类型,对应fieldType节点,在此结点中可以配置对应字段类型的相应分词器
    • indexed :是否进行索引
    • stored:是否进行保存,如不保存,可以进行索引但不能显示此字段的内容
    • multiValues:是否允许多值
    • required:是否是必须字段,如是,则该字段必须有值,否则索引报错
  2. 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"/>
      <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"/>
    动态字段表示:如果字段的定义没有在配置中找到,例如menu_s字段,field节点中没有配置,就可以在dynamicField中匹配name="*_s",表示该字段为string类型
  3. copyField 复制字段节点
      <copyField source="title" dest="text"/>
      <copyField source="author" dest="text"/>
      <copyField source="manu" dest="manu_exact"/>
      <copyField source="price" dest="price_c"/>
    复制源字段到目标字段。通过复制字段的配置,就可以把这些字段放到一起,这样搜索的时候不用写很复杂的查询组合就可以在所有的字段中搜索
  4. fieldType 字段类型节点
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
    <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" />
            	<!-- 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.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>
    添加处理对应字段类型的方法,包括相应分词器等
  5. 其他节点
    <uniqueKey>id</uniqueKey><!-- 唯一标示,如建索引时遇到重复,则覆盖 -->
    

           -------------------------------------------------------------------------------------

solrconfig.xml

solrconfig.xml中配置很多,大部分可以保持默认

  1. dataDir 索引数据data路径
    <dataDir>${solr.data.dir:}</dataDir>
    默认不指定,默认房子每个code下data目录中
  2. autoCommit 自动提交
    <autoCommit> 
        <maxTime>${solr.autoCommit.maxTime:15000}</maxTime> 
        <openSearcher>false</openSearcher> <!-- 默认关闭-->
    </autoCommit>
  3. autoSoftCommit 软提交(近实时搜索)
    <!-- softAutoCommit is like autoCommit except it causes a
         'soft' commit which only ensures that changes are visible
         but does not ensure that data is synced to disk.  This is
         faster and more near-realtime friendly than a hard commit.
    -->
    <autoSoftCommit> 
         <maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime> 
    </autoSoftCommit>
    Solr创建索引数据时要在提交(Commit)时写入磁盘,这是硬提交,确保即便是停电也不会丢失数据,如果想进行 实时的查询操作需要每次进行commit操作,但是这种方式是比较消耗资源的。为了提供更实时的检索能力,同时又 能保证性能,Solr设定了一种软提交方式。软提交(soft commit):仅把数据提交到内存,index可见,此时没有 写入到磁盘索引文件中。通常的用法是:每1-10分钟自动触发硬提交,每秒钟自动触发软提交
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值