zhwz 发表于 2017-12-20 07:31:25

solr6.6初探之配置篇

  一.solr的简介
  1) solr是企业级应用的全文检索项目,它是基于Apache Lucence搜索引擎开发出来的用于搜索的应用工程
  2) solr最新版本6.6 下载地址:下载地址
  二 启动与配置solr
  1) 下载并解压文件后会得到以下界面:

  我们重点关注以下几个文件夹:
  1.bin 放置solr的相关执行脚本,在solr5.0版本以前,部署过程相当麻烦,好在Apache帮我们简化了相关solr的配置
  2.example :这个文件夹里放置的一些solr应用实例。对于我们当然可以在实际的应用中将示例借来使用
  3.server:其实就是tomcat目录,在这里部署了solr的项目
  下一步进入bin文件夹里运行 ./solr start
  

$ ./solr start  
Waiting up to
180 seconds to see Solr running on port 8983 [\]  
Started Solr server on port
8983 (pid=2725). Happy searching!  

  在浏览器输入 localhost:8983/solr 就可以展示如下界面

  当运行成功后,紧接着要运行命令:
  

$ ./solr create -c helloworld  

  创建一个名字为 helloworld的core (core相当于一个搜索项目工程)
  三.配置dataimport从数据库获取数据
  1.在${solr.home}/example/example-DIH/solr/db/conf下拷贝solrconfig.xml与db-data-config.xml文件至${solr.home}/server/solr/${core.name}/conf下,注意:${solr.home}指solr的安装目录 ${core.name}指创建的core的名字,本例中是helloworld
  2.编辑db-data-config.xml
  

<dataConfig>  <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/house?charactorEncoding=utf-8" user="root" password="" />
  <document>
  <entity name="item" query="select * from topics" pk="topic_id"
  deltaQuery="select * where updatedate > '${dataimporter.last_index_time}'">
  <field column="topic_id" name="topicId" />
  

  <field column="topic" name="topic" />
  <field column="updatedate" name="ldate" dateTimeFormat="yyyy-MM-dd HH:mm:ss"/>
  </entity>
  </document>
  
</dataConfig>
  

  该配置文件配置数据源,以及查询数据表中数据
  注意以下几点:
  .保证查询的字段必须包含数据表的主键
  .配置文件中的field节点对应数据表中的列名及索引名(name)
  .datasource节点中配置数据源 entity节点配置一个实体 deltaQuery属性是配置增量获取数据的SQL
  .注意一定要将数据库的驱动拷贝到${solr.home}/server/solr-webapp/webapp/WEB-INF/lib 下
  3.编辑${solr.home}/server/solr/${core.name}/conf/managed-schema
  注意修改unqiuekey节点值为topicId (对应<field name="topicId" column="topic_id" />中的name属性)
  并增加以下配置:
  

<field name="topicId" type="long" multiValued="false" indexed="true" required="true" stored="true"/>  <field name="ldate" type="date" indexed="true" stored="true"/>
  <field name="topic" type="text_general" docValues="false" indexed="true" stored="true"/>
  

  注意:
  必须修改unqiueKey的节点内容为对应的主键信息,这一步很重要
  field节点对应db-data-import.xml中的field节点 其中他们的name属性保持一致
  四 将数据库的数据导入到solr中
  在工作台上运行该功能即可,需要标注的地方都标红:

  五:验证是否成功:
页: [1]
查看完整版本: solr6.6初探之配置篇