现在的位置: 首页 > 综合 > 正文

solr dataimport 的配置

2012年09月21日 ⁄ 综合 ⁄ 共 6142字 ⁄ 字号 评论关闭

1)在solrconfig.xml增加

 <!--新增加的配置-->
   <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">

      <str name="config">data-config.xml</str>
    
    </lst>
  </requestHandler>

2)然后在solrconfig.xml同一个目录下,即是solr home目录下增加 data-config.xml 文件

 

<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="123456"/>
    <document name="movieDoc">
        <entity name="movie" transformer="RegexTransformer,DataToIntTransformer" query="select * from movie" >
        
            <field column="actors" splitBy="," sourceColName="actors"/>
            <field column="director" splitBy="," sourceColName="director"/>
         
            <entity name="type" query="select id as tid from movie_type where mid='${movie.mid}'">
                <field name="tid" column="tid" />
            </entity>
             <entity name="language" query="select id as lid from movie_language where mid='${movie.mid}'">
                <field name="lid" column="lid" />
            </entity>
             <entity name="zone" query="select id as zid from movie_zone where mid='${movie.mid}'">
                <field name="zid" column="zid" />
            </entity>
            
             <entity name="detail" query="select sub_index,title,vid  from movie_detail where mid='${movie.mid}' and chk_yn='y'">
                <field name="sub_index" column="sub_index" />
                <field name="title" column="title" />
                <field name="vid" column="vid" />
            </entity>
            <!--
            <entity name="item_category" query="select CATEGORY_ID from item_category where item_id='${item.ID}'">
                <entity name="category" query="select description from category where id = '${item_category.CATEGORY_ID}'">
                    <field column="description" name="cat" />
                </entity>
            </entity>
            -->
        
        </entity>
    </document>
</dataConfig>

3)加入相关的jar包,apache-solr-dataimporthandler-1.4.0.jar,apache-solr-dataimporthandler-extras-1.4.0.jar,mysql-connector-java-5.1.10.jar

 

启动tomcat,访问http://localhost:8080/solr/dataimport?command=full-import 将数据全部导入solr服务器进行索引

访问http://localhost:8080/solr/dataimport?command=status可以查看运行状态

当修改data-config.xml 文件配置时运行http://localhost:8080/solr/dataimport?command=reload-config可以进行重新加载配置文件

如果想终止运行http://localhost:8080/solr/dataimport?command=abort

 

 要建立自己的全文检索,一般都需要从数据库导入数据,在原来配置的基础上,增加导入的功能 


1、D:\apache-tomcat-7.0.27\solr\conf\solrconfig.xml中增加 

Xml代码  收藏代码
  1. <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">  
  2.     <lst name="defaults">  
  3.           <str name="config">data-config.xml</str>  
  4.     </lst>  
  5. </requestHandler>  


2、增加D:\apache-tomcat-7.0.27\solr\conf\data-config.xml,内容为数据库的连接信息 

Xml代码  收藏代码
  1.   <?xml version="1.0" encoding="UTF-8"?>  
  2. <dataConfig>  
  3. <dataSource type="JdbcDataSource" driver="oracle.jdbc.driver.OracleDriver"  
  4.     url="jdbc:oracle:thin:@10.74.8.206:1521:orcl"  
  5.     user="uname"  
  6.     password="pwd"/>  
  7.   
  8. <document name="zpxx">           
  9.     <entity name="zpxx" query="select * from vw_zp_fullindex" transformer="ClobTransformer">                    
  10.                 <field column="GANG_WEI_BH"      name="GANG_WEI_BH"      />  
  11.                 <field column="GANG_WEI_MC"      name="GANG_WEI_MC"      />  
  12.                 <field column="GANG_WEI_MS"      name="GANG_WEI_MS"       clob="true"/>  
  13.                 <field column="GONG_ZU_DD_ZW"    name="GONG_ZU_DD_ZW"    />  
  14.                 <field column="QI_TA"            name="QI_TA"            />  
  15.                 <field column="YUE_XIN"          name="YUE_XIN"          />  
  16.                 <field column="ZHI_CHENG"        name="ZHI_CHENG"        />  
  17.                 <field column="GANGWEILB"        name="GANGWEILB"        />  
  18.                 <field column="COMPID"           name="COMPID"           />  
  19.                 <field column="DAN_WEI_MC"       name="DAN_WEI_MC"       />  
  20.                 <field column="DANWEIXZ"     name="DANWEIXZ"         />  
  21.                 <field column="JING_YING_FW" name="JING_YING_FW"     />  
  22.                 <field column="DAN_WEI_JJ"       name="DAN_WEI_JJ"        clob="true"/>  
  23.                 <field column="DAN_WEI_DZ"       name="DAN_WEI_DZ"       />  
  24.                 <field column="HANGYELB"     name="HANGYELB"         />  
  25.     </entity>  
  26. </document>  
  27. </dataConfig>  


因为有Clob字段,所以需要加上ClobTransformer 
3、D:\apache-tomcat-7.0.27\solr\conf\schema.xml文件中增加 

Xml代码  收藏代码
  1.  <!--自定义Field开始 -->  
  2.             <field name="GANG_WEI_BH"        type="string" indexed="true" stored="true" required="true"/>  
  3.             <field name="GANG_WEI_MC"        type="text" indexed="true" stored="true" />  
  4.             <field name="GANG_WEI_MS"        type="text" indexed="true" stored="true" />  
  5.             <field name="GONG_ZU_DD_ZW"      type="text" indexed="true" stored="true" />  
  6.             <field name="QI_TA"              type="text" indexed="true" stored="true" />  
  7.             <field name="YUE_XIN"            type="text" indexed="true" stored="true" />  
  8.             <field name="ZHI_CHENG"          type="text" indexed="true" stored="true" />  
  9.             <field name="GANGWEILB"          type="text" indexed="true" stored="true" />  
  10.             <field name="COMPID"         type="string" indexed="true" stored="true" />  
  11.             <field name="DAN_WEI_MC"     type="text" indexed="true" stored="true" />  
  12.             <field name="DANWEIXZ"           type="text" indexed="true" stored="true" />  
  13.             <field name="JING_YING_FW"       type="text" indexed="true" stored="true" />  
  14.             <field name="DAN_WEI_JJ"     type="text" indexed="true" stored="true" />  
  15.             <field name="DAN_WEI_DZ"     type="text" indexed="true" stored="true" />  
  16.             <field name="HANGYELB"           type="text" indexed="true" stored="true" />    
  17. <!--自定义Field结束 -->  
  18.   
  19.   <copyField source="DAN_WEI_JJ" dest="text"/><!--clob字段 -->  
  20.   <copyField source="GANG_WEI_MS" dest="text"/>  


把原有文件中id字段的required="true"去掉,否则导入的时候,会验证id字段,其实自己在做的时候,如果其他字段没有的话,可以删除 
3、还要把oracle的jdbc驱动放到D:\apache-tomcat-7.0.27\webapps\solr\WEB-INF\lib 
4、http://localhost:8080/solr/dataimport?command=full-import即可以进行导入数据 
5、查询则通过http://localhost:8080/solr/admin/进行查询,输入查询字符串(Query String)"DAN_WEI_JJ:计算机"即可以查看全文检索结果

抱歉!评论已关闭.