English 中文(简体)
Lucene seems to be caching search results - why?
原标题:
  • 时间:2009-11-26 08:24:33
  •  标签:
  • java
  • lucene

In my project we use Lucene 2.4.1 for fulltext search. This is a J2EE project, IndexSearcher is created once. In the background, the index is refreshed every couple of minutes (when the content changes). Users can search the index through a search mechanism on the page.

The problem is, the results returned by Lucene seem to be cached somehow.

This is scenario I noticed:

  • I start the application and search for keyword - 6 results are returned,
  • Index is refreshed, using Luke I see, that there are 8 results now to query keyword ,
  • I search again using the application, again 6 results are returned.

I analyzed our configuration and haven t found any caching anywhere. I have debugged the search, and there is no caching in out code, searcher.search returnes 6 results.

Does Lucene cache results internally somehow? What properties etc. should I check?

最佳回答

To see changes made by IndexWriters against an index for which you have an open IndexReader, be sure to call IndexReader.reopen() to see the latest changes.

Make sure also that your IndexWriter is committing the changes, either through an explicit commit(), a close(), or having autoCommit set to true.

问题回答

With versions prior to 2.9.0, Lucene cached automatically the results of queries. With later releases there s no caching unless you wrap your query in a QueryFilter and then wrap the result in a CachingWrapperFilter. You could consider switching to a release >= 2.9.0 if reopening the index becomes a problem

One more note: In order to IndexReader find the real-time other threads updated documents, when initialize IndexReader, the parameter "read-only" has to be false. Otherwise, method reopen() will not work.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签