solr服務的安裝與配置

1.到Apach官方下載對應的tgz包。

2.解壓tgz包,獲取/example/lib/ext目錄下的所有jar包,添加到自定義solr工程的WEB-INF/lib包下。

3.創建一個solrhome目錄(管理solr服務的),可以參考/example下的solr目錄,該目錄就是一個solrhome的實例。

4.進入solr項目,修改WEB-INF下的web.xml文件。(修改env-entry-value指向的路徑爲solrhome的location)

 <env-entry>//環境入口
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>E:\SolrHome</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

5.0配置solr的業務域

solrhome/collection1/conf/schema.xml

<fieldType name="text_ik" class="solr.TextField">
        <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
    </fieldType>
    
    <field name="item_title" type="text_ik" indexed="true" stored="true"/>
    <field name="item_sell_point" type="text_ik" indexed="true" stored="true"/>
    <field name="item_price"  type="long" indexed="true" stored="true"/>
    <field name="item_image" type="string" indexed="false" stored="true" />
    <field name="item_category_name" type="string" indexed="true" stored="true" />
    <field name="item_desc" type="text_ik" indexed="true" stored="false" />

    <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/>
    <copyField source="item_title" dest="item_keywords"/>
    <copyField source="item_sell_point" dest="item_keywords"/>
    <copyField source="item_category_name" dest="item_keywords"/>
    <copyField source="item_desc" dest="item_keywords"/>

5.1配置業務域涉及到分詞器的配置

   5.1.1將分詞器jar包添加到自定義solr工程WEB-INF/lib/下

   5.1.2將擴展詞典添加到/WEB-INF/build/classes/下(一般分詞器都有配置文件,例如IKAnalyzer的IKAnalyzer.cfg.xml內容如下)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">  
<properties>  
    <comment>IK Analyzer 擴展配置</comment>
    <!--用戶可以在這裏配置自己的擴展字典
    <entry key="ext_dict">ext.dic;</entry>
    -->
    <!--用戶可以在這裏配置自己的擴展停止詞字典-->
    <entry key="ext_stopwords">stopword.dic;</entry>
    
</properties>

stopword.dic內容如下

a
an
and
are
as
at
be
but
by
for
if
in
into
is
it
no
not
of
on
or
such
that
the
their
then
there
these
they
this
to
was
will
with

6.0solr索引的增量導入

將pache-solr-dataimportscheduler-1.0.jar下的dataimport.properties複製出來

 並根據實際情況修改,然後放到 solrhome/conf 目錄下面,該目錄是沒有的,需要新建

1、將 apache-solr-dataimportscheduler-1.0.jar 和solr自帶的 apache-solr-dataimporthandler-.jar, apache-solr-dataimporthandler-extras-.jar 放到solr的lib目錄下面 
2、修改solr中WEB-INF/web.xml, 在servlet節點前面增加:
 <listener>  
          <listener-class>  
                org.apache.solr.handler.dataimport.scheduler.ApplicationListener  
          </listener-class>  
</listener>


6.1solr索引的全量導入

拷貝mysql-connector-java-x.x.xx-bin.jar和solr-dataimporthandler-x.xx.x.jar到自定義solr項目的WEB_INF/lib/下

修改\SolrHome\collection1\conf\下的solrconfig.xml文件

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

data-config.xml內容

<?xml version="1.0" encoding="UTF-8" ?>  
<dataConfig>   
<dataSource type="JdbcDataSource"   
          driver="com.mysql.jdbc.Driver"   
          url="jdbc:mysql://localhost:3306/solr"   
          user="root"   
          password="root"/>   
<document>   

    <entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">

//query="select * from prodcts limit ${dataimporter.request.length} offset ${dataimporter.request.offset}">可以實現按時間批量導入,
//不過數據庫表要新添加對應字段,並且需要在dataimporter.properties中配置對應的length和offset
//也可以這樣 updateTime> '${dataimporter.last_index_time}'

         <field column="pid" name="id"/>
         <field column="name" name="product_name"/>
         <field column="catalog_name" name="product_catalog_name"/>
         <field column="price" name="product_price"/>
         <field column="description" name="product_description"/>
         <field column="picture" name="product_picture"/>
    </entity>   
</document>   

</dataConfig>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章