您的位置:首页 > 数据库

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

2014-01-14 12:59 435 查看
一,运行

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

<Environment name="solr/home" type="java.lang.String" value="D:/solr-tomcat/solr" override="true" />

</Context>

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

6,开始为导入数据库数据添加配置。将jdbc驱动jar和apache-solr-3.6.0\dist\apache-solr-dataimporthandler-3.6.0.jar 两个jar拷贝到tomcat的webapps/solr/WEB-INF/lib下。将apache-solr-3.6.0\example\example-DIH\solr下的所有文件及文件夹拷贝(并覆盖)到solr的HOME目录,如:d:/solr-tomcat/solr

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
11,如果有中文,修改tomcat的server.xml文件

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

<analyzer>

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

<filter class="solr.LowerCaseFilterFactory"/>

</analyzer>

</fieldType>

<fieldType name="textSimple" class="solr.TextField" positionIncrementGap="100" >

<analyzer>

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

<filter class="solr.LowerCaseFilterFactory"/>

</analyzer>

</fieldType>

..

</types>

Xml代码





<field name="simple" type="textSimple" indexed="true" stored="true" multiValued="true"/>

<field name="complex" type="textComplex" indexed="true" stored="true" multiValued="true"/>

<field name="maxword" type="textMaxWord" indexed="true" stored="true" multiValued="true"/>

Xml代码





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

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

14,重启tomcat,
进入 http://yourhost:8080/solr-example/admin/analysis.jsp,测试中文分词
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: