加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

指尖上的电商---(5)schema.xml配置详解

发布时间:2020-12-16 08:37:18 所属栏目:百科 来源:网络整理
导读:这一节我们看下schema.xml文件中各个节点的配置极其作用。schema.xml文件里面主要定义了索引数据类型,索引字段等信息。 主要包括了以下节点 1.fieldtype节点 fieldtype节点主要用来定义数据类型。 [html] view plain copy fieldType name = "string" sortMi

这一节我们看下schema.xml文件中各个节点的配置极其作用。schema.xml文件里面主要定义了索引数据类型,索引字段等信息。

主要包括了以下节点

1.fieldtype节点

fieldtype节点主要用来定义数据类型。

[html] view plain copy
  1. <fieldTypename="string"sortMissingLast="true"class="solr.StrField"/>
  2. <!--booleantype:"true"or"false"-->
  3. fieldTypename="boolean"sortMissingLast="true"class="solr.BoolField"/>

name指定的是节点定义的名称

class指向org.apache.solr.analysis中定义的类型名称

fieldtype还可以自己定义当前类型建立索引和查询数据的时候使用的查询分析器。

tokenizer指定分词器

filter指定过滤器

copy
fieldTypename="text_general"class="solr.TextField"positionIncrementGap="100">
  • analyzertype="index">
  • tokenizerclass="solr.StandardTokenizerFactory"filterclass="solr.StopFilterFactory"words="stopwords.txt"ignoreCase="true"/>
  • filterclass="solr.LowerCaseFilterFactory"</analyzeranalyzertype="query"filterclass="solr.SynonymFilterFactory"ignoreCase="true"expand="true"synonyms="synonyms.txt"fieldType>
  • positionIncrementGap:可选属性,定义在同一个文档中此类型数据的空白间隔,避免短语匹配错误。
    positionIncrementGap=100 只对 multiValue = true 的fieldType有意义。
    StrField类型不被分析,而是被逐字地索引/存储

    solr.TextField 允许用户通过分析器来定制索引和查询,分析器包括一个分词器(tokenizer)和多个过滤器(filter)

    2.field节点

    field节点指定建立索引和查询数据的字段。

    name代表数据字段名称

    type代表数据类型,也就是之前定义的fieldtype

    indexed代表是否被索引

    stored代表是否被存储

    multiValued是否有多个值,如果字段可能有多个值,尽可能设为true

    _version节点和root节点是必须保留的,不能删除

    copy
    fieldname="_version_"stored="true"indexed="true"type="long"fieldname="_root_"stored="false"indexed="true"type="string"fieldname="ProductCode"stored="true"indexed="true"type="string"multiValued="false"required="true"fieldname="ProductName"stored="true"indexed="true"type="text_general"
    3.copyfield节点

    通过这个节点,可以把一个字段的值复制到另一个字段中,也可以把多个字段的值同时复制到另一个字段中,

    这样搜索的时候都可以根据一个字段来进行搜索。

    copy
    copyFieldsource="ProductName"dest="text"copyFieldsource="ProductCode"dest="text"
    4.dynamicField节点

    dynamicField表示动态字段,可以动态定义一个字段,只要符合规则的字段都可以

    *_i只要以_i结尾的字段都满足这个定义,

    copy
    dynamicFieldname="*_i"stored="true"indexed="true"type="int"

    5.其他节点

    uniquekey节点是文档的唯一标示,相当于主键,每次更新,删除的时候都根据这个字段来进行操作。必须填写

    <uniqueKey>ProductCode</uniqueKey>

    defaultSearchField指定搜索的时候默认搜索字段的值,

    <defaultSearchField > text </ defaultSearchField >

    solrQueryParser指定搜索时多个词之间的关系,可以是or,and两种

    <solrQueryParser defaultOperator="OR" />

    6.性能优化


    将所有只用于搜索的,而不需要作为结果的field(特别是一些比较大的field)的stored设置为false
    将不需要被用于搜索的,而只是作为结果返回的field的indexed设置为false,删除所有不必要的copyField声明
    为了索引字段的最小化和搜索的效率,将所有的 text fields的index都设置成false,然后使用copyField将他们都复制到一个总的 text field上,

    然后进行搜索。

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读