指尖上的电商---(5)schema.xml配置具体解释
这一节我们看下schema.xml文件中各个节点的配置极其作用。schema.xml文件中面主要定义了索引数据类型,索引字段等信息。主要包含了下面节点
1.fieldtype节点
fieldtype节点主要用来定义数据类型。
<fieldType name="string" sortMissingLast="true"/>
<!-- boolean type: "true" or "false" -->
<fieldType name="boolean" sortMissingLast="true"/>
name指定的是节点定义的名称
> fieldtype还能够自定义当前类型建立索引和查询数据的时候使用的查询分析器。
tokenizer指定分词器
filter指定过滤器
<fieldType name="text_general" positionIncrementGap="100"> <analyzer type="index">
<tokenizer/>
<filter words="stopwords.txt" ignoreCase="true"/>
<filter/>
</analyzer>
<analyzer type="query">
<tokenizer/>
<filter words="stopwords.txt" ignoreCase="true"/>
<filter ignoreCase="true" expand="true" synonyms="synonyms.txt"/>
<filter/>
</analyzer>
</fieldType>
positionIncrementGap:可选属性,定义在同一个文档中此类型数据的空白间隔。避免短语匹配错误。
positionIncrementGap=100仅仅对 multiValue = true 的fieldType有意义。
StrField类型不被分析。而是被逐字地索引/存储
solr.TextField 同意用户通过分析器来定制索引和查询。分析器包含一个分词器(tokenizer)和多个过滤器(filter)
2.field节点
field节点指定建立索引和查询数据的字段。
name代表数据字段名称
type代表数据类型,也就是之前定义的fieldtype
indexed代表是否被索引
stored代表是否被存储
multiValued是否有多个值,假设字段可能有多个值,尽可能设为true
_version节点和root节点是必须保留的,不能删除
<field name="_version_" stored="true" indexed="true" type="long"/>
<field name="_root_" stored="false" indexed="true" type="string"/>
<field name="ProductCode" stored="true" indexed="true" type="string" multiValued="false" required="true"/>
<field name="ProductName" stored="true" indexed="true" type="text_general"/>
3.copyfield节点
通过这个节点。能够把一个字段的值拷贝到还有一个字段中,也能够把多个字段的值同一时候拷贝到还有一个字段中,
这样搜索的时候都能够依据一个字段来进行搜索。
<copyField source="ProductName" dest="text"/>
<copyField source="ProductCode" dest="text"/>
4.dynamicField节点
dynamicField表示动态字段,能够动态定义一个字段,仅仅要符合规则的字段都能够
*_i仅仅要以_i结尾的字段都满足这个定义。
<dynamicField name="*_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上。
然后进行搜索。
页:
[1]