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


    一、配置中文分析器
        使用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

  • 相关阅读:
    Java方法命名之“由简入繁”原则
    设置Tomcat的字符编码
    MyBatis之会话Session原理
    SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1fa5519] was not registered for synchronization because synchronization is not active
    python3 驱动 PyMySQL
    win 7 64 安装 MondgoDB 3.4
    Python
    win 7 64 安装 tensorflow
    俞敏洪:2017年上半年我的阅读书单和笔记 转
    阿里巴巴开源产品列表 转
  • 原文地址:https://www.cnblogs.com/javaxiaoxin/p/7507155.html
Copyright © 2020-2023  润新知