qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          solr4.0環境搭建

           

          solr4.0環境搭建

          因近期想搞個知識庫,所以選擇solr,現在最新的solr是4.0,所以用solr4.0。

          服務器:tomcat6

            JDK   :1.6

           SOLR :4.0

          中文分詞器 :ik-analyzer,mmseg4j


          安裝:目前mmseg4j的版本是mmseg4j-1.9.0.v20120712-SNAPSHOT,經過測試,發現這個版本有bug:

          	java.lang.RuntimeException: java.lang.NoSuchMethodError: org.apache.l 	ucene.analysis.Tokenizer.reset(Ljava/io/Reader;)V
          	由于solr4.0對其中的有些類與方法做了調整,所以還是等待mmseg4j新版本修復吧。果斷使用了ik-analyzer。
              一、將apache-solr-4.0.0\example\webapps\solr.war放在tomcat的webapps下啟動服務器解壓該war包,另外還需要增加幾個jar包:
          	apache-solr-dataimporthandler-4.0.0.jar
          	apache-solr-dataimporthandler-extras-4.0.0.jar
          	這兩個jar包可以在solr的dist中可以找到
          	另外還需要相應數據庫的驅動包,比如
          	mysql-connector-java-5.1.13-bin.jar
              二、將apache-solr-4.0.0\example下的solr拷貝至apache-tomcat-6.0.29-solr\bin下
              三、在apache-tomcat-6.0.29-solr\bin\solr\collection1\conf下的solrconfig.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>   

              四、將apache-tomcat-6.0.29-solr\bin\solr\collection1\conf下增加data-config.xml文件,內容如下:
          	
          1. <dataConfig>    
          2.     <dataSource type="JdbcDataSource"    
          3.    driver="com.mysql.jdbc.Driver"    
          4.    url="jdbc:mysql://localhost:3306/solrdb"    
          5.    user="root"    
          6.    password="888888"/>    
          7.     <document name="content">    
          8.         <entity name="node" query="select id,author,title,content from solrdb">    
          9.             <field column="id" name="id" />    
          10.             <field column="author" name="author" />    
          11.             <field column="title" name="title" />    
          12.             <field column="content" name="content" />  
          13.         </entity>    
          14.     </document>    
          15. </dataConfig>  
           
              五、增加中文分詞器,ik-analyzer的配置如下:
          	它的安裝部署十分簡單,將IKAnalyzer2012.jar部署亍項目的lib目錄中;IKAnalyzer.cfg.xml不stopword.dic文件放置在class根目錄對于web項目,通常是WEB-I	NF/classes目彔,同hibernate、log4j等配置文件相同)下即可
          	solr4.0中schema.xml配置解析器:
          	
          1. <schema name="example" version="1.1">   
          2.     ……   
          3.     <fieldType name="text" class="solr.TextField">   
          4.         <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
          5.     </fieldType>  
          6.     ……   
          7. </schema>  
          六、schema.xml完整配置:
          1. <?xml version="1.0" encoding="UTF-8" ?>    
          2. <schema name="example" version="1.5">    
          3.   <types>        
          4.   
          5.     <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>  
          6.   
          7.     
          8.       <fieldType name="string" class="solr.StrField" sortMissingLast="true" />   
          9.   <!-- IKAnalyzer 配置 -->  
          10.      <fieldType name="text" class="solr.TextField">   
          11.         <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>   
          12.      </fieldType>  
          13.      
          14. </types>    
          15.     
          16.     
          17.  <fields>    
          18.    <field name="id" type="string" indexed="true" stored="true" required="true" />   
          19.    <field name="author" type="text" indexed="true" stored="true" multiValued="false"/>    
          20.    <field name="title" type="text" indexed="true" stored="true" multiValued="false"/>    
          21.    <field name="content" type="text" indexed="true" stored="true" multiValued="false" />    
          22.    <field name="_version_" type="long" indexed="true" stored="true"/>  
          23.  </fields>    
          24.     
          25.  <uniqueKey>id</uniqueKey>    
          26.  <defaultSearchField>content</defaultSearchField>    
          27.  <solrQueryParser defaultOperator="OR"/>    
          28. <copyField source="title" dest="content"/>    
          29. <copyField source="author" dest="content"/>  
          30.   
          31.     
          32. </schema>    

          解析:multiValued的個人理解是配置true則返回單條數據,false則可以返回多條,以后深入理解了再詳解。defaultSearchField配置默認搜索索引,copyField可以講 title、author字段添加至content默認搜索中
          	七、登錄管理頁面:
          	中文分詞器分詞的示例:
          	
          	query示例:
          	

          posted on 2013-01-22 14:35 順其自然EVO 閱讀(519) 評論(0)  編輯  收藏 所屬分類: 測試學習專欄

          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南澳县| 阿拉尔市| 许昌市| 平果县| 嘉祥县| 尖扎县| 东宁县| 青阳县| 康定县| 庆城县| 乌什县| 柳林县| 沙坪坝区| 安顺市| 荃湾区| 且末县| 彭阳县| 双桥区| 罗田县| 竹溪县| 方正县| 门源| 日土县| 陆河县| 台州市| 黄龙县| 荆门市| 朝阳区| 延川县| 利辛县| 镇雄县| 凌源市| 新兴县| 台中市| 新密市| 美姑县| 陕西省| 伊吾县| 黔东| 元江| 桃园市|