标签:
1.把Mysql的Jar包 例如:mysql-connector-java-5.1.8-bin.jar 或其他版本
放到D:\apache-tomcat-7.0.57\webapps\solr\WEB-INF\lib下
2.然后在tomcat-solr\collection1\conf下新建一个配置文件:data-config.xml,然后在本目录下编辑配置文件: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> 或 <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">D:\apache-tomcat-7.0.57\webapps\solr\solr_home\collection1\conf\data-config.xml</str> </lst> </requestHandler>
3. 将初次下载的solr-4.10.2文件夹下的dist, contrib文件夹复制到TomCat根目录下:
4.然后再次修改刚才编辑过的solrconfig.xml增加两个文件夹的配置并修改一些参数:
大约在75行默认有8个路径,但是路径不一定全对,顺着这个配置的路径去找文件夹,根据查找的层数修改这个路径配置,另增加一个新的配置,全文如下:(具体配置还要根据实际情况而定)
<lib dir="D:\apache-tomcat\contrib\extraction\lib" regex=".*\.jar" /> <lib dir="D:\apache-tomcat\dist\" regex="solr-cell-\d.*\.jar" /> <lib dir="D:\apache-tomcat\contrib\clustering\lib\" regex=".*\.jar" /> <lib dir="D:\apache-tomcat\dist\" regex="solr-clustering-\d.*\.jar" /> <lib dir="D:\apache-tomcat\contrib\langid\lib\" regex=".*\.jar" /> <lib dir="D:\apache-tomcat\dist\" regex="solr-langid-\d.*\.jar" /> <lib dir="D:\apache-tomcat\contrib\velocity\lib" regex=".*\.jar" /> <lib dir="D:\apache-tomcat\dist\" regex="solr-velocity-\d.*\.jar" /> <lib dir="D:\apache-tomcat\dist\" regex="solr-dataimporthandler-\d.*\.jar" />
5. 将dist文件夹下的
复制到webapps\solr\WEB-INF\lib下。
6.编辑data-config.xml,例如
<!-- db导入solr配置文件 --> <dataConfig> <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/数据库名" user="root" password="000000"/> <document> <entity name="sysDictionary" pk="ID" query="SELECT ‘SSR_DICTIONARY‘ AS type, CONCAT(‘SSR_DICTIONARY_‘,DIC_ID) AS indexId, DIC_ID AS dicId, DIC_NAME AS dicName, DIC_VALUE AS dicValue, DIC_GROUP AS dicGroup, DIC_TYPE AS dicType, DIC_ORDER AS dicOrder, DIC_STATUS AS dicStatus, DIC_PARENT_ID AS dicParentId FROM SYS_DICTIONARY"/>
<entity name="appPerson" pk="ID" query="SELECT ‘SSR_DICTIONARY‘ AS type, CONCAT(‘SSR_APPPERSON_‘,P_ID) AS indexId, P_ID AS pkid, P_NAME AS pname, P_MOBILE AS pmobile, P_TYPE AS ptype, P_CREATETIME AS pcreatetime, P_NOTE AS pnote, P_STATUS AS pstatus, P_ORG AS porg, DIC_GROUP AS dicGroup FROM APP_PERSON"/> </document> </dataConfig>
query是获取全部数据的SQL(solr从sql中获取那些数据),多列
还可以配置
deltaImportQuery是获取增量数据时使用的SQL(数据库新增数据追加到solr的数据),多列 (提示:最后索引时间与数据库字段(创建时间比较)) 可以试着配置一下
7.编辑schema.xml文件 例如:
<field name="indexId" type="string" indexed="true" stored="true" required="true" multiValued="false"/> <field name="type" type="string" indexed="true" stored="true" required="true" multiValued="false"/> <field name="indexTime" type="tdate" default="NOW/SECOND"/> <!-- APPPERSON FIELD --> <field name="pkid" type="string" indexed="true" stored="true"/> <field name="pname" type="string" indexed="true" stored="true"/> <field name="pmobile" type="string" indexed="true" stored="true"/> <field name="ptype" type="int" indexed="true" stored="true"/> <field name="pcreatetime" type="tdate" indexed="true" stored="true"/> <field name="pnote" type="text_ik" indexed="true" stored="true"/> <field name="pstatus" type="int" indexed="true" stored="true"/> <field name="porg" type="string" indexed="true" stored="true"/> <!-- SYSDICTIONARY FIELD --> <field name="dicId" type="string" indexed="true" stored="true"/> <field name="dicName" type="string" indexed="true" stored="true"/> <field name="dicValue" type="text_ik" indexed="true" stored="true"/> <field name="dicGroup" type="string" indexed="true" stored="true"/> <field name="dicType" type="string" indexed="true" stored="true"/> <field name="dicOrder" type="int" indexed="false" stored="true"/> <field name="dicStatus" type="string" indexed="true" stored="true"/> <field name="dicParentId" type="string" indexed="true" stored="true"/>
这样配置就算是完成了
标签:
原文地址:http://www.cnblogs.com/Crow0/p/5116677.html