您的位置:首页 > 数据库 > MySQL

Solr配置从Mysql导入数据到索引库

2017-09-12 15:56 543 查看
**1.在solr的解压缩文件中solr-4.10.4\dist下面,找到solr-dataimporthandler-4.10.4.jar与

solr-dataimporthandler-extras-4.10.4.jar:**



还有mysql的驱动的jar放在solrHome下的collection1下的lib中,没有lib文件夹可以新建

例如我的home在: G:\solr-service\solrHome



2.配置核心配置文件:在solrconfig.xml中,添加一个requestHandler

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


3.创建一个data-config.xml,保存到home路径下的collection1下的conf下:

<?xml  version="1.0"  encoding="UTF-8"?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/lucene"
user="root"
password="mysql"/>
<document>
<entity   name="product"  query="select              pid,name,catalog_name,price,descrition,picture from products">
<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="descrition" name="product_descrition"/>
<field column="picture" name="product_picture"/>
</entity>
</document>
</dataConfig>


4.在solr的home下的collection1下config下的schema.xml中,设置业务的field,也就是上面的映射字段的name的属性值

<!--product-->
<field name="product_name" type="text_ik" indexed="true" stored="true"/>
<field name="product_descrition" type="text_ik" indexed="true" stored="false"/>
<field name="product_catalog_name" type="string" indexed="true" stored="true"/>
<field name="product_price" type="float" indexed="true" stored="true"/>
<field name="product_picture" type="string" indexed="false" stored="true"/>

<field  name="product_keywords"  type="text_ik"
indexed="true" stored="false"  multiValued="true"/>
<copyField  source="product_name"  dest="product_keywords"/>
<copyField  source="product_descrition"  dest="product_keywords"/>


重启服务即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  solr 索引 mysql 数据