windows下Solr配置
一、配置中文分词器
1、在SolrCore(collection1)的conf目录下有schema.xml,它是Solr数据表配置文件,它定义了加入索引的数据的数据类型的。主要 包括FieldTypes、Fields和其他的一些缺省设置。
2、把IKAnalyzer2012FF_u1.jar添加到solr/WEB-INF/lib目录下。
3、复制IKAnalyzer的配置文件和自定义词典和停用词词典到Tomcat中solr的WEB-INF/classes目录下。(没有自己建)
4、在schema.xml中添加一个自定义的fieldType,使用中文分析器。
<!-- IKAnalyzer-->
<fieldType name="text_ik" class="solr.TextField">
<analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>
5、定义field,指定field的type属性为text_ik。
<!--IKAnalyzer Field-->
<field name="title_ik" type="text_ik" indexed="true" stored="true" />
<field name="content_ik" type="text_ik" indexed="true" stored="false" multiValued="true"/>
6、重启Tomcat,测试有没有配好。
![Center][]
二、业务配置
1、设置业务系统Field
如果不使用Solr提供的Field可以针对具体的业务需要自定义一套Field,如下是商品信息Field。也是在schema.xml中配置。
<!--product-->
<field name="product_name" type="text_ik" indexed="true" stored="true"/>
<field name="product_price" type="float" indexed="true" stored="true"/>
<field name="product_description" type="text_ik" indexed="true" stored="false" />
<field name="product_picture" type="string" indexed="false" stored="true" />
<field name="product_catalog_name" type="string" indexed="true" stored="true" />
<field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
<copyField source="product_name" dest="product_keywords"/>
<copyField source="product_description" dest="product_keywords"/>
![Center 1][]
2、使用dataimport插件批量导入数据。
(1)将dataimport所需的jar包添加到D:\\Others\\solrhome\\collection1\\lib中。
![Center 2][]
(2)配置solrconfig.xml,在D:\\Others\\solrhome\\collection1\\conf中,添加一个requestHandler。
<requestHandler name="/dataimport"
class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
![Center 3][]
(3)创建一个data-config.xml文件,保存到collection1\\conf\\目录下。该文件配置的是数据库表的字段和上文Solr中用于检索的 product下name字段的对应关系。在data-config.xml中也要配置数据库连接信息以及要导入哪个表。数据库中表的字段如下 图。
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"
user="root"
password="2109"/>
<document>
<entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">
<field column="pid" name="id"/>
<field column="name" name="product_name"/>
<field column="catalog_name" name="product_catalog_name"/>
<field column="price" name="product_price"/>
<field column="description" name="product_description"/>
<field column="picture" name="product_picture"/>
</entity>
</document>
</dataConfig>
![Center 4][]
3、重启Tomcat,点击execute导入数据,导入数据前会先清空索引库,再导入。可以选中下方的auto-refresh status按钮。
还没有评论,来说两句吧...