随笔 - 14  文章 - 0  评论 - 0 

solr 本地搭建

 
1. 运行
D:\solr-4.7.2\example
--> java -jar start.jar
 
2. 添加插件IK
D:\solr-4.7.2\example\solr-webapp\webapp\WEB-INF\classes
-->IKAnalyzer.cfg.xml
-->stopword.dic
 
D:\solr-4.7.2\example\solr-webapp\webapp\WEB-INF\lib
-->IKAnalyzer2012FF_u1.jar
一定要用这个版本的,兼容 solr 4.7.2
 
3.schema.xml  使用IK进行索引和分词查询
-->    <fieldType name="text_ik" class="solr.TextField">
-->           <analyzer type="index" isMaxWordLength="false"
-->               class="org.wltea.analyzer.lucene.IKAnalyzer"/>
-->          <analyzer type="query" isMaxWordLength="true"
-->                class="org.wltea.analyzer.lucene.IKAnalyzer"/>
-->        </fieldType>
 
4. mysql 数据库进行分词索引
solrconfig.xml  添加数据库导入缓存或更新缓存
-->  <requestHandler name="/dataimport" -->        class="org.apache.solr.handler.dataimport.DataImportHandler">
-->    <lst name="defaults">
-->      <str name="config">data-config.xml</str>
-->    </lst>
-->   </requestHandler>
 
5.需要的jar包
D:\solr-4.7.2\example\solr-webapp\webapp\WEB-INF\lib
mysql-connector-java-5.1.25.jar
solr-dataimporthandler-4.7.2.jar
solr-dataimporthandler-extras-4.7.2.jar
 
 
6.data-config.xml
<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.10.15:3306/wenda" user="root" password="root@sg"/>
    <document name="wendaQuestion">
        <entity pk="id" name="question"  query="select * from wenda_question where delete_flag != 1"
             deltaQuery="select id from wenda_question where updated_at > '${dataimporter.last_index_time}'"
             deletedPkQuery="select id from wenda_question where delete_flag = 1"  
             deltaImportQuery="select * from wenda_question where ID='${dataimporter.delta.ID}'"
            >
 
            <field column="id" name="id" />
            <field column="title" name="title" />
            <field column="answer_count" name="answerCount" />
            <field column="default_category_id" name="categoryId" />
            <entity name="categoryids" query="SELECT GROUP_CONCAT(catagory_id) as categoryids FROM wenda_question_category_ref t WHERE  question_id ='${question.id}'" />
            <entity name="acceptCount" query="SELECT COUNT(1) AS acceptCount FROM wenda_answer  WHERE accept_flag = 1 AND   question_id ='${question.id}'" />
 
        </entity>
    </document>
</dataConfig>
 
7.schema.xml 字段映射
   <field name="id" type="long" indexed="true" stored="true"  required="true" />
   <field name="title" type="text_ik" indexed="true" stored="true" />
   <field name="answerCount" type="long" indexed="true" stored="true"   />
   <field name="categoryId" type="long" indexed="true" stored="true"   />
   <field name="categoryids"  type="string" indexed="true" stored="true"  />
   <field name="acceptCount" type="long" indexed="true" stored="true"   required="true" />
 
8.elevate.xml  id 为long 出错修复  MA147LL/A 换成 1    IW-02 换成 2
<query text="ipod">
   <doc id="1" />  <!-- "MA147LL/A" put the actual ipod at the top -->
   <doc id="2" exclude="true" /> <!-- "IW-02"exclude this cable -->
</query>
 



来自为知笔记(Wiz)



posted on 2015-08-28 09:30  知识铺  阅读(94)  评论(0编辑  收藏