天天看点

solr运行配置与数据库数据导入到solr

 一、运行

  1,solr运行容器,tomcat

  2,拷贝apache-solr-3.6.0.war到tomcat的webapps目录下,并改名为solr.war

  3,tomcat的conf目录下建立结构为conf/catalina/localhost的两个文件夹。建立结构为solr-tomcat/solr的两个文件夹(solr的home目录),如建在d盘根目录,d:/solr-tomcat/solr,solr-tomcat文件夹名字可任意命名,将apache-solr-3.6.0\example\solr下的所有文件及文件夹拷贝到这下面

  4,在localhost文件夹下建立solr.xml,并保存如下内容:

<context docbase="d:\tomcat-6.0\webapps\solr.war" debug="0" crosscontext="true" >

</context>

  5,此时可以运行tomcat,地址栏输入:http://localhost:8080/solr/admin进行验证

  7,更改solr home目录下的conf/solrconfig.xml,添加如下内容:

<requesthandler name="/dataimport" class="org.apache.solr.handler.dataimport.dataimporthandler">

<lst name="defaults">

<str name="config">d:\solr-tomcat\solr\db\conf\db-data-config.xml</str> <!--  根据自己电脑里的db-data-config.xml的实际路径来写 -- >

</lst>

</requesthandler>

  8, 将solr home目录下面的solrconfig.xml和schema.xml拷贝到db文件夹下面的conf中,注意:导入的字段要先在schema.xml中定义

  定义如:<field name="firstname" type="string" stored="true" indexed="true"/>

  9,修改db\conf\db-data-config.xml,可参考如下:

<dataconfig>

<datasource type="jdbcdatasource" driver="com.mysql.jdbc.driver" url="jdbc:mysql://localhost:3306/langsin1" user="root" password="root"/>

<document name="userss">

<entity name="users" pk="id" query="select * from users">

<field column="id" name="id" />

<field column="firstname" name="firstname" />

<field column="lastname" name="lastname" />

<field column="age" name="age" />

</entity>

</document>

</dataconfig>

  10,启动tomcat,输入地址进行导入,导入分为很多模式:我选用的全部倒入模式

  http://localhost:8080/solr/db/dataimport?command=full-import

  <connector port="8080" protocol="http/1.1"

  connectiontimeout="20000"

  redirectport="8443" uriencoding="utf-8"

  12,添加中文分词,如:mmseg4j, 在$solr_home下建立lib和dic两个目录,讲mmseg4j-all-1.8.4.jar拷贝到lib目录,将data里的.dic文件拷贝到dic目录

13,修改schema.xml

  添加fieldtype

  xml代码

<types>

<fieldtype name="textcomplex" class="solr.textfield" positionincrementgap="100" >

<analyzer>

<tokenizer class="com.chenlb.mmseg4j.solr.mmsegtokenizerfactory" mode="complex" dicpath="/opt/solr/example/solr/dic"/>

<filter class="solr.lowercasefilterfactory"/>

</analyzer>

</fieldtype>

<fieldtype name="textmaxword" class="solr.textfield" positionincrementgap="100" >

<tokenizer class="com.chenlb.mmseg4j.solr.mmsegtokenizerfactory" mode="max-word" dicpath="/opt/solr/example/solr/dic"/>

<fieldtype name="textsimple" class="solr.textfield" positionincrementgap="100" >

<tokenizer class="com.chenlb.mmseg4j.solr.mmsegtokenizerfactory" mode="simple" dicpath="/opt/solr/example/solr/dic"/>

..

</types>

<fieldname="simple"type="textsimple"indexed="true"stored="true"multivalued="true"/>

<fieldname="complex"type="textcomplex"indexed="true"stored="true"multivalued="true"/>

<fieldname="maxword"type="textmaxword"indexed="true"stored="true"multivalued="true"/>

<copyfield source="simple" dest="text"/>

<copyfield source="complex" dest="text"/>

  14,重启tomcat,

  进入 http://yourhost:8080/solr-example/admin/analysis.jsp,测试中文分词

最新内容请见作者的github页:http://qaseven.github.io/