该文使用  Centos6.5 64 位    solr4.10.3   IK-Analyzer中文分析器

一、solr域

在solr中域的概念与lucene中域的概念相同,数据库的一条记录或者一个文件的信息就是一个document,数据库记录的字段或者文件的某个属性就是一个Field域,solr中对索引的检索也是对Field的操作。lucene中对域的操作是通过代码,solr对域的管理是通过一个配置文件schema.xml。

solr中域的类型是schema.xml中<fieldType>元素常用的field类型

 <!--string 类型 在存储索引时不进行分词   sortMissingLast:设置为true时 没有该filed的数据将排在有该Field的数据后面,忽略请求时的排序规则,默认为false。-->
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<!-- boolean 类型只有两个值 true false-->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/> <!--用于直接数值搜索,该类型不分词 -->
<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"/> <!--用于数值范围搜索,进行分词 通过设置precisionStep的值可以提高检索速度,8是solr的推荐值 -->
<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"/>
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
<!--二进制类型-->
<fieldtype name="binary" class="solr.BinaryField"/>
<!--随机数类型-->
<fieldType name="random" class="solr.RandomSortField" indexed="true" /> <!-- text_general 类型 进行分词 -->
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<!--创建索引时的配置 -->
<analyzer type="index">
<!-- tokenizer 创建索引使用的分词器 -->
<tokenizer class="solr.StandardTokenizerFactory"/>
<!--filter 分词时的过滤器 class="solr.StopFilterFactory" 处理停用词 words:配置停用词-->
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<!-- filter 分词时的过滤器 class="solr.LowerCaseFilterFactory" 处理大小写转换问题(将大写转小写)-->
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<!--查询索引时的配置 -->
<analyzer type="query">
<!-- tokenizer 对查询条件分词时使用的分词器 -->
<tokenizer class="solr.StandardTokenizerFactory"/>
<!--filter 分词时的过滤器 class="solr.StopFilterFactory" 处理停用词 words:配置停用词-->
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
<!--filter 分词时的过滤器 class="solr.SynonymFilterFactory" 处理同义词 synonyms:配置同义词-->
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<!-- filter 分词时的过滤器 class="solr.LowerCaseFilterFactory" 处理大小写转换问题(将大写转小写)-->
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>

solr在操作Field域时需要在schema.xml中定义(根据自己的业务需求自定义)。

 <!--name域的名称  type:域的类型  indexed:是否使用该域搜索
stored:是否存储 如果不存储在查询时是查不到该域的 但可以进行搜索
multiValued:是否支持存储多值
-->
<field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="subject" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>
<field name="comments" type="text_general" indexed="true" stored="true"/>
<field name="author" type="text_general" indexed="true" stored="true"/>
<field name="keywords" type="text_general" indexed="true" stored="true"/>
<field name="category" type="text_general" indexed="true" stored="true"/>
<field name="resourcename" type="text_general" indexed="true" stored="true"/>
<field name="url" type="text_general" indexed="true" stored="true"/>
<field name="content_type" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="last_modified" type="date" indexed="true" stored="true"/>
<field name="links" type="string" indexed="true" stored="true" multiValued="true"/>

 1、唯一域

 <!-- id 域 也叫唯一域 每一个文档必须有唯一域 -->
<uniqueKey>id</uniqueKey>

2、动态域

   <!-- 动态域  *_i:通配符 -->
<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" />
<dynamicField name="*_ss" type="string" indexed="true" stored="true" multiValued="true"/>

3、复制域 copyField 可以将多个Field复制到一个Field中,一便进行统一检索

<copyField source="title" dest="text"/>

例如:搜索title标题、description内容 、author作者,我们可以定义title、description、author的复制域

a、先创建域

  <field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="author" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>
<field name="keywords" type="text_general" indexed="true" stored="false"/>

b、创建copyField 域

 <!--source:源域   dest:目标域 -->
<copyField source="title" dest="keywords"/>
<copyField source="author" dest="keywords"/>
<copyField source="description" dest="keywords"/>

c、配置完成后导入索引。

二、配置中文分析器

在solr中默认是中文分析器,需要手工配置。配置一个FieldType,在FieldType中指定中文分析器。

1、使用 IK-Analyzer中文分析器   将该分析器文件上传服务器  /opt/tools/IK Analyzer 2012FF_hf1

2、将需要把分析器的jar包(IKAnalyzer2012FF_u1.jar)添加到solr工程中。

[root@localhost IK Analyzer 2012FF_hf1]# cp IKAnalyzer2012FF_u1.jar /usr/local/solr4/tomcat7/webapps/solr/WEB-INF/lib/

3、把IKAnalyzer需要的扩展词典及停用词词典、配置文件复制到solr工程的classpath。

  (1) 在usr/local/solr4/tomcat7/webapps/solr/WEB-INF/目录下创建classes目录  [root@localhost WEB-INF]# mkdir classes

  (2)复制文件 [root@localhost IK Analyzer 2012FF_hf1]# cp IKAnalyzer.cfg.xml ext_stopword.dic mydict.dic /usr/local/solr4/tomcat7/webapps/solr/WEB-INF/classes

  ext_stopword.dic:扩展词词典

  mydict.dic:停用词词典

  注意:扩展词典及停用词词典的字符集必须是utf-8。不能使用windows记事本编辑。

4、配置fieldType。需要在solrhome/collection1/conf/schema.xml中配置。技巧:使用vi、vim跳转到文档开头gg。跳转到文档末尾:G

在文件末尾添加fieldType

<fieldType name="text_ik" class="solr.TextField">
<analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>

name="text_ik":一个标识可以随便写

class="solr.TextField":分词分析器

二、配置业务字段

Solr中的字段必须是先定义后使用。该配置要与我们的实际业务关联。

业务字段判断标准:

1、在搜索时是否需要在此字段上进行搜索。例如:商品名称、商品的卖点、商品的描述

2、后续的业务是否需要用到此字段。例如:商品id。

本人这次项目需要用到的字段:

1、商品id

2、商品title

3、卖点sell_point

4、价格price

5、商品图片image

6、商品分类名称category_name

7、商品描述item_des

在solrhome/collection1/conf/schema.xml 中添加 Solr中的业务字段:

id——商品id

其他的对应字段创建solr的字段。

<field name="item_title" type="text_ik" indexed="true" stored="true"/>
<field name="item_sell_point" type="text_ik" indexed="true" stored="true"/>
<field name="item_price" type="long" indexed="true" stored="true"/>
<field name="item_image" type="string" indexed="false" stored="true" />
<field name="item_category_name" type="string" indexed="true" stored="true" />
<field name="item_desc" type="text_ik" indexed="true" stored="false" /> <!-- 创建复制域 将其他域上的搜索关键词都复制到一个域上 是solr对搜所的优化--> <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<copyField source="item_title" dest="item_keywords"/>
<copyField source="item_sell_point" dest="item_keywords"/>
<copyField source="item_category_name" dest="item_keywords"/>
<copyField source="item_desc" dest="item_keywords"/>

将数据写入索引库的字段要与该配置相同。

重启tomcat

solr学习之域的管理与中文分析器配置的更多相关文章

  1. Solr学习总结(八)IK 中文分词的配置和使用

    最近,很多朋友问我solr 中文分词配置的问题,都不知道怎么配置,怎么使用,原以为很简单,没想到这么多朋友都有问题,所以今天就总结总结中文分词的配置吧. 有的时候,用户搜索的关键字,可能是一句话,不是 ...

  2. Solr学习笔记(3) —— SolrJ管理索引库&集群

    一.什么是SolrJ solrj是访问Solr服务的java客户端,提供索引和搜索的请求方法,SolrJ通常嵌入在业务系统中,通过SolrJ的API接口操作Solr服务,如下图: 二.SolrJ的基本 ...

  3. solr学习篇(一) solr7.4 安装配置篇

    目录: solr简介 solr安装 创建core 1.solr简介 solr是企业级应用的全文检索项目,它是基于Apache Lucence搜索引擎开发出来的用于搜索的应用工程 运行环境:solr需要 ...

  4. lucene&solr学习——solr学习(一)

    1.什么是solr solr是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文检索服务器.Solr提供了比lucene风味丰富的查询语言,同时实现了可配置,可扩展,并对索 ...

  5. (转)淘淘商城系列——中文分析器IK-Analyzer的使用

    在Solr中默认是没有中文分析器的,需要手工配置,配置一个FieldType,在FieldType中指定使用的中文分析器.另外,Solr中的字段(即业务域)必须先定义后使用.下面我们先把中文分析器配好 ...

  6. Solr学习笔记之2、集成IK中文分词器

    Solr学习笔记之2.集成IK中文分词器 一.下载IK中文分词器 IK中文分词器 此文IK版本:IK Analyer 2012-FF hotfix 1 完整分发包 二.在Solr中集成IK中文分词器 ...

  7. solr创建业务域以及指定中文分析器IK

    第一步:把中文分析器添加到工程中. 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下 ...

  8. Centos7系统环境下Solr之Java实战(二)制定中文分析器、配置业务域

    制定中文分析器 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下. 配置一个Fiel ...

  9. 推荐学习《组织与管理研究的实证方法(第2版)》中文PDF

    在写文章论文时,会涉及到观点论证,需要掌握一些实证方法. 建议学习<组织与管理研究的实证方法(第2版)>,对管理研究中涉及的方法进行了介绍,例如实验室研究,二手数据的研究,实地研究等,这对 ...

随机推荐

  1. oracle之 ORA-12557: TNS: 协议适配器不可加载

    操作系统:windows 7数据库版本: 11.2.0.1问题描述:直接通过 sqlplus sys/oracle@10.10.100.109:1521/ysxt as sysdba 可以登录,但是通 ...

  2. checkbox复选框,如何让其勾选时触发一个事件,取消勾选时不触发

    <input type="checkbox" onclick="checkboxOnclick(this)" /> <script> f ...

  3. PCA原理解释

      上图讲述的两组数据,可以看到左图的数据离散度比较大,相关性比较弱,右图数据的相关性比较强:我们在使用PCA的时候,就是要将相关性强的数据进行降维,以减少处理的数据量. 那么怎么描述数据的相关性呢? ...

  4. 读懂 PetaLinux:让 Linux 在 Zynq 上轻松起“跑”(转)

    对于Zynq这样一个“ARM+可编程逻辑”异构处理系统我们已经不陌生,其创新性大家也有目共睹.不过想要让更多的应用享受到这一“创新”带来的红利,让其真正“落地”则需要大量系统性的工作,去营造一个完善的 ...

  5. C# 抽象类和密闭方法

    抽象类abstract: 1.抽象类只存在一个目的就是被继承:2.抽象类不能够实例化,只能够被继承:3.抽象类可以包含抽象成员和普通成员,以及他们的任意组合:4.抽象类的抽象成员在派生类中需要使用ov ...

  6. tornado请求头/状态码/接口 笔记

    set_header()/set_default_headers() set_header():设置请求头数据 set_default_headers():设置默认请求头数据 import torna ...

  7. 使用zlib来压缩文件-用delphi描述

    今天用到压缩文件的问题,找了一些网上的资料,后来发现了delphi自身所带的zlib单元,根据例子稍微改变了一些,使它能够符合所有的格式. 使用时,需要Zlib.pas和 Zlibconst.pas两 ...

  8. C# .NET 4.5 将多个文件添加到压缩包中

    string zipFilePath = @"d:\test.zip"; string file1 = @"D:\门头照处理\门店照片2018-3-19 wuxl\门店照 ...

  9. InfluxDB学习之InfluxDB的基本操作| Linux大学

    来源地址:https://www.linuxdaxue.com/influxdb-study-series-manual.html 本文属于<InfluxDB系列教程>文章系列,该系列共包 ...

  10. [蓝桥杯]ALGO-8.算法训练_操作格子

    题目描述: 问题描述 有n个格子,从左到右放成一排,编号为1-n. 共有m次操作,有3种操作类型: .修改一个格子的权值, .求连续一段格子权值和, .求连续一段格子的最大值. 对于每个2.3操作输出 ...