1.把PostgreSQL的Jar包 例如:postgresql-9.1-901-1.jdbc4.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="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/postgres?useUnicode=true&characterEncoding=utf-8" user="postgres" password="000000"/> <document> <entity name="notification" pk="ID" query="SELECT 'SLQ_Notification' AS type, "NOTIFY_ID" AS indexId, "UUID" AS uuid, "NOTIFY_ID" AS notifyId, "NOTIFY_TYPE" AS notifyType, "DIRECTION" AS direction, "UID" AS uid, "MSG" AS msg, "REF_ID" AS refId, "REF_UID" AS refUid, "APPLY_UID" AS applyUid, "APPLY_ID" AS applyId, "REF_IMAGE_URLS" AS refImageUrls, "FROM_UID" AS fromUid, "LAST_UPDATE_TIME" AS lastUpdateTime, "CREATE_TIME" AS createTime, "IS_DELETED" AS isDeleted FROM "TBL_SLQ_NOTIFICATION""/> <entity name="letter" pk="ID" query="SELECT 'SLQ_Letter' AS type, 'slq'||"ID" AS indexId, "DIRECTION" AS direction, "MSG_BOX_TYPE" AS messageBoxType, "UUID" AS uuid, "MSG_TYPE" AS msgType, "DURATION" AS duration, "CONTENT" AS msg, "AUDIO_URLS" AS audioUrls, "VIDEO_URLS" AS videoUrls, "IMAGE_URLS" AS imageUrls, "TO_UID" AS toUid, "REF_ID" AS refId, "REF_UID" AS refUid, "APPLY_UID" AS applyUid, "SUGGEST_UID" AS suggestUid, "FROM_UID" AS fromUid, "CREATE_TIME" AS createTime, "IS_DELETED" AS isDeleted FROM "TBL_SLQ_MESSAGE""/> </document> </dataConfig>
7.编辑schema.xml文件 和mysql oracle一样