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 ...
随机推荐
- phpDocumentor 注释语法详解
PHPDocumentor是强大的代码注释生成器,本文对各个参数进行了简单地的总结: @abstract-------------使用@abstract标记来声明一个方法,类变量或类必须重新定义子类中 ...
- linux ssh 登录同时执行其他指令
目的:懒的敲一些重复的指令,比如登录后cd到某个目录. 咋办: ssh -t user@xxx.xxx.xxx.xxx "cd /directory_wanted ; bash" ...
- Install OE and BitBake
LeapFrog Explorers: Install OE and BitBake - eLinux.org http://elinux.org/LeapFrog_Explorers:_In ...
- STL---list(列表)
Lists将元素按顺序储存在链表中. 与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比较慢. list的类模板声明为 template<class T, class A ...
- Shell 语法 if 、 case 、for 、 while、 until 、select 、repeat、子函数
if语法 : if [ expression ] then commandselif [ expression2 ] then commandselse commandsfi ...
- ios 在storyboard 和 xib中,显示自定义view的预览效果
发现FSCalendar这个控件能在xib中显示预览效果,是怎么实现的呢?其中涉及的知识又有哪些? 主要就是IBInspectable 和 IB_DESIGNABLE 先看 IBInspectable ...
- ACM/ICPC 之 BFS(离线)+康拓展开 (HDU1430-魔板)
魔板问题,一道经典的康拓展开+BFS问题,为了实现方便,我用string类来表示字符串,此前很少用string类(因为不够高效,而且相对来说我对char数组的相关函数比较熟),所以在这里也发现了很多容 ...
- 密码加SALT原理
原来这个技术叫SALT,以前我们经常这么用 ============================================================================== ...
- 在Debian上用Bind 配置DNS服务器
1 什么是DNS 初学者可能不理解DNS到底是什么,干什么用.我是在1998年大学毕业时才听说这个词的.那时我在聊天室碰到潍坊信息港的一个网管,我恬不知耻地说我也是个网管,他说也维护DNS吗?我说,D ...
- Effective C++ -----条款47:请使用traits classes表现类型信息
Traits classes使得“类型相关信息”在编译期可用.它们以template和“templates特化”完成实现. 整合重载技术(overloading)后,traits classes有可能 ...