solr随记,
写了两篇的学习记录,发现介绍那些东西,我好难受啊,所以决定写一下solr学习中遇到的一下问题吧。记录一些难点,也为后来的人提个醒,说不定可以根据我写的一些bug,给你们一些启发。
Bug1:在写solr的全量导入中。显示导入成功了,但是却导入了0条数据,这是为什么呢,找了半天,最后发现是没有导入数据连接所使用的jar包。
Bug2:solr关于定时增量导入中,明明配置好了却就是不进行导入数据库,通过看solr的日志中发现是sql语句写的有问题。然后我又去查找语句,最后找到问题所在。在下面介绍一下增量导入的xml配置,和字段的意思。为了防止我自己以后忘记
<!-- Pk:数据库中的主键 dataSource:使用哪个连接池
query:全量更新的查询语句
deltaQuery:${dih.last_index_time}是solr中记录的最后一次更新时间,查询出所需要的id
deltaImportQuery:根据给到的id查询出相应的记录
-->
<entity name="t_wc_case" pk="uuid"
dataSource="dateSource"
query="select * from t_wc_case"
deltaImportQuery="select * from t_wc_case where id='${dih.delta.id}'"
deltaQuery="select id from t_wc_case where addon > '${dih.last_index_time}'">
<!-- 数据库中的列和solr的属性对应,如果一致可以不用写 -->
<field column="uuid" name="id" />
</entity>
其中的addon是数据库中记录的最后更新的字段,而不是什么函数,我一开始就搞错了导致上面的错误。
下面贴出我dataimport.properties的配置
#################################################
# to sync or not to sync
# 1 - active; anything else - inactive
syncEnabled=1
# which cores to schedule
# in a multi-core environment you can decide which cores you want syncronized
# leave empty or comment it out if using single-core deployment
# 说是说使用的核心是那个,但我还是不知道什么意思,所以我就写了实例,以防万一嘛
syncCores=collection1
# solr server name or IP address
# [defaults to localhost if empty]
# 连接的地址,我做本地测试就是localhost了
server=localhost
# solr server port
# [defaults to 80 if empty]
# 连接的端口号
port=8081
# application name/context
# [defaults to current ServletContextListener's context (app) name]
# 其实这个才能说是实例名
webapp=solr-4.10.3
# URL params [mandatory]
# remainder of URL
# 增量更新时的,其实就是通过httpclient访问的,前面拼接上上面的参数,
# command:更新的方式,clean:是否清除原有的数据,commit是否提交,wt:格式json,entity使用的是哪个实体
params=/dataimport?command=delta-import&clean=false&commit=true&optimize=false&wt=json&indent=true&entity=test&verbose=false&debug=false
# schedule interval
# number of minutes between two runs
# [defaults to 30 if empty]
# 增量更新的频率把,分钟为单位
interval=1
# 重做索引的时间间隔,单位分钟,默认7200,即1天;
# 为空,为0,或者注释掉:表示永不重做索引,重做索引也就是全量更新
reBuildIndexInterval=7200
# 重做索引的参数
reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true&optimize=true&wt=json&indent=true&entity=test&verbose=false&debug=false
# 重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;
# 两种格式:2012-04-11 03:10:00 或者 03:10:00,后一种会自动补全日期部分为服务启动时的日期
reBuildIndexBeginTime=2017-09-08 12:06:00
Bug3:使用solrj时候的查询bug,因为我需要使用高亮,所以把高亮数据给替换进了solr document中,结果最后放入实体类中发现报arrayLISt不能转换为String,最后发现高亮的的数据,取出来是一个List集合,当然不可以强转为String,所以就toString了。
SolrDocumentList results = response.getResults();
Map<String, Map<String, List<String>>> map = response.getHighlighting();
for (SolrDocument doc : results) {
String id = (String)doc.getFieldValue("id");
Map<String, List<String>> fieldMap = map.get(id);
Set<String> set = fieldMap.keySet();
for (String string : set) {
doc.setField(string,fieldMap.get(string).toString().replace("[", "").replace("]", ""));
}
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。