dongyinting3179
dongyinting3179
2013-02-26 08:43

如何将Apache Solr与mysql连接

I want to connect Apache Solr Search Server with mysql server so that i can fetch filtered data from my database and convert it to JSON or XML.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • dougudu3564 dougudu3564 8年前

    You can refer to http://wiki.apache.org/solr/DataImportHandler#Oracle_Example , configre your datasource ,config your data-config.xml

    点赞 评论 复制链接分享
  • drzdu44226 drzdu44226 8年前

    I also had the same issue and it is not easy to find simple tutorial for this. Anyway I found following tutorial and it was useful for me. http://lasithtechavenue.blogspot.com/2013/11/crawling-mysql-database-with-apache-solr.html

    If I briefly explain steps.

    1. Make a config file on solr/collection1/conf and add database information and table column information on it.

    2. Point that config file from solr/collection1/conf/solrconfgig.xml

    3. Add unknown fields to schema

    4. Add dataimport and mysql related dependencies

    点赞 评论 复制链接分享
  • duangu4943 duangu4943 8年前

    Step 1: Make a new xml file db-data-config.xml and put the following content:

        <dataConfig>
        <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://`localhost`/database_name" user="" password=""/>
        <document>
        <entity name="table_name" query="select * from table_name" >
        <field name="solr_field_map" column="table_column_name" />
        <field name="name" column="name" />
        </entity>
        <entity name="emp" query="select id from emp">
    <field name="id" column="id" />
        </entity>
        </document>
        </dataConfig>
    

    Step 2: In solrconfig.xml,add:

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

    Step 3: Use command to import data from your mysql source to solr:

    http://localhost:8983/solr/db/dataimport?command=full-import

    if you want to modify the fields before indexing to solr, then you can make your transformers on entity in db-data-config.xml.Transformers are explained here

    点赞 评论 复制链接分享
  • douwen7516 douwen7516 8年前

    The way I have done it in the past it to just create an indexing script. The script runs as a nightly process and extracts the mySQL data that you want to add to the search index and specifies all the information that solr will need to display the relevant search results.

    Additionally you can add index items as the database is updated, for example if a new user is created, add some code into the register script which insert the new index item.

    It is pretty quick and easy to do, the solr documentation is quite good.

    http://lucene.apache.org/solr/4_1_0/tutorial.html

    Hope this helps.

    点赞 评论 复制链接分享