Ubuntu搭建solr搜索服务器

参考:http://blog.csdn.net/makang110/article/details/50971705

一:搭建solr服务器

1:安装jdk1.7,并配置环境变量

2:下载tomcat 7,并解压缩:本文解压缩到根目录下    /tomcat下

3:下载solr  4.13,并解压缩到 /solr目录下

4:复制/solr4.13/example/webapps下面的solr.war到 /tomcat7/webapps 下面,

5:启动tomcat,solr.war将会自动解压,

6:关闭tomcat,删除sorl.war   :要不然每次启动tomcat,都会重新发布solr

7:复制/solr/solr4.13/example/resources/  下面的log4j.properties  到/tomcat/tomcat7/webapps/solr/WEB-IINF/classes下面。(classes自己创建目录)

8:修改/tomcat/tomcat7/webapps/solr/WEB-IINF目录下的web.xml文件。将地址指向example下面solr工程所在的位置

      <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>/solr/solr4.13/example/solr</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

9:启动tomcat,成功。

二添加ik分词

   ik分词粒度较细,paoding容易扩展词典

    1:下载ik分词器,并解压缩

        2:将ik分词器的jar包IKAnalyzer2012FF_u1.jar复制到/tomcat/tomcat7/webapps/solr/WEB-INF/lib下面

 

           3:将 IKAnalyzer.cfg.xml                ext_stopword.dic                    mydict.dic            复制到/tomcat/tomcat7/webapps/solr/WEB-INF/classes目录下,注意必须保存为utf-8类型

4:修改solr 下面shcema.xml文件   /solr/solr4.13/example/solr/collection1/conf/schema.xml  ,添加fieldtype

<fieldType name="text_ik" class="solr.TextField">

<analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>

</fieldType>

5:设置业务系统Field

业务字段判断标准:

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

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

需要用到的字段:自己配置

    1. 商品id

    2. 商品title

    3. 卖点

    4. 价格

    5. 商品图片

    6. 商品分类名称

    7. 商品描述

 

/solr/solr4.13/example/solr/collection1/conf/schema.xml中添加:

<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" />  <!--这个域只搜索,不展示,所以不存储-->

 


 <!--复制域,一个item_keywords代表下面的几个域,以后想在下面几个域中搜索时,用这一个域item_keywords就行了-->

<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"/>

 

      

         

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/liyafei/p/8005571.html