solr的索引更新

 
背景: solr作为搜索工具,索引采用传统的lucene构建,当更新索引文件的时候,搜索并不会出现更新
 
solr确实做了精细的缓存机制,缓存跟一个特定的searcher绑定,与普通的缓存相比,solr的缓存并不会在一段时间之后失效,除非searcher发生改变
 
当你将solr集成到你的应用,而非采用solr服务器方式的时候,此时会带来麻烦,你不得不自己编写代码解决
 
通过分析solr自带的readercycle脚本和SolrUpdateServlet,你就会容易的找到答案
 
代码如下:
 
legacyUpdateHandler = new  XmlUpdateRequestHandler();
legacyUpdateHandler.init(
null );
BufferedReader requestReader
= new  BufferedReader( new  StringReader( " <commit/> " ));
legacyUpdateHandler.update(requestReader);
 
当你跟新了索引文件,然后再调用此段代码,你会发现类似结果
2008 - 4 - 23   1 : 28 : 12  org.apache.solr.update.DirectUpdateHandler2 commit
信息: start commit(optimize
= false , waitFlush = false , waitSearcher = true)
2008 - 4 - 23   1 : 28 : 12  org.apache.solr.search.SolrIndexSearcher <init>
信息: Opening Searcher@1474fc main
2008 - 4 - 23   1 : 28 : 12  org.apache.solr.update.DirectUpdateHandler2 commit
信息: end_commit_flush
2008 - 4 - 23   1 : 28 : 12  org.apache.solr.search.SolrIndexSearcher warm
信息: autowarming Searcher@1474fc main from Searcher@c550 main
        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.SolrIndexSearcher warm
信息: autowarming result for Searcher@1474fc main
        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.SolrIndexSearcher warm
信息: autowarming Searcher@1474fc main from Searcher@c550 main
        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.SolrIndexSearcher warm
信息: autowarming result for Searcher@1474fc main
        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.SolrIndexSearcher warm
信息: autowarming Searcher@1474fc main from Searcher@c550 main
        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.SolrIndexSearcher warm
信息: autowarming result for Searcher@1474fc main
        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.SolrCore registerSearcher
信息: Registered new searcher Searcher@1474fc main
2008 - 4 - 23   1 : 28 : 12  org.apache.solr.handler.XmlUpdateRequestHandler update
信息: commit 
0   9
 
从日志看出,searcher的确换了新的
此后你再重新搜索,结果果然更新了
 

 

你可能感兴趣的:(服务器,脚本,null,Lucene,Solr,工具)