solr的索引更新

背景: solr作为搜索工具,索引采用传统的lucene构建,当更新索引文件的时候,搜索并不会出现更新
solr确实做了精细的缓存机制,缓存跟一个特定的searcher绑定,与普通的缓存相比,solr的缓存并不会在一段时间之后失效,除非searcher发生改变
当你将solr集成到你的应用,而非采用solr服务器方式的时候,此时会带来麻烦,你不得不自己编写代码解决
通过分析solr自带的readercycle脚本和SolrUpdateServlet,你就会容易的找到答案
代码如下:
legacyUpdateHandler = new XmlUpdateRequestHandler();
legacyUpdateHandler.init(
null );
BufferedReaderrequestReader
= new BufferedReader( new StringReader( " <commit/> " ));
legacyUpdateHandler.update(requestReader);
当你跟新了索引文件,然后再调用此段代码,你会发现类似结果
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.update.DirectUpdateHandler2commit
信息:startcommit(optimize
= false , waitFlush = false , waitSearcher = true)
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcher<init>
信息:OpeningSearcher@1474fcmain
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.update.DirectUpdateHandler2commit
信息:end_commit_flush
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcherwarm
信息:autowarmingSearcher@1474fcmainfromSearcher@c550main
filterCache{lookups
= 0 , hits = 0 , hitratio = 0.00 , inserts = 1 , evictions = 0 , size = 1 , cumulative_lookups = 0 , cumulative_hits = 0 , cumulative_hitratio = 0.00 , cumulative_inserts = 1 , cumulative_evictions = 0 }
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcherwarm
信息:autowarmingresultforSearcher@1474fcmain
filterCache{lookups
= 0 , hits = 0 , hitratio = 0.00 , inserts = 1 , evictions = 0 , size = 1 , cumulative_lookups = 0 , cumulative_hits = 0 , cumulative_hitratio = 0.00 , cumulative_inserts = 1 , cumulative_evictions = 0 }
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcherwarm
信息:autowarmingSearcher@1474fcmainfromSearcher@c550main
queryResultCache{lookups
= 1 , hits = 0 , hitratio = 0.00 , inserts = 1 , evictions = 0 , size = 1 , cumulative_lookups = 1 , cumulative_hits = 0 , cumulative_hitratio = 0.00 , cumulative_inserts = 1 , cumulative_evictions = 0 }
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcherwarm
信息:autowarmingresultforSearcher@1474fcmain
queryResultCache{lookups
= 0 , hits = 0 , hitratio = 0.00 , inserts = 1 , evictions = 0 , size = 1 , cumulative_lookups = 1 , cumulative_hits = 0 , cumulative_hitratio = 0.00 , cumulative_inserts = 1 , cumulative_evictions = 0 }
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcherwarm
信息:autowarmingSearcher@1474fcmainfromSearcher@c550main
documentCache{lookups
= 0 , hits = 0 , hitratio = 0.00 , inserts = 0 , evictions = 0 , size = 0 , cumulative_lookups = 0 , cumulative_hits = 0 , cumulative_hitratio = 0.00 , cumulative_inserts = 0 , cumulative_evictions = 0 }
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.search.SolrIndexSearcherwarm
信息:autowarmingresultforSearcher@1474fcmain
documentCache{lookups
= 0 , hits = 0 , hitratio = 0.00 , inserts = 0 , evictions = 0 , size = 0 , cumulative_lookups = 0 , cumulative_hits = 0 , cumulative_hitratio = 0.00 , cumulative_inserts = 0 , cumulative_evictions = 0 }
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.core.SolrCoreregisterSearcher
信息:RegisterednewsearcherSearcher@1474fcmain
2008 - 4 - 23 1 : 28 : 12 org.apache.solr.handler.XmlUpdateRequestHandlerupdate
信息:commit
0 9
从日志看出,searcher的确换了新的
此后你再重新搜索,结果果然更新了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值