windows下Solr配置

青旅半醒 2022-06-07 22:17 297阅读 0赞

一、配置中文分词器

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,使用中文分析器。

  1. <!-- IKAnalyzer-->
  2. <fieldType name="text_ik" class="solr.TextField">
  3. <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
  4. </fieldType>

5、定义field,指定field的type属性为text_ik。

  1. <!--IKAnalyzer Field-->
  2. <field name="title_ik" type="text_ik" indexed="true" stored="true" />
  3. <field name="content_ik" type="text_ik" indexed="true" stored="false" multiValued="true"/>

6、重启Tomcat,测试有没有配好。

  1. ![Center][]

二、业务配置

1、设置业务系统Field

  1. 如果不使用Solr提供的Field可以针对具体的业务需要自定义一套Field,如下是商品信息Field。也是在schema.xml中配置。
  2. <!--product-->
  3. <field name="product_name" type="text_ik" indexed="true" stored="true"/>
  4. <field name="product_price" type="float" indexed="true" stored="true"/>
  5. <field name="product_description" type="text_ik" indexed="true" stored="false" />
  6. <field name="product_picture" type="string" indexed="false" stored="true" />
  7. <field name="product_catalog_name" type="string" indexed="true" stored="true" />
  8. <field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
  9. <copyField source="product_name" dest="product_keywords"/>
  10. <copyField source="product_description" dest="product_keywords"/>
  11. ![Center 1][]

2、使用dataimport插件批量导入数据。

  1. (1)将dataimport所需的jar包添加到D:\\Others\\solrhome\\collection1\\lib中。
  2. ![Center 2][]
  3. (2)配置solrconfig.xml,在D:\\Others\\solrhome\\collection1\\conf中,添加一个requestHandler
  4. <requestHandler name="/dataimport"
  5. class="org.apache.solr.handler.dataimport.DataImportHandler">
  6. <lst name="defaults">
  7. <str name="config">data-config.xml</str>
  8. </lst>
  9. </requestHandler>
  10. ![Center 3][]
  11. (3)创建一个data-config.xml文件,保存到collection1\\conf\\目录下。该文件配置的是数据库表的字段和上文Solr中用于检索的 productname字段的对应关系。在data-config.xml中也要配置数据库连接信息以及要导入哪个表。数据库中表的字段如下 图。
  12. <?xml version="1.0" encoding="UTF-8" ?>
  13. <dataConfig>
  14. <dataSource type="JdbcDataSource"
  15. driver="com.mysql.jdbc.Driver"
  16. url="jdbc:mysql://localhost:3306/test"
  17. user="root"
  18. password="2109"/>
  19. <document>
  20. <entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">
  21. <field column="pid" name="id"/>
  22. <field column="name" name="product_name"/>
  23. <field column="catalog_name" name="product_catalog_name"/>
  24. <field column="price" name="product_price"/>
  25. <field column="description" name="product_description"/>
  26. <field column="picture" name="product_picture"/>
  27. </entity>
  28. </document>
  29. </dataConfig>
  30. ![Center 4][]

3、重启Tomcat,点击execute导入数据,导入数据前会先清空索引库,再导入。可以选中下方的auto-refresh status按钮。Center 5

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读

    相关 windowsSolr配置

    一、配置中文分词器 1、在SolrCore(collection1)的conf目录下有schema.xml,它是Solr数据表配置文件,它定义了加入索引的数据的数据类型的。主