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

  • 相关阅读:
    常用修图工具的一些使用技巧及问题解决方法——ai
    IIS7web服务器调试ASP.net程序遇到的一些故障的解决办法
    使用ecstore-sdk开发包制作易开店和启明星模板
    虚拟机安装Centos6.5服务器系统
    使用UltraISO制作光盘镜像
    安装配置Windows Live Writer做为博客客户端
    Winform关于OpenFileDialog的使用方法
    SQLServer的数据类型
    SqlServer把日期转换成不同格式的字符串的函数大全
    SQL字符串处理函数大全
  • 原文地址:https://www.cnblogs.com/langfanyun/p/5868461.html
Copyright © 2020-2023  润新知