solr5.5.2 增量索引配置方法

  • 经过各种测试,解决N多BUG终于把增量索引配置成功了。
  • 一定要查看solr_home/server/logs/solr.log这个日志文件,这里记录了整个输出信息。以前用的4.7版本日志都输出在cmd窗口的,到了5.5cmd窗口就只有启动时输出的少量信息。如果发现哪里功能不正常了就在这个log文件里查看是否有异常信息输出。
  • 配置定时任务时用到的solr-dataimportscheduler-1.0.jar和其他人修改过的solr-dataimportscheduler-1.1.jar在5.5都会报空指针异常。
  • 可以用的jar包为http://download.csdn.net/detail/ljsososo/9486023#comment 修改过的mydataimportscheduler.jar。
  • 两个主要的配置文件代码如下:
  • managed-schema文件(或者schema.xml)
<?xml version="1.0" encoding="UTF-8" ?>

<schema name="example" version="1.6">

<fields>
<field name="text" type="text_mmseg4j_complex" indexed="true" stored="false" multiValued="true"/>
   <field name="_version_" type="string" indexed="true" stored="true"/>
   <field name="id" type="string" required="true"/>    
   <field name="doc_type" type="string" />
   <field name="name" type="text_mmseg4j_maxword" />    
   <field name="address" type="text_mmseg4j_complex" />
   <field name="abstract" type="text_mmseg4j_complex" />
   <!-- Latitude -->
   <field name="lat" type="tdouble" indexed="true" stored="true"/>
   <!-- Longitude -->
   <field name="lon" type="tdouble" indexed="true" stored="true"/>
   <field name="actiontime" type="tdate" />
   <field name="type" type="text_mmseg4j_maxword" />    
   <field name="city" type="text_mmseg4j_complex" />
   <field name="dam_id" type="int"/>   
</fields>
<uniqueKey>id</uniqueKey>
 <types>
  <fieldType name="string" class="solr.StrField" sortMissingLast="true" />  
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
    <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
    <!-- mmseg4j-->
     <field name="mmseg4j_complex_name" type="text_mmseg4j_complex" indexed="true" stored="true"/>
     <field name="mmseg4j_maxword_name" type="text_mmseg4j_maxword" indexed="true" stored="true"/>
     <field name="mmseg4j_simple_name" type="text_mmseg4j_simple" indexed="true" stored="true"/>

     <fieldType name="text_mmseg4j_complex" class="solr.TextField" positionIncrementGap="100" >
        <analyzer>
           <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="dic"/>
           <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
         </analyzer>
     </fieldType>
     <fieldType name="text_mmseg4j_maxword" class="solr.TextField" positionIncrementGap="100" >
          <analyzer>
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="/dic"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
          </analyzer>
      </fieldType>
      <fieldType name="text_mmseg4j_simple" class="solr.TextField" positionIncrementGap="100" >
          <analyzer>
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="/dic"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
          </analyzer>
      </fieldType>
    <!-- mmseg4j-->
 </types>
</schema>

data-config.xml文件:

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://192.168.1.124/isfs_sims" 
              user="root" 
              password="1234"/>
  <document>
    <entity name="dam" pk="dam_id" transformer="TemplateTransformer" 
     query="select a.intId dam_id,b.varName type,a.varName name,c.varName city ,a.varAddress address,a.fltLongitude lon,a.fltLatitude lat,a.varAbstract abstract,dtLastModified actiontime from tbDam a,tbAffiliate b,tbCity c where a.varType=b.intId and a.intCityId=c.intCityId"
     deltaImportQuery="select a.intId dam_id,b.varName type,a.varName name,c.varName city ,a.varAddress address,a.fltLongitude lon,a.fltLatitude lat,a.varAbstract abstract,dtLastModified actiontime from tbDam a,tbAffiliate b,tbCity c where a.intId='${dataimporter.delta.dam_id}' and a.varType=b.intId and a.intCityId=c.intCityId" 
     deltaQuery="select intId dam_id from tbDam where dtLastModified &gt; '${dataimporter.last_index_time}'">  
            <field column="id"  template="Dam_${dam.dam_id}"/>
            <field column="dam_id" />
            <field column="doc_type"  template="dam"/>
            <field column="name" />
            <field column="type" />
            <field column="city" />
            <field column="lat" />
            <field column="lon" />
            <field column="address" />
            <field column="abstract" />
            <field column="actiontime" />
    </entity>

  </document>
</dataConfig>

这里涉及到多表的联合查询,所以代码较长。但是这里主要关注的应该的dam_id,这个是entity的主键因此需要一个field来存这个值,不然作为唯一值的id不能设置template,进一步导致多个entity时,创建或修改索引就会乱七八糟,因为相同的id会直接覆盖。

别忘了在启动solr的容器中修改web.xml,在servlet标签之前加上:


<listener>
<listener-class>
org.apache.solr.handler.dataimport.scheduler.ApplicationListener
</listener-class>
</listener>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Solr源码在MyEclipse下的搭建 1. 下载并按装Ant 下载地址: http://ant.apache.org/bindownload.cgi Ant环境变量配置: ANT_HOME: E:\Program Files\apache-ant-1.9.0 Path: %ANT_HOME%\bin 在cmd中输入ant -v, 有下图结果表示成功安装 2. 下载Solr源码 下载地址: http://lucene.apache.org/solr/mirrors-solr-latest-redir.html 3. 用Ant把Solr源码转换为MyEclipse Web项目 进入Solr源码的根目录 在cmd中输入ant eclipse, 按回车后你将会看到如下画面, 如果你的c:\Users\用户名\.ant\lib下没有ivy jar包的话 此时你按它说的那样需输入ant ivy-bootstrap命令下载ivy, 当然你也可以直接吧ivy jar包直接放入c:\Users\用户名\.ant\lib下 下好后再输入刚才的ant eclipse命令,回车后你会看到一堆信息,此时表明ant已经再帮你生成项目了。期间会等一段时间,在这期间也可能会出现fault信息,而且就是它可能造成你很久都看不到成功生成,在我目前遇到的情况下的解决办法是,再输入一遍命令,之后就看你的点了,或者你有更好的解决办法。 4. 把Eclipse普通项目转化为web项目 如果是Eclipse可以看考百度。这里只介绍MyEclipse的转化方法。 1. 在项目根目录下创建一个WebRoot文件夹 2. 找一个MyEclipse Web项目,把.project文件中的<buildSpec>...</buildSpec>和<natures>...</natures>标签中的内容复制到生成的项目中的.project文件中。 3. 找到Web项目中的.mymetadata文件,看看里面的内容,就知道怎么回事了。 4. 求改项目编译结果的存放地址,找到"<classpathentry kind="output"..."部分,修改path的值为WebRoot/WEB-INF/classes,这样就可以跑自己的代码了。 5. 配置Solr运行环境 1. 把solr.war(solr-4.2.0\example\solr-webapp\solr.war)里的东西全复制到WebRoot下 2. 创建solr/home, 把solr-4.2.0\example\solr所有文件复制到你创建的solr/home目录下 3. 创建JNDI让程序找到solr/home(当然你也可以用System Properties方式), 在WebRoot/META-INF目下创建context.xml 文件,并写入以下字符 <?xml version='1.0' encoding='utf-8'?> <Context> <Environment name="solr/home" type="java.lang.String" value="E:\Solr" override="true" /> </Context> 注:value对应地址即你创建的solr/home目录地址 4. 部署到tomcat,开始Solr

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值