Solr基础教程之Schema.xml(二)
来源:互联网 发布:js显示display 编辑:程序博客网 时间:2024/05/17 22:44
在 Solr 中,使用一个或多个 Document 来构建索引。Document 包括一个或多个 Field。Field 包括名称、内容以及告诉 Solr 如何处理内容的元数据。
例如,Field 可以包含字符串、数字、布尔值或者日期,也可以包含你想添加的任何类型,只需用在solr的配置文件中进行相应的配置即可。Field 可以使用大量的选项来描述,这些选项告诉 Solr 在索引和搜索期间如何处理内容。
下面来挨个详细介绍下这些属性的含义。
1、模式配置Schema.xml
schema.xml这个配置文件可以在你下载solr包的安装解压目录的\solr\example\solr\collection1\conf中找到,也可以在我们上篇讲到的solrhome\mycore\conf中找到,它就是solr模式关联的文件。打开这个配置文件,你会发现有详细的注释。
模式组织主要分为三个重要配置。
2、types 部分
fieldType 是一些常见的可重用定义,定义了 Solr(和 Lucene)如何处理 Field。也就是添加到索引中的xml文件属性中的类型,如int、text、date等.
<fieldType name="string" class="solr.StrField" sortMissingLast="true"/><fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/><fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/><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" /> <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>
参数说明:
3、fileds 部分
filed是你添加到索引文件中出现的属性名称,也就是前文介绍的,select后面跟着的字段名,而声明类型就需要用到上面的types
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false"/><field name="path" type="text_smartcn" indexed="false" stored="true" multiValued="false" termVector="true" /><field name="content" type="text_smartcn" indexed="false" stored="true" multiValued="false" termVector="true"/><field name ="text" type ="text_ik" indexed ="true" stored ="false" multiValued ="true"/><field name ="pinyin" type ="text_pinyin" indexed ="true" stored ="false" multiValued ="false"/><field name="_version_" type="long" indexed="true" stored="true"/><dynamicField name="*_i" type="int" indexed="true" stored="true"/><dynamicField name="*_l" type="long" indexed="true" stored="true"/><dynamicField name="*_s" type="string" indexed="true" stored="true" /><copyField source="content" dest="pinyin"/><copyField source="content" dest="text"/><copyField source="pinyin" dest="text"/>
copyField就引出了solr的一个全文检索的概念,如果我要实现一个搜索,而我要搜索的属性有很多个那么应该使用如下配置方法:
<!-- 关键字搜索 --><field name="keyword" type="text_general" indexed="true" stored="false" multiValued="true"/><copyField source="seoTitle" dest="keyword"/><copyField source="title" dest="keyword"/><copyField source="subTitle" dest="keyword"/><copyField source="shopName" dest="keyword"/><copyField source="seoKeywords" dest="keyword"/><copyField source="category_name_*" dest="keyword"/><copyField source="descriptionForSearch" dest="keyword"/>
此时keyword的值就相当于包含了seoTitle、title、subTitle、shopName、seoKeywords、category_name_*、descriptionForSearch的所有内容。
如果这里不理解,可以看下这篇帖子里面介绍的概念:全文索引概念
另外这里大家一定会好奇,keyword使用的type=”text_general”会达到什么效果,其实很简单,text_general是我在上面定义的分词器,能够根据一定的格式分词,利于搜索,如果不实用text_general,那么就达不到全文检索,模糊搜索的目的了。
字段属性说明:
注意:_version_ 是一个特殊字段,不能删除,是记录当前索引版本号的.
4、其他配置
uniqueKey:唯一键,这里配置的是上面出现的fileds,一般是id、url等不重复的。在更新、删除的时候可以用到。
defaultSearchField:默认搜索属性,如q=solr就是默认的搜索那个字段
solrQueryParser:查询转换模式,是并且还是或者(AND/OR必须大写)
- Solr基础教程之Schema.xml(二)
- Solr之Schema.xml
- Solr基础教程之solrconfig.xml(三)
- 【solr专题之二】配置文件:solr.xml solrConfig.xml schema.xml
- 【solr专题之二】配置文件:solr.xml solrConfig.xml schema.xml
- Solr 配置文件之schema.xml
- solr之schema.xml中文翻译
- Solr 配置文件之schema.xml
- 【solr基础教程之二】索引
- 【solr基础教程之二】索引
- 【solr基础教程之二】索引
- (搜索引擎之solr) schema.xml 配置文件说明
- (搜索引擎之solr) schema.xml 配置文件说明
- Solr主要配置文件之schema.xml。
- Solr之模式配置Schema.xml。
- solr schema.xml 解析
- solr的schema.xml
- solr schema.xml
- Asp.net网站中 js通过input type="file" 上传文件
- Android学习笔记-界面和数据存储以及一些零碎知识点
- IMS (IP多媒体子系统)
- 静态内部类和非静态内部类的区别
- 大数据分析师吴女士观点:大数据是回暖的计算机行业中绩增速最高的子行业
- Solr基础教程之Schema.xml(二)
- 【CSS3】background-clip
- 基于S3C6410的ARM11学习(六) 核心初始化之关闭所有中断
- codeforces 629 D. Babaei and Birthday Cake dp + 线段树
- Building Mapnik dependencies on Windows
- linux字符驱动之异步通知按键驱动
- 【算法总结】Binary Tree & Binary Search Tree 二叉树
- Android自定义view-弹性ScrollView(上)
- LeetCode之Intersection of two linked list不同方法