qileilove

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

          solr運行配置與數據庫數據導入到solr

           一、運行
            1,solr運行容器,tomcat
            2,拷貝apache-solr-3.6.0.war到tomcat的webapps目錄下,并改名為solr.war
            3,tomcat的conf目錄下建立結構為conf/Catalina/localhost的兩個文件夾。建立結構為solr-tomcat/solr的兩個文件夾(solr的HOME目錄),如建在D盤根目錄,d:/solr-tomcat/solr,solr-tomcat文件夾名字可任意命名,將apache-solr-3.6.0\example\solr下的所有文件及文件夾拷貝到這下面
            4,在localhost文件夾下建立solr.xml,并保存如下內容:
          <Context docBase="D:\tomcat-6.0\webapps\solr.war" debug="0" crossContext="true" >
          <Environment name="solr/home" type="java.lang.String" value="D:/solr-tomcat/solr" override="true" />
          </Context>
            5,此時可以運行tomcat,地址欄輸入:http://localhost:8080/solr/admin進行驗證
            6,開始為導入數據庫數據添加配置。將jdbc驅動jar和apache-solr-3.6.0\dist\apache-solr-dataimporthandler-3.6.0.jar 兩個jar拷貝到tomcat的webapps/solr/WEB-INF/lib下。將apache-solr-3.6.0\example\example-DIH\solr下的所有文件及文件夾拷貝(并覆蓋)到solr的HOME目錄,如:d:/solr-tomcat/solr
            7,更改solr Home目錄下的conf/solrconfig.xml,添加如下內容:
          <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
          <lst name="defaults">
          <str name="config">D:\solr-tomcat\solr\db\conf\db-data-config.xml</str> <!--  根據自己電腦里的db-data-config.xml的實際路徑來寫 -- >
          </lst>
          </requestHandler>
            8, 將solr Home目錄下面的solrconfig.xml和schema.xml拷貝到db文件夾下面的conf中,注意:導入的字段要先在schema.xml中定義
            定義如:<field name="firstname" type="string" stored="true" indexed="true"/>
            9,修改db\conf\db-data-config.xml,可參考如下:
          <dataConfig>
          <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/langsin1" user="root" password="root"/>
          <document name="userss">
          <entity name="users" pk="id" query="select * from users">
          <field column="id" name="id" />
          <field column="firstname" name="firstname" />
          <field column="lastname" name="lastname" />
          <field column="age" name="age" />
          </entity>
          </document>
          </dataConfig>
            10,啟動TOMCAT,輸入地址進行導入,導入分為很多模式:我選用的全部倒入模式
            http://localhost:8080/solr/db/dataimport?command=full-import
            11,如果有中文,修改tomcat的server.xml文件
            <Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" URIEncoding="UTF-8"
            12,添加中文分詞,如:mmseg4j, 在$SOLR_HOME下建立lib和dic兩個目錄,講mmseg4j-all-1.8.4.jar拷貝到lib目錄,將data里的.dic文件拷貝到dic目錄
          13,修改Schema.xml
            添加fieldType
            Xml代碼
          <types>
          <fieldType name="textComplex" class="solr.TextField" positionIncrementGap="100" >
          <analyzer>
          <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="/opt/solr/example/solr/dic"/>
          <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
          </fieldType>
          <fieldType name="textMaxWord" class="solr.TextField" positionIncrementGap="100" >
          <analyzer>
          <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="/opt/solr/example/solr/dic"/>
          <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
          </fieldType>
          <fieldType name="textSimple" class="solr.TextField" positionIncrementGap="100" >
          <analyzer>
          <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="/opt/solr/example/solr/dic"/>
          <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
          </fieldType>
          ..
          </types>
            Xml代碼
          <fieldname="simple"type="textSimple"indexed="true"stored="true"multiValued="true"/>
          <fieldname="complex"type="textComplex"indexed="true"stored="true"multiValued="true"/>
          <fieldname="maxword"type="textMaxWord"indexed="true"stored="true"multiValued="true"/>
            Xml代碼
          <copyField source="simple" dest="text"/>
          <copyField source="complex" dest="text"/>
            14,重啟tomcat,
            進入 http://yourhost:8080/solr-example/admin/analysis.jsp,測試中文分詞

          posted on 2014-01-20 10:13 順其自然EVO 閱讀(1633) 評論(0)  編輯  收藏 所屬分類: 數據庫

          <2014年1月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 承德县| 龙陵县| 宾阳县| 建平县| 邹城市| 封开县| 台南县| 临清市| 涞源县| 双桥区| 东港市| 从江县| 常山县| 云阳县| 科尔| 亳州市| 惠州市| 遂宁市| 尚义县| 敦化市| 温泉县| 沾化县| 林甸县| 商河县| 福清市| 西林县| 大冶市| 烟台市| 中阳县| 正镶白旗| 民勤县| 平安县| 蓝田县| 平原县| 西吉县| 彭泽县| 碌曲县| 乌审旗| 汝南县| 万山特区| 苍山县|