data-config.xml配置如下
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/sorl" user="root" password="root" />
<document >
<entity name="product" query="SELECT pid,name,catalog,catalog_name,price,number,description,picture from products">
<field column="pid" name="id"/>
<field column="name" name="product_name"/>
<field column="catalog" name="product_catalog"/>
<field column="catalog_name" name="product_catalog_name"/>
<field column="price" name="product_price"/>
<field column="number" name="product_number"/>
<field column="description" name="product_description"/>
<field column="picture" name="product_picture"/>
</entity>
</document>
</dataConfig>
---------------------------------------------------------------------------------------------------------------------------------------
schema.xml中配置
<!-- 商品名称 -->
<field name="product_name" type="text_ik" indexed="true" stored="true"/>
<!-- 商品分类ID -->
<field name="product_catalog" type="string" indexed="true" stored="true"/>
<!-- 商品分类名称 -->
<field name="product_catalog_name" type="string" indexed="true" stored="false"/>
<!-- 商品价格 -->
<field name="product_price" type="float" indexed="true" stored="true"/>
<!-- 商品描述 -->
<field name="product_description" type="text_ik" indexed="true" stored="false"/>
<!-- 商品图片地址 -->
<field name="product_picture" type="string" indexed="false" stored="true"/>
<!--穆标域-->
<field name="product_keywords" type="text_ik" indexed="true" stored="true" multiValued="true"/>
<!--将商品名称添加到目标域-->
<copyField source="product_name" dest="product_keywords"/>
<copyField source="product_description" dest="product_keywords"/>
中文分词器
<fieldType name="text_ik" class="solr.TextField">
<analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"></analyzer>
</fieldType>
----------------------------------------------------------------------------------------------------------------------
solrconfig.xml配置
<lib dir="${solr.install.dir:../..}/contrib/extraction/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../..}/dist/" regex="solr-cell-\d.*\.jar" />
<lib dir="${solr.install.dir:../..}/contrib/clustering/lib/" regex=".*\.jar" />
<lib dir="${solr.install.dir:../..}/dist/" regex="solr-clustering-\d.*\.jar" />
<lib dir="${solr.install.dir:../..}/contrib/langid/lib/" regex=".*\.jar" />
<lib dir="${solr.install.dir:../..}/dist/" regex="solr-langid-\d.*\.jar" />
<lib dir="${solr.install.dir:../..}/contrib/velocity/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../..}/dist/" regex="solr-velocity-\d.*\.jar" />
<lib dir="${solr.install.dir:../..}/contrib/dataimporthandler/lib" regex=".*\.jar" />
<dataDir>${solr.data.dir:F:/solr4.1/solrhome/collection1/data}</dataDir>
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>