欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

solr 配置中文分析器/定义业务域/配置DataImport功能方法(测试用)

程序员文章站 2024-02-29 13:58:34
一、配置中文分析器 使用ikanalyzer 配置方法: 1)把ik的jar包添加到solr工程中/web-inf/lib目录下 2)把ik的配置文件扩展词典,放到...

一、配置中文分析器

使用ikanalyzer

配置方法:

1)把ik的jar包添加到solr工程中/web-inf/lib目录下

2)把ik的配置文件扩展词典,放到classpath下。/web-inf/classes目录下

3)在schema.xml中定义fieldtype,指定使用ik作为分析器

<!-- ikanalyzer-->
  <fieldtype name="text_ik" class="solr.textfield">
   <analyzer class="org.wltea.analyzer.lucene.ikanalyzer"/>
  </fieldtype>

4)重启tomcat

二、业务域的定义

1)创建数据库

需要导入的字段:pid,name,catelog_name,price,description,picture

2)每个字段需要对应索引库中的一个field

一条记录对应一个document,一个字段对应一个域

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

三、配置dataimport功能(测试用)

步骤:

1、把dataimport插件需要的jar包添加到solr中

solr-dataimporthandler-4.10.3.jar
solr-dataimporthandler-extras-4.10.3.jar

可以放到solrhome/collection1/lib目录下

2、需要mysql的数据库驱动的jar包

可以放到collection1/lib目录下

3、需要在solrconfig.xml添加一个requesthandler处理器

<requesthandler name="/dataimport" class="org.apache.solr.handler.dataimport.dataimporthandler">
  <lst name="defaults">
  <str name="config">data-config.xml</str>
  </lst>
  </requesthandler>

4、在solrconfig.xml配置文件所在的目录添加一个data-config.xml文件

配置连接数据库的连接串

查询数据库的sql语句

结果集和索引库的映射关系

<?xml version="1.0" encoding="utf-8" ?> 
<dataconfig>  
<datasource type="jdbcdatasource"  
     driver="com.mysql.jdbc.driver"  
     url="jdbc:mysql://localhost:3306/solr"  
     user="root"  
     password="root"/>  
<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>

5、重启tomcat

以上这篇solr 配置中文分析器/定义业务域/配置dataimport功能方法(测试用)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。