Lucene - IndexSearcher



This class acts as a core component which reads/searches indexes during the searching process.

Class Declaration

Following is the declaration for org.apache.lucene.search.IndexSearcher class −

public class IndexSearcher
   extends Searcher

Field

Following are the fields for org.apache.lucene.index.IndexWriter class −

  • protected int[] docStarts
  • protected IndexReader[] subReaders
  • protected IndexSearcher[] subSearchers

Class Constructors

The following table shows a list of class constructors −

S.No. Constructor & Description
1

IndexSearcher(Directory path)

Deprecated. Use IndexSearcher(IndexReader) instead.

2

IndexSearcher(Directory path, boolean readOnly)

Deprecated. Use IndexSearcher(IndexReader) instead.

3

IndexSearcher(IndexReader r)

Creates a searcher searching the provided index.

4

IndexSearcher(IndexReader r, ExecutorService executor)

Runs searches for each segment separately, using the provided ExecutorService.

5

IndexSearcher(IndexReader reader, IndexReader[] subReaders, int[] docStarts)

Expert: directly specify the reader, subReaders and their docID starts.

6

IndexSearcher(IndexReader reader, IndexReader[] subReaders, int[] docStarts, ExecutorService executor)

Expert: directly specify the reader, subReaders and their docID starts, and an ExecutorService.

Class Methods

The following table shows the different class methods −

S.No. Method & Description
1

void close()

Note that the underlying IndexReader is not closed, if IndexSearcher was constructed with IndexSearcher(IndexReader).

2

Weight createNormalizedWeight(Query query)

Creates a normalized weight for a top-level Query.

3

Document doc(int docID)

Returns the stored fields of document ID.

4

Document doc(int docID, FieldSelector fieldSelector)

Get the Document at the nth position.

5

int docFreq(Term term)

Returns total docFreq for this term.

6

Explanation explain(Query query, int doc)

Returns an Explanation that describes how a doc scored against a query.

7

Explanation explain(Weight weight, int doc)

Expert: Low-level implementation method that returns an Explanation that describes how a doc scored against weight.

8

protected void gatherSubReaders(List allSubReaders, IndexReader r)

9

IndexReader getIndexReader()

Returns the IndexReader this searches.

10

Similarity getSimilarity()

Expert: Returns the Similarity implementation used by this Searcher.

11

IndexReader[] getSubReaders()

Returns the atomic subReaders used by this searcher.

12

int maxDoc()

Expert: Returns one greater than the largest possible document number.

13

Query rewrite(Query original)

Expert: Called to re-write queries into primitive queries.

14

void search(Query query, Collector results)

Lower-level search API.

15

void search(Query query, Filter filter, Collector results)

Lower-level search API.

16

TopDocs search(Query query, Filter filter, int n)

Finds the top n hits for query, applying filter if non-null.

17

TopFieldDocs search(Query query, Filter filter, int n, Sort sort)

Search implementation with arbitrary sorting.

18

TopDocs search(Query query, int n)

Finds the top n hits for query.

19

TopFieldDocs search(Query query, int n, Sort sort)

Search implementation with arbitrary sorting and no filter.

20

void search(Weight weight, Filter filter, Collector collector)

Lower-level search API.

21

TopDocs search(Weight weight, Filter filter, int nDocs)

Expert: Low-level search implementation.

22

TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort)

Expert: Low-level search implementation with arbitrary sorting.

23

protected TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort, boolean fillFields)

This works like search(Weight, Filter, int, Sort), but here you choose whether or not the fields in the returned FieldDoc instances should be set by specifying fillFields.

24

protected TopDocs search(Weight weight, Filter filter, ScoreDoc after, int nDocs)

Expert: Low-level search implementation.

25

TopDocs searchAfter(ScoreDoc after, Query query, Filter filter, int n)

Finds the top n hits for query, applying filter if non-null, where all results are after a previous result (after).

26

TopDocs searchAfter(ScoreDoc after, Query query, int n)

Finds the top n hits for query where all results are after a previous result (after).

27

void setDefaultFieldSortScoring(boolean doTrackScores, boolean doMaxScore)

By default, no scores are computed when sorting by field (using search(Query,Filter,int,Sort)).

28

void setSimilarity(Similarity similarity)

Expert: Set the Similarity implementation used by this Searcher.

29

String toString()

Methods Inherited

This class inherits methods from the following classes −

  • org.apache.lucene.search.Searcher
  • java.lang.Object
lucene_searching_classes.htm
Advertisements