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的确换了新的
此后你再重新搜索,结果果然更新了

你可能感兴趣的:(apache,应用服务器,脚本,Solr,Lucene)