標籤: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的整合(索引與搜尋)