zoukankan      html  css  js  c++  java
  • Solr 6.7学习笔记(02) 配置文件 managedschema (schema.xml)(2)

          接上篇

       2. <dynamicField>

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

                2.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.2 支持来自不同来源的文档

                 比如索引的时候想要增加标注其来源的field,可以进行如下的配置:

                 <field name="source1_field1" type="string" index="true" stored="true" />

                 <field name="source1_field2" type="string" index="true" stored="true" />

                 <field name="source1_field3" 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" />

                 <field name="source2_field3" 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定义。

                 2.3 增加新的文档来源

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

         3. <uniqueKey>

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

         4. <copyField>

               用百度或google搜索时,我们可能想要搜索一个人名,或者书名,或者网站的名字,其后台索引文件里分别由不同的field去保存那些值,那它是如何用一个输入框去搜索不同的field的内容的呢?答案就是<copyField> (不知道百度或google用的是什么搜索技术,但是原理应该差不多)

               <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里的内容就可以了。

  • 相关阅读:
    BGP的MA网络、自动汇总、聚合
    [转载]CISCO配置HSRP
    BGP选路十种方法总结 用实验详细介绍(副实验拓扑)
    [win技巧] windows 7的上帝模式你用过吗?【相信你没用过!如此方便的的设置】
    CISCO BGP(EBGP/IBGP)基本配置小结以及如何防止BGP路由黑洞(附实验拓扑)
    执行外部程序
    C#编写COM组件
    在SQL Server 2005上遇到了先删除已运行维护计划后,再删除代理中由其产生的作业时,提示删除失败,如何处理?
    关于存储过程编写的一点总结(转)
    WCF:调用方未由服务器进行身份验证
  • 原文地址:https://www.cnblogs.com/langfanyun/p/5868461.html
Copyright © 2011-2022 走看看