Solr入门之(5)配置文件schema.xml
该配置文件中的标签:<fileTypes>、<fields>、<uniqueKey>、<copyField>
fieldType说明
标签types中定义了field可以使用的类型,类型定义中可以指定document中字段的常用属性及分词规则。
solr中提供了多个预定义的fieldType,另外用户也可以自定义fieldType(比如中文分词的配置)。
一、fieldType常用属性:
A、name: 字段类型名
B、class: java类名
C、indexed: 缺省true。 说明这个数据应被搜索和排序,如果数据没有indexed,则stored应是true。
D、stored: 缺省true。说明这个字段被包含在搜索结果中是合适的。如果数据没有stored,则indexed应是true。
E、sortMissingLast: 指没有该指定字段数据的document排在有该指定字段数据的document的后面
F、sortMissingFirst: 指没有该指定字段数据的document排在有该指定字段数据的document的前面
G、omitNorms: 字段的长度不影响得分和在索引时不做boost时,设置它为true。一般文本字段不设置为true。
H、termVectors: 如果字段被用来做more like this 和highlight的特性时应设置为true。
I、compressed: 字段是压缩的。这可能导致索引和搜索变慢,但会减少存储空间,只有StrField和TextField是可以压缩,这通常适合字段的长度超过200个字符。
J、multiValued: 字段多于一个值的时候,可设置为true。详细说明参见:http://blog.csdn.net/alen1985/article/details/8538942
K、positionIncrementGap: 和multiValued一起使用,设置多个值之间的虚拟空白的数量
二、fieldType子标签analyzer:
定义该类型字段的分词规则、过滤规则等。type:index/query。
A、tokenizer:指定该类型的文本分词器,如何切分为tokens。
B、filter:过滤器,常用的有停用词、同义词、大小写等过滤。可以定义多个。
三、fileType示例:
<types>
<!--
string类型不分词,但是索引、存储。支持doc values,但是要保证该field是单值并且该field有值。
-->
<fieldType name="string" class="solr.StrField" sortMissingLast="true" /> <!-- boolean type: "true" or "false" -->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/> <!--
默认的数字类型,如果想要更快的范围查询,考虑使用tint/tfloat/tlong/tdouble类型.
支持doc values,但是要保证该field是单值并且该field有值。
-->
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/> <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/> <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/> <!-- A Trie based date field for faster date range queries and date faceting. -->
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/> <!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings -->
<fieldtype name="binary" class="solr.BinaryField"/> <fieldType name="pint" class="solr.IntField"/>
<fieldType name="plong" class="solr.LongField"/>
<fieldType name="pfloat" class="solr.FloatField"/>
<fieldType name="pdouble" class="solr.DoubleField"/>
<fieldType name="pdate" class="solr.DateField" sortMissingLast="true"/> <!-- 只按空格分词的分词器 -->
<fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
</analyzer>
</fieldType> <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" enablePositionIncrements="true" />
<!-- 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" enablePositionIncrements="true" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType> <fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<!-- Case insensitive stop word removal.
add enablePositionIncrements=true in both the index and query
analyzers to leave a 'gap' for more accurate phrase queries.
-->
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:
<filter class="solr.EnglishMinimalStemFilterFactory"/>
-->
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EnglishPossessiveFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:
<filter class="solr.EnglishMinimalStemFilterFactory"/>
-->
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType> </types>
其余详细请参照solr提供的默认schema.xml文件,solr中提供了许多预制的类型。
fields标签说明
fields中有两种字段定义方式:field和dynamicField。此两种方式的区别就是绝对匹配和模糊匹配,其属性相同。
一、field和dynamicField的常用属性:
A、name: 必须定义。 - 字段的名称
B、class: 必须定义。 - 只能引用fieldTypes中定义的fieldType。
C、indexed: 缺省true。 说明这个数据应被搜索和排序,如果数据没有indexed,则stored应是true。
D、stored: 缺省true。说明这个字段被包含在搜索结果中是合适的。如果数据没有stored,则indexed应是true。
E、sortMissingLast: 指没有该指定字段数据的document排在有该指定字段数据的document的后面
F、sortMissingFirst: 指没有该指定字段数据的document排在有该指定字段数据的document的前面
G、omitNorms: 字段的长度不影响得分和在索引时不做boost时,设置它为true。一般文本字段不设置为true。
H、termVectors: 如果字段被用来做more like this 和highlight的特性时应设置为true。
I、compressed: 字段是压缩的。这可能导致索引和搜索变慢,但会减少存储空间,只有StrField和TextField是可以压缩,这通常适合字段的长度超过200个字符。
J、multiValued: 字段多于一个值的时候,可设置为true。详细说明参见:http://blog.csdn.net/alen1985/article/details/8538942
K、positionIncrementGap: 和multiValued一起使用,设置多个值之间的虚拟空白的数量
L、docValues: 默认[true]。是否使用doc values. doc values 在 facet、group、sort和function queries时很有用。当前只支持StrField、UUIDField、所有的Trie*Fields。
M、omitNorms: 可以通过将omitNorms=“true”来减少indexed fields数量增加所带来的影响。
N、termVectors: 默认[false]。是否保存该字段的term vector。当使用MoreLikeThis时,为了有比较的效果,应该保存。
O、termPositions: 是否保存term vector的位置信息,如果保持会增加存储的消耗。效果详见下图。
P、termOffsets: 是否保存term vector的偏移信息。
Q、required: 必选。当该值不存在时抛出异常。
R、default: 默认值。

二、动态字段说明:
<fields>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="sku" type="text_en_splitting_tight" indexed="true" stored="true" omitNorms="true"/>
<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="manu" type="text_general" indexed="true" stored="true" omitNorms="true"/>
<field name="cat" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="features" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="includes" type="text_general" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />
<field name="weight" type="float" indexed="true" stored="true"/>
<field name="price" type="float" indexed="true" stored="true"/>
<field name="popularity" type="int" indexed="true" stored="true" />
<field name="inStock" type="boolean" indexed="true" stored="true" />
<field name="store" type="location" indexed="true" stored="true"/> <!--动态字段-->
<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" />
</fields>
uniqueKey
相当于数据库中主键的定义。
<uniqueKey>id</uniqueKey>
copyField说明
对于查询来说,如果查询字段要来自多个字段,一种选择是使用CopyField,化多个字段为一个字段,缺点是不能区分各个字段的重要度差别。比如文章的标题和摘要,标题就要比摘要重要性更强,如果有这方面的要求,可以选择查询多个字段的做法。
CopyField示例:
<copyField source="cat" dest="text"/>
<copyField source="name" dest="text"/>
<copyField source="manu" dest="text"/>
<copyField source="features" dest="text"/>
<copyField source="includes" dest="text"/>
<copyField source="manu" dest="manu_exact"/>
Solr入门之(5)配置文件schema.xml的更多相关文章
- Solr配置文件 schema.xml
1 添加自己的分词器(mmseg4j) 意思是textCommplex 这个类型,用的是 com.chenlb.mmseg4j.solr.MMSegTokenizerFactory 这个分词器,词库是 ...
- solr官方文档翻译系列之schema.xml配置介绍
常见的元素 <field name="weight" type="float" indexed="true" stored=" ...
- 认识配置文件schema.xml(managed-schema)
1.schema文件是在SolrConfig中的架构工厂定义,有两种定义模式: 1.1.默认的托管模式: solr默认使用的就是托管模式.也就是当在solrconfig.xml文件中没有显式声明< ...
- Mycat配置文件schema.xml参数配置
Mycat原理: Mycat的原理中最重要的一个动词是"拦截",它拦截了用户发送过来的SQL语句,首先对SQL语句做了一些特定的分析:如分片分析.路由分析.读写分离分析.缓存分析等 ...
- Mycat 配置文件schema.xml
1.介绍 schema.xml 作为 MyCat 中重要的配置文件之一,管理着 MyCat 的逻辑库.表.分片规则. DataNode 以及 DataSource. 2.schema相关标签 sche ...
- 【solr】schemaFactory配置相关schema.xml
schemaFactory配置相关schema.xml 关于schemaFactory的配置困扰我半天啦,下面来总结一下. 话说,好像是从5.0以后就已经没有schema.xml啦,这是由于Solr ...
- solr中的schema.xml(managed-schema)文件解读
solr 7.2.1版本managed-schema文件示例 <uniqueKey>id</uniqueKey> 唯一键字段,solr对每一个文档都赋予一个唯一标识符字段,避免 ...
- solr 6.0 没有schema.xml未自动创建schema文件
solr 6.0 没有schema.xml未自动创建schema文件 摘要:在之前的Solr版本中(Solr5之前),在创建core的时候,Solr会自动创建好schema.xml,但是在之后的版本中 ...
- 1.solr学习速成之配置文件
什么是solr Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过H ...
随机推荐
- supervisor的配置
看了下文档,比较多.http://www.supervisord.org/ 抱着试试又不会怀孕的心态,trying,碰了几鼻子灰,记录如下, 方便大家 1. 安装 easy_install super ...
- GMM简单解释
1.GMM(guassian mixture model) 混合高斯模型,顾名思义,就是用多个带有权重的高斯密度函数来描述数据的分布情况.理论上来说,高斯分量越多,极值点越多,混合高斯密度函数可以逼近 ...
- Android蓝牙连接以及数据接收发送
1.加入权限 <uses-feature android:name="android.hardware.bluetooth_le" android:required=&quo ...
- SQL Server常用命令
1.DECLARE DECLARE命令用于声明一个或多个局部变量.游标变量或表变量. 注:如果定义的变量是字符型,应该指定data_type表达式中其最大长度,否则系统认为其长度为1. declare ...
- ios 关于使用异步网络请求时block回调的内存注意
在一个controller中,使用 NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest ...
- bccomp比较大小注意
2015年12月15日 14:18:56 星期二 echo bccomp('1', '1.01', 2); // -1 echo bccomp('1', '1.01', 3); // -1 echo ...
- ACM/ICPC 之 数据结构-邻接表+BFS(TSH OJ-无线广播Broadcast)
这道题中若能够构成互不干扰的区域,其构成的图其实就是汉密尔顿路(Hamilton road),因此如果能够观察出来可以直接转化为汉密尔顿路的存在性证明,即便不能观察,我相信ACMer也能转化为BFS问 ...
- 13. javacript高级程序设计-事件
1. 事件 1.1 事件流 事件流描述的是从页面中接受事件的顺序,IE的事件是冒泡流,而Netscape Communicator的事件流是事件捕捉流. 1.1.1 事件冒泡 <!DOCTYPE ...
- 项目管理工具~SVN
SVN 定期更新:每周五,周一早上 目录完备: 需求文档 设计文档 数据字典 测试报告 代码备份 周报月报 ...
- Linux/Unix命令
MAC 中自定义环境变量 打开:nano .bash_profile 查看:cat text 保存退出:Ctrl+C,Y #在.bash_profile 中添加tree alias tree=&quo ...