windows搭建solr5.4.1全文搜索引擎



一.   搭建solr服务器

         1.下载solr http://archive.apache.org/dist/lucene/solr/5.4.1/ ,并解压

         2.将..\solr-5.4.1\example\example-DIH目录下的solr文件夹复制到tomcat根目录下

         3.将..\solr-5.4.1\server\solr-webapp目录下的webapp复制到tomcat\webapp下并命名为为solr

         4.将..\solr-5.4.1\server\lib\ext目录下的所有jar包复制到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib下

         5.将..\solr-5.4.1\dist目录下的solr-dataimporthandler-5.4.1.jar和solr-dataimporthandler-extras-5.4.1.jar复制到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib下

         6.将..\solr-5.4.1\server\resources目录下的log4j.properties复制到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\classes下

         如果没有classes文件,则创建一个

         7.修改..\apache-tomcat-7.0.67\webapps\solr\WEB-INF目录下的web.xml

         找到<env-entry>节点,删除注释,修改如下

[html] view plain copy
 print?windows搭建solr5.4.1全文搜索引擎windows搭建solr5.4.1全文搜索引擎
  1. <span style="white-space:pre">    </span>  <env-entry>  
  2.                 <env-entry-name>solr/home</env-entry-name>  
  3.                             <!--指向tomcat根目录下的solr文件夹 -->  
  4.                <env-entry-value>E:\apache-tomcat-7.0.67\solr</env-entry-value>  
  5.                <env-entry-type>java.lang.String</env-entry-type>  
  6.           </env-entry>  
  7.           

         8.启动tomcat,访问 http://localhost:8080/solr/index.html#/, 出现如下页面说明搭建成功

windows搭建solr5.4.1全文搜索引擎

二.   连接数据库   

         1.SQL配置

         以MySQL为例,需要下载mysql-connector-Java-bin.jar到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib目录下

         http://dev.mysql.com/downloads/file/?id=462849

         2.建立查询

         进入在solr/home 目录下也就是本例的..\apache-tomcat-7.0.67\solr目录下

         复制db得到collection

         进入..\apache-tomcat-7.0.67\solr\collection目录下,编辑conf文件夹下的db-data-config.xml文件

[html] view plain copy
 print?windows搭建solr5.4.1全文搜索引擎windows搭建solr5.4.1全文搜索引擎
  1. <dataConfig>  
  2.     <dataSourcedriverdataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost:3306/dubbotest?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"user="root" password="123456/>  
  3.     <document>  
  4.         <entity name="Student" query="select* from t_student"  
  5.                 deltaQuery="select * fromt_student where last_modified > '${dataimporter.last_index_time}'"  
  6.                                       deltaImportQuery="SELECT* FROM t_student where last_modified >'${dataimporter.last_index_time}'">  
  7.             <field column="id"name="id" />  
  8.                             <fieldcolumnfieldcolumn="name" name="name" />  
  9.                             <fieldcolumnfieldcolumn="sex" name="sex" />  
  10.                             <fieldcolumnfieldcolumn="userId" name="userid" />  
  11.         </entity>  
  12.     </document>  
  13. </dataConfig>  

         编辑..\apache-tomcat-7.0.67\solr\collection\conf\schema.xml文件,在

         <fieldname="" type="" indexed=""stored=""/>最后,添加

[html] view plain copy
 print?windows搭建solr5.4.1全文搜索引擎windows搭建solr5.4.1全文搜索引擎
  1. <fieldnamefieldname="sex" type="string" indexed="text"stored="false"/>  
  2. <fieldnamefieldname="userId" type="string" indexed="text"stored="false"/>  

         因为id和name字段已有,所以不添加。

         3.重新启动tomcat,可以通过http://localhost:8080/solr/index.html

导入数据

windows搭建solr5.4.1全文搜索引擎

查询数据

windows搭建solr5.4.1全文搜索引擎

       

  不同版本的solr,搭建会有不同,需要注意的是相应的jar包必须添加到

         ..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib中


文章来源:http://blog.csdn.net/tgbsqliuying/article/details/51591039