zoukankan      html  css  js  c++  java
  • solr插件导入数据库中的数据

    solr插件导入数据库中的数据

    1:自定义与数据库对应的域:

    1.1. 设置业务系统Field

         如果不使用Solr提供的Field可以针对具体的业务需要自定义一套Field。

    例如:如下是商品信息Field:

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

    2、  批量导入数据:

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

    第一步:把dataimport插件依赖的jar包添加到solrcore(collection1lib)中,lib自己建。

    还需要mysql的数据库驱动。

     


    第二步:配置solrconfig.xml文件,添加一个requestHandler。(/solrHome/collectin1/conf/solrconfig.xml)

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

    第三步:创建一个data-config.xml,保存到collection1conf目录下

    <?xml version="1.0" encoding="UTF-8" ?>  
    <dataConfig>   
    <dataSource type="JdbcDataSource"   
              driver="com.mysql.jdbc.Driver"   
              url="jdbc:mysql://localhost:3306/lucene"   
              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>

     注意:<document>中包含数据库中的表名(product) ,查询语句,《fileld》中的column对应product表中的列名,name对应是上面我们自定义的域名。

    第四步:重启tomcat

     


    solr浏览器界面操作:

    2-1、删除索引格式如下:

     

    1) 删除制定ID的索引

    <delete>

           <id>8</id>

    </delete>

     

    2) 删除查询到的索引数据

    <delete>

           <query>product_catalog_name:幽默杂货</query>

    </delete>

    3) 删除所有索引数据

     <delete>

           <query>*:*</query>

    </delete>

    2-1. 查询索引

    通过/select搜索索引,Solr制定一些参数完成不同需求的搜索:

    q - 查询字符串,必须的,如果查询所有使用*:*。

    fq - (filter query)过虑查询,作用:在q查询符合结果中同时是fq查询符合的,例如:

     

     

     


  • 相关阅读:
    关于Visual Studio中的TraceDebugging文件夹
    没有App打得开发证书, 收不到推送
    转:ios应用崩溃日志揭秘
    转 iOS:NSAttributedString
    [UIDevice currentDevice].model
    转: Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
    NSTimer 增加引用计数, 导致内存泄露,
    matplotlib基础(2)
    matplotlib基础
    《python自然语言处理》(1)
  • 原文地址:https://www.cnblogs.com/dw3306/p/9660402.html
Copyright © 2011-2022 走看看