Win7下Solr4.10.1和MySql的整合(索引與搜尋)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   java   strong   

1、開啟D:\webserver\solr\collection1\conf\solrconfig.xml檔案,在<requestHandler name="/select" class="solr.SearchHandler">行上面加入以下內容:

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

2、建立資料庫b2c,建立表goods,添加欄位goods_id(int)和goods_name(varchar);

3、在D:\webserver\solr\collection1\conf目錄下建立一個data-config.xml檔案,檔案內容如下:

  <dataConfig>
    <dataSource type="JdbcDataSource"
          driver="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost/b2c"
               user="root"
               password="666666"/>
    <document>
        <entity name="goods" query="select goods_id,goods_name from goods">
        <field column="goods_id" name="id"/>
        <field column="goods_name" name="goods_name"/>
      </entity>
    </document>
  </dataConfig>

4、將D:\solr-4.10.1\dist\solr-dataimporthandler-4.10.1.jar 檔案拷貝到 D:\Tomcat 8.0\webapps\solr\WEB-INF\lib下面;

5、將MySql的java驅動包(我用的是mysql-connector-java-5.1.33-bin.jar)拷貝到 D:\Tomcat 8.0\webapps\solr\WEB-INF\lib;

6、開啟D:\webserver\solr\collection1\conf\schema.xml檔案,

  (1)保留如下欄位的定義;

     <field name="_version_" type="long" indexed="true" stored="true"/>
     <field name="_root_" type="string" indexed="true" stored="false"/>

  (2)刪除多餘欄位的定義;

  (3)添加以下欄位:

     <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
     <field name="goods_name" type="text_ik" indexed="true" stored="true"/> 

  (4)修改主鍵欄位

   <uniqueKey>id</uniqueKey>

 

7、訪問 http://127.0.0.1:8080/solr/,按1-6的步驟建索引

圖右側的顯示表示正在建索引,稍候重新整理可以見到如下顯示:

Indexing completed. Added/Updated: 999 documents. Deleted 0 documents. (Duration: 01s)

Requests: 1 (1/s), Fetched: 999 (999/s), Skipped: 0, Processed: 999 (999/s)Started: 19 minutes agoOK了,索引建成,總共999條資料! 

8、搜尋資料

出現結果就OK了~~~~~~

Win7下Solr4.10.1和MySql的整合(索引與搜尋)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.