Constructor: |
public IndexSearcher(Directory path) throws CorruptIndexException, IOException {
this(IndexReader.open(path, true), true);
}
Creates a searcher searching the index in the named
directory, with readOnly=true Parameters:
path - directory where IndexReader will be opened
Throws:
CorruptIndexException - if the index is corrupt
IOException - if there is a low-level IO error
|
public IndexSearcher(IndexReader r) {
this(r, false);
}
Creates a searcher searching the provided index. |
public IndexSearcher(Directory path,
boolean readOnly) throws CorruptIndexException, IOException {
this(IndexReader.open(path, readOnly), true);
}
Creates a searcher searching the index in the named
directory. You should pass readOnly=true, since it
gives much better concurrent performance, unless you
intend to do write operations (delete documents or
change norms) with the underlying IndexReader. Parameters:
path - directory where IndexReader will be opened
readOnly - if true, the underlying IndexReader
will be opened readOnly
Throws:
CorruptIndexException - if the index is corrupt
IOException - if there is a low-level IO error
|
public IndexSearcher(IndexReader reader,
IndexReader[] subReaders,
int[] docStarts) {
this.reader = reader;
this.subReaders = subReaders;
this.docStarts = docStarts;
closeReader = false;
}
|
Method from org.apache.lucene.search.IndexSearcher Detail: |
public void close() throws IOException {
if(closeReader)
reader.close();
}
Note that the underlying IndexReader is not closed, if
IndexSearcher was constructed with IndexSearcher(IndexReader r).
If the IndexReader was supplied implicitly by specifying a directory, then
the IndexReader gets closed. |
public Document doc(int i) throws CorruptIndexException, IOException {
return reader.document(i);
}
|
public Document doc(int i,
FieldSelector fieldSelector) throws CorruptIndexException, IOException {
return reader.document(i, fieldSelector);
}
|
public int docFreq(Term term) throws IOException {
return reader.docFreq(term);
}
|
public Explanation explain(Weight weight,
int doc) throws IOException {
int n = ReaderUtil.subIndex(doc, docStarts);
int deBasedDoc = doc - docStarts[n];
return weight.explain(subReaders[n], deBasedDoc);
}
|
protected void gatherSubReaders(List<IndexReader> allSubReaders,
IndexReader r) {
ReaderUtil.gatherSubReaders(allSubReaders, r);
}
|
public IndexReader getIndexReader() {
return reader;
}
|
public int maxDoc() throws IOException {
return reader.maxDoc();
}
|
public Query rewrite(Query original) throws IOException {
Query query = original;
for (Query rewrittenQuery = query.rewrite(reader); rewrittenQuery != query;
rewrittenQuery = query.rewrite(reader)) {
query = rewrittenQuery;
}
return query;
}
|
public TopDocs search(Weight weight,
Filter filter,
int nDocs) throws IOException {
if (nDocs < = 0) {
throw new IllegalArgumentException("nDocs must be > 0");
}
TopScoreDocCollector collector = TopScoreDocCollector.create(nDocs, !weight.scoresDocsOutOfOrder());
search(weight, filter, collector);
return collector.topDocs();
}
|
public void search(Weight weight,
Filter filter,
Collector collector) throws IOException {
if (filter == null) {
for (int i = 0; i < subReaders.length; i++) { // search each subreader
collector.setNextReader(subReaders[i], docStarts[i]);
Scorer scorer = weight.scorer(subReaders[i], !collector.acceptsDocsOutOfOrder(), true);
if (scorer != null) {
scorer.score(collector);
}
}
} else {
for (int i = 0; i < subReaders.length; i++) { // search each subreader
collector.setNextReader(subReaders[i], docStarts[i]);
searchWithFilter(subReaders[i], weight, filter, collector);
}
}
}
|
public TopFieldDocs search(Weight weight,
Filter filter,
int nDocs,
Sort sort) throws IOException {
return search(weight, filter, nDocs, sort, true);
}
|
public TopFieldDocs search(Weight weight,
Filter filter,
int nDocs,
Sort sort,
boolean fillFields) throws IOException {
TopFieldCollector collector = TopFieldCollector.create(sort, nDocs,
fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.scoresDocsOutOfOrder());
search(weight, filter, collector);
return (TopFieldDocs) collector.topDocs();
}
|
public void setDefaultFieldSortScoring(boolean doTrackScores,
boolean doMaxScore) {
fieldSortDoTrackScores = doTrackScores;
fieldSortDoMaxScore = doMaxScore;
}
By default, no scores are computed when sorting by
field (using #search(Query,Filter,int,Sort) ).
You can change that, per IndexSearcher instance, by
calling this method. Note that this will incur a CPU
cost. |