Solr4.2.0的配置以及与MySQL连接创建document

1)      安装配置:

使用版本:4.2.0   可以到http://lucene.apache.org/solr/下载

配置:将文件解压,

将dis目录下的war文件放入到tomcat  webapp目录下,改名为solr.war; 

第一次启动Tomcat,会报错,因为我们还没有配置solr/home,打开webapp/solr下的web.xml,配置如下:

  <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>D:\solr-4.2.0\example\solr</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

打开:localhost:8080/slor, 正确显示。

2)      连接数据库

要建立自己的全文检索,一般都需要从数据库导入数据,在原来配置的基础上,增加导入的功能 。

l D:\solr-4.2.0\example\solr\collection1\conf\solrconfig.xml中增加 :

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">  

    <lst name="defaults">  

          <str name="config">data-config.xml</str>  

    </lst>  

</requestHandler>  

l  data-config.xml,内容为数据库的连接信息 (文件dataconfig.xml建在solrconfig所在目录下)

<?xml version="1.0"encoding="UTF-8" ?> 

<dataConfig> 

<dataSource type="JdbcDataSource"driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test"  user="root" password="123"/> 

 <document name="test">          

   

 <entity name="post" query="select * from post"  deltaImportQuery="SELECT * FROM post WHERE id='${dataimporter.delta.id}'"
 deltaQuery="SELECT id FROM post WHERE time > '${dataimporter.last_index_time}'">
        <field column="id"      name="id"      />               
<field column="name"      name="name"      />  
<field column="post"      name="post"      />  
<field column="time"      name="time"   />                 
    </entity>  

</document> 

</dataConfig> 

l  schema.xml文件中增加 

<field name="name"type="string" indexed="true" stored="true"/>

<field name="post"        type="string"indexed="true" stored="true" />  

<field name="time"        type="date"indexed="true" stored="true" /> 

这里会存在的问题是: <uniqueKey>name</uniqueKey>的处理;

l 添加jar包: 添加到webapps\solr\WEB-INF\lib 目录下

mysql-connector-java-5.1.6.jar 

solr-dataimporthandler-4.2.0.jar

solr-dataimporthandler-extras-4.2.0.jar

后两个jar包在D:\solr-4.2.0\dist 下

l http://localhost:8080/solr/dataimport?command=full-import即可以进行导入数据 
http://localhost:8080/solr/#/collection1/query可以进行查询

  当数据表中有新的数据插入时,访问

 http://localhost:8080/solr/dataimport?command=delta-import  可以建立对新数据的索引。但是这里的问题是:1)在数据表里必须有一个字段是维护记录的修改时间的,因为在Solr中会根据这个时间与dataimporter.last_index_time比较来决定是否建立索引。是否可以用其他的字段来完成这一功能我还没有找到。2):当数据库中是删除的操作时,Solr这边怎么知道呢? 3)如何在数据库变化时,自动访问

 http://localhost:8080/solr/dataimport?command=delta-import  来维护Solr对DB的索引?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值