|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.lucene.search.Searcher
org.apache.lucene.search.IndexSearcher
org.apache.lucene.search.DelayCloseIndexSearcher
Implements search over a single IndexReader, but remains open even if close() is called. This way it can be shared by
multiple objects that need to search the index without being aware of the keep-the-index-open-until-it-changes logic.
Basic use (works, but can slow all searcher while opening a new Searcher instance:
class SearcherFactory {
SearcherFactory(Directory directory){
currentSearcher=new DelayCloseIndexSearcher(directory);
}
public synchronized IndexSearcher createSearcher() {
if (!currentSearcher.isCurrent()) {
currentSearcher.closeWhenDone();
currentSearcher=new DelayCloseIndexSearcher(directory);
}
currentSearcher.open();
return currentSearcher;
}
void synchronized close() {
currentSearcher.closeWhenDone();
}
private final Directory directory;
private DelayCloseIndexSearcher currentSearcher;
}
Objects that need to search the index do the following://searcherFactory is created once at startup IndexSearcher indexSearcher=searcherFactory.createSearcher(); Hits hist=indexSearcher.search(query, filter, sort); ... // handle results indexSearcher.close(); // when the application shuts down searcherFactory.close();
| Constructor Summary | |
DelayCloseIndexSearcher(org.apache.lucene.store.Directory directory)
Creates a DelayCloseIndexSearcher searching the index in the provided directory.. |
|
DelayCloseIndexSearcher(org.apache.lucene.index.IndexReader indexReader)
Creates a DelayCloseIndexSearcher searching the index using the provided Reader |
|
DelayCloseIndexSearcher(org.apache.lucene.index.IndexReader indexReader,
org.apache.lucene.store.Directory directory)
Deprecated. Use DelayCloseIndexSearcher(org.apache.lucene.index.IndexReader) instead |
|
DelayCloseIndexSearcher(java.lang.String string)
|
|
| Method Summary | |
void |
close()
Should be called once for every call to open(). |
void |
closeWhenDone()
Signals that this instance may really close when all open() calls have been balanced with a call to close(). |
boolean |
isClosed()
Returns wether the underlying IndexSearcher has really been closed. |
boolean |
isCurrent()
Returns whether the underlying IndexSearcher instance still works on a current version of the index. |
void |
open()
This should be called whenever this instances is passed as a new IndexSearcher. |
| Methods inherited from class org.apache.lucene.search.IndexSearcher |
doc, doc, docFreq, explain, getIndexReader, maxDoc, rewrite, search, search, search |
| Methods inherited from class org.apache.lucene.search.Searcher |
createWeight, docFreqs, explain, getSimilarity, search, search, search, search, search, search, search, search, setSimilarity |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DelayCloseIndexSearcher(java.lang.String string)
throws java.io.IOException
public DelayCloseIndexSearcher(org.apache.lucene.store.Directory directory)
throws java.io.IOException
directory - containing the index.
java.io.IOException - if an I/O error occurs.
public DelayCloseIndexSearcher(org.apache.lucene.index.IndexReader indexReader)
throws java.io.IOException
indexReader - Reader to use for opening the searcher
java.io.IOException - if an I/O error occurs
public DelayCloseIndexSearcher(org.apache.lucene.index.IndexReader indexReader,
org.apache.lucene.store.Directory directory)
throws java.io.IOException
DelayCloseIndexSearcher(org.apache.lucene.index.IndexReader) instead
indexReader - The indexReader to use for the searcherdirectory - No longer in use
java.io.IOException - If there's a problem opening the underlying searcher| Method Detail |
public void open()
public void closeWhenDone()
throws java.io.IOException
java.io.IOException - if an I/O error occurs.
public boolean isCurrent()
throws java.io.IOException
java.io.IOException - if an I/O error occurs.public boolean isClosed()
public void close()
throws java.io.IOException
java.io.IOException - if an I/O error occurs.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||