Lucene++ - a full-featured, c++ search engine
API Documentation

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Lucene::IndexSearcher Class Reference

Implements search over a single IndexReader. More...

`#include <IndexSearcher.h>`

Inheritance diagram for Lucene::IndexSearcher:

## Public Member Functions

| IndexSearcher (const DirectoryPtr &path, bool 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.
| IndexSearcher (const IndexReaderPtr &reader)
| Creates a searcher searching the provided index.
| IndexSearcher (const IndexReaderPtr &reader, Collection< IndexReaderPtr > subReaders, Collection< int32_t > docStarts)
| Directly specify the reader, subReaders and their docID starts.
virtual | ~IndexSearcher ()
virtual String | getClassName ()
boost::shared_ptr< IndexSearcher > | shared_from_this ()
IndexReaderPtr | getIndexReader ()
| Return the `IndexReader` this searches.
virtual void | close ()
| Note that the underlying IndexReader is not closed, if IndexSearcher was constructed with IndexSearcher(const IndexReaderPtr& reader). If the IndexReader was supplied implicitly by specifying a directory, then the IndexReader gets closed.
virtual int32_t | docFreq (const TermPtr &term)
| Returns the number of documents containing term.
virtual DocumentPtr | doc (int32_t n)
| Returns the stored fields of document i.
virtual DocumentPtr | doc (int32_t n, const FieldSelectorPtr &fieldSelector)
| Get the `Document` at the n'th position. The `FieldSelector` may be used to determine what `Field`s to load and how they should be loaded.
virtual int32_t | maxDoc ()
| Returns one greater than the largest possible document number.
virtual TopDocsPtr | search (const WeightPtr &weight, const FilterPtr &filter, int32_t n)
| Low-level search implementation. Finds the top n hits for query, applying filter if non-null. Applications should usually call `Searcher#search(QueryPtr, int32_t)` or `Searcher#search(QueryPtr, FilterPtr, int32_t)` instead.
virtual TopFieldDocsPtr | search (const WeightPtr &weight, const FilterPtr &filter, int32_t n, const SortPtr &sort)
| Low-level search implementation with arbitrary sorting. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort.
virtual TopFieldDocsPtr | search (const WeightPtr &weight, const FilterPtr &filter, int32_t n, const SortPtr &sort, bool fillFields)
| Just like `search(WeightPtr, FilterPtr, int32_t, SortPtr)`, but you choose whether or not the fields in the returned `FieldDoc` instances should be set by specifying fillFields.
virtual void | search (const WeightPtr &weight, const FilterPtr &filter, const CollectorPtr &results)
| Lower-level search API.
virtual QueryPtr | rewrite (const QueryPtr &query)
| Called to re-write queries into primitive queries.
virtual ExplanationPtr | explain (const WeightPtr &weight, int32_t doc)
| Low-level implementation method. Returns an Explanation that describes how doc scored against weight.
virtual void | setDefaultFieldSortScoring (bool doTrackScores, bool doMaxScore)
| By default, no scores are computed when sorting by field (using `search(QueryPtr, FilterPtr, int32_t, SortPtr)`). You can change that, per IndexSearcher instance, by calling this method. Note that this will incur a CPU cost.
virtual TopFieldDocsPtr | search (const QueryPtr &query, const FilterPtr &filter, int32_t n, const SortPtr &sort)
| Search implementation with arbitrary sorting. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort.
virtual void | search (const QueryPtr &query, const CollectorPtr &results)
| Lower-level search API.
virtual void | search (const QueryPtr &query, const FilterPtr &filter, const CollectorPtr &results)
| Lower-level search API.
virtual TopDocsPtr | search (const QueryPtr &query, const FilterPtr &filter, int32_t n)
| Finds the top n hits for query, applying filter if non-null.
virtual TopDocsPtr | search (const QueryPtr &query, int32_t n)
| Finds the top n hits for query.
virtual ExplanationPtr | explain (const QueryPtr &query, int32_t doc)
| Returns an Explanation that describes how doc scored against query.
Public Member Functions inherited from Lucene::Searcher
| Searcher ()
virtual | ~Searcher ()
boost::shared_ptr< Searcher > | shared_from_this ()
virtual void | setSimilarity (const SimilarityPtr &similarity)
| Set the Similarity implementation used by this Searcher.
virtual SimilarityPtr | getSimilarity ()
| Return the Similarity implementation used by this Searcher.
virtual Collection< int32_t > | docFreqs (Collection< TermPtr > terms)
| For each term in the terms array, calculates the number of documents containing term. Returns an array with these document frequencies. Used to minimize number of remote calls.
Public Member Functions inherited from Lucene::Searchable
virtual | ~Searchable ()
Public Member Functions inherited from Lucene::LuceneObject
virtual | ~LuceneObject ()
virtual void | initialize ()
| Called directly after instantiation to create objects that depend on this object being fully constructed.
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr())
| Return clone of this object.
virtual int32_t | hashCode ()
| Return hash code for this object.
virtual bool | equals (const LuceneObjectPtr &other)
| Return whether two objects are equal.
virtual int32_t | compareTo (const LuceneObjectPtr &other)
| Compare two objects.
virtual String | toString ()
| Returns a string representation of the object.
Public Member Functions inherited from Lucene::LuceneSync
virtual | ~LuceneSync ()
virtual SynchronizePtr | getSync ()
| Return this object synchronize lock.
virtual LuceneSignalPtr | getSignal ()
| Return this object signal.
virtual void | lock (int32_t timeout=0)
| Lock this object using an optional timeout.
virtual void | unlock ()
| Unlock this object.
virtual bool | holdsLock ()
| Returns true if this object is currently locked by current thread.
virtual void | wait (int32_t timeout=0)
| Wait for signal using an optional timeout.
virtual void | notifyAll ()
| Notify all threads waiting for signal.

## Static Public Member Functions

static String | _getClassName ()
Static Public Member Functions inherited from Lucene::Searcher
static String | _getClassName ()
Static Public Member Functions inherited from Lucene::Searchable
static String | _getClassName ()

## Data Fields

IndexReaderPtr | reader

## Protected Member Functions

void | ConstructSearcher (const IndexReaderPtr &reader, bool closeReader)
void | gatherSubReaders (Collection< IndexReaderPtr > allSubReaders, const IndexReaderPtr &reader)
void | searchWithFilter (const IndexReaderPtr &reader, const WeightPtr &weight, const FilterPtr &filter, const CollectorPtr &collector)
Protected Member Functions inherited from Lucene::Searcher
virtual WeightPtr | createWeight (const QueryPtr &query)
| Creates a weight for query.
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

bool | closeReader
Collection< IndexReaderPtr > | subReaders
Collection< int32_t > | docStarts
bool | fieldSortDoTrackScores
bool | fieldSortDoMaxScore
Protected Attributes inherited from Lucene::Searcher
SimilarityPtr | similarity
| The Similarity implementation used by this searcher.
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

## Detailed Description

Implements search over a single IndexReader.

Applications usually need only call the inherited `search(QueryPtr, int32_t)` or `search(QueryPtr, FilterPtr, int32_t)` methods. For performance reasons it is recommended to open only one IndexSearcher and use it for all of your searches.

NOTE: `IndexSearcher` instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the IndexSearcher instance; use your own (non-Lucene) objects instead.

## Constructor & Destructor Documentation

## ◆ IndexSearcher() [1/3]

Lucene::IndexSearcher::IndexSearcher | ( | const DirectoryPtr & | path,
|  | bool | 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

Referenced by _getClassName().

## ◆ IndexSearcher() [2/3]

Lucene::IndexSearcher::IndexSearcher | ( | const IndexReaderPtr & | reader | ) |

Creates a searcher searching the provided index.

References reader.

## ◆ IndexSearcher() [3/3]

Lucene::IndexSearcher::IndexSearcher | ( | const IndexReaderPtr & | reader,
|  | Collection< IndexReaderPtr > | subReaders,
|  | Collection< int32_t > | docStarts )

Directly specify the reader, subReaders and their docID starts.

References docStarts, reader, and subReaders.

## ◆ ~IndexSearcher()

virtual Lucene::IndexSearcher::~IndexSearcher | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

String Lucene::IndexSearcher::_getClassName | ( |  | ) |

inline static

References IndexSearcher().

## ◆ close()

virtual void Lucene::IndexSearcher::close | ( |  | ) |

virtual

Note that the underlying IndexReader is not closed, if IndexSearcher was constructed with IndexSearcher(const IndexReaderPtr& reader). If the IndexReader was supplied implicitly by specifying a directory, then the IndexReader gets closed.

Implements Lucene::Searcher.

## ◆ ConstructSearcher()

void Lucene::IndexSearcher::ConstructSearcher | ( | const IndexReaderPtr & | reader,
|  | bool | closeReader )

protected

References closeReader, and reader.

## ◆ doc() [1/2]

virtual DocumentPtr Lucene::IndexSearcher::doc | ( | int32_t | n | ) |

virtual

Returns the stored fields of document i.

See also
  IndexReader::document(int32_t)

Implements Lucene::Searcher.

Referenced by explain().

## ◆ doc() [2/2]

virtual DocumentPtr Lucene::IndexSearcher::doc | ( | int32_t | n,
|  | const FieldSelectorPtr & | fieldSelector )

virtual

Get the `Document` at the n'th position. The `FieldSelector` may be used to determine what `Field`s to load and how they should be loaded.

NOTE: If the underlying Reader (more specifically, the underlying FieldsReader) is closed before the lazy `Field` is loaded an exception may be thrown. If you want the value of a lazy `Field` to be available after closing you must explicitly load it or fetch the Document again with a new loader.

Parameters

  n | Get the document at the n'th position
  fieldSelector | The `FieldSelector` to use to determine what Fields should be loaded on the Document. May be null, in which case all Fields will be loaded.

Returns
  The stored fields of the `Document` at the n'th position

See also
  IndexReader#document(int32_t, FieldSelectorPtr)
  Fieldable
  FieldSelector
  SetBasedFieldSelector
  LoadFirstFieldSelector

Implements Lucene::Searcher.

## ◆ docFreq()

virtual int32_t Lucene::IndexSearcher::docFreq | ( | const TermPtr & | term | ) |

virtual

Returns the number of documents containing term.

See also
  IndexReader#docFreq(TermPtr)

Implements Lucene::Searcher.

## ◆ explain() [1/2]

virtual ExplanationPtr Lucene::Searcher::explain | ( | const QueryPtr & | query,
|  | int32_t | doc )

virtual

Returns an Explanation that describes how doc scored against query.

This is intended to be used in developing Similarity implementations, and for good performance, should not be displayed with every hit. Computing an explanation is as expensive as executing the query over the entire index.

Reimplemented from Lucene::Searcher.

## ◆ explain() [2/2]

virtual ExplanationPtr Lucene::IndexSearcher::explain | ( | const WeightPtr & | weight,
|  | int32_t | doc )

virtual

Low-level implementation method. Returns an Explanation that describes how doc scored against weight.

This is intended to be used in developing Similarity implementations, and for good performance, should not be displayed with every hit. Computing an explanation is as expensive as executing the query over the entire index.

Applications should call `Searcher#explain(QueryPtr, int32_t)`.

Implements Lucene::Searcher.

References doc().

## ◆ gatherSubReaders()

void Lucene::IndexSearcher::gatherSubReaders | ( | Collection< IndexReaderPtr > | allSubReaders,
|  | const IndexReaderPtr & | reader )

protected

References reader.

## ◆ getClassName()

virtual String Lucene::IndexSearcher::getClassName | ( |  | ) |

inline virtual

Reimplemented from Lucene::Searcher.

## ◆ getIndexReader()

IndexReaderPtr Lucene::IndexSearcher::getIndexReader | ( |  | ) |

Return the `IndexReader` this searches.

## ◆ maxDoc()

virtual int32_t Lucene::IndexSearcher::maxDoc | ( |  | ) |

virtual

Returns one greater than the largest possible document number.

See also
  IndexReader::maxDoc()

Implements Lucene::Searcher.

References Lucene::Searcher::explain(), and Lucene::Searcher::search().

## ◆ rewrite()

virtual QueryPtr Lucene::IndexSearcher::rewrite | ( | const QueryPtr & | query | ) |

virtual

Called to re-write queries into primitive queries.

Implements Lucene::Searcher.

## ◆ search() [1/9]

virtual void Lucene::Searcher::search | ( | const QueryPtr & | query,
|  | const CollectorPtr & | results )

virtual

Lower-level search API.

`Collector#collect(int32_t)` is called for every matching document.

Applications should only use this if they need all of the matching documents. The high-level search API (`Searcher#search(QueryPtr, int32_t)`) is usually more efficient, as it skips non-high-scoring hits.

Note: The score passed to this method is a raw score. In other words, the score will not necessarily be a double whose value is between 0 and 1.

Reimplemented from Lucene::Searcher.

## ◆ search() [2/9]

virtual void Lucene::Searcher::search | ( | const QueryPtr & | query,
|  | const FilterPtr & | filter,
|  | const CollectorPtr & | results )

virtual

Lower-level search API.

`Collector#collect(int32_t)` is called for every matching document. Collector-based access to remote indexes is discouraged.

Applications should only use this if they need all of the matching documents. The high-level search API (`Searcher#search(QueryPtr, FilterPtr, int32_t)`) is usually more efficient, as it skips non-high-scoring hits.

Parameters

  query | To match documents
  filter | If non-null, used to permit documents to be collected.
  results | To receive hits

Reimplemented from Lucene::Searcher.

## ◆ search() [3/9]

virtual TopDocsPtr Lucene::Searcher::search | ( | const QueryPtr & | query,
|  | const FilterPtr & | filter,
|  | int32_t | n )

virtual

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

Reimplemented from Lucene::Searcher.

## ◆ search() [4/9]

virtual TopFieldDocsPtr Lucene::Searcher::search | ( | const QueryPtr & | query,
|  | const FilterPtr & | filter,
|  | int32_t | n,
|  | const SortPtr & | sort )

virtual

Search implementation with arbitrary sorting. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort.

NOTE: this does not compute scores by default; use `IndexSearcher#setDefaultFieldSortScoring` to enable scoring.

Reimplemented from Lucene::Searcher.

## ◆ search() [5/9]

virtual TopDocsPtr Lucene::Searcher::search | ( | const QueryPtr & | query,
|  | int32_t | n )

virtual

Finds the top n hits for query.

Reimplemented from Lucene::Searcher.

## ◆ search() [6/9]

virtual void Lucene::IndexSearcher::search | ( | const WeightPtr & | weight,
|  | const FilterPtr & | filter,
|  | const CollectorPtr & | collector )

virtual

Lower-level search API.

`Collector#collect(int32_t)` is called for every document. Collector-based access to remote indexes is discouraged.

Applications should only use this if they need all of the matching documents. The high-level search API (`Searcher#search(QueryPtr, int32_t)`) is usually more efficient, as it skips non-high-scoring hits.

Parameters

  weight | To match documents
  filter | If non-null, used to permit documents to be collected.
  collector | To receive hits

Implements Lucene::Searcher.

## ◆ search() [7/9]

virtual TopDocsPtr Lucene::IndexSearcher::search | ( | const WeightPtr & | weight,
|  | const FilterPtr & | filter,
|  | int32_t | n )

virtual

Low-level search implementation. Finds the top n hits for query, applying filter if non-null. Applications should usually call `Searcher#search(QueryPtr, int32_t)` or `Searcher#search(QueryPtr, FilterPtr, int32_t)` instead.

Implements Lucene::Searcher.

## ◆ search() [8/9]

virtual TopFieldDocsPtr Lucene::IndexSearcher::search | ( | const WeightPtr & | weight,
|  | const FilterPtr & | filter,
|  | int32_t | n,
|  | const SortPtr & | sort )

virtual

Low-level search implementation with arbitrary sorting. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort.

Applications should usually call `Searcher#search(QueryPtr, FilterPtr, int32_t, SortPtr)` instead.

Implements Lucene::Searcher.

## ◆ search() [9/9]

virtual TopFieldDocsPtr Lucene::IndexSearcher::search | ( | const WeightPtr & | weight,
|  | const FilterPtr & | filter,
|  | int32_t | n,
|  | const SortPtr & | sort,
|  | bool | fillFields )

virtual

Just like `search(WeightPtr, FilterPtr, int32_t, SortPtr)`, but you choose whether or not the fields in the returned `FieldDoc` instances should be set by specifying fillFields.

NOTE: this does not compute scores by default. If you need scores, create a `TopFieldCollector` instance by calling `TopFieldCollector#create` and then pass that to `search(WeightPtr, FilterPtr, CollectorPtr)`.

## ◆ searchWithFilter()

void Lucene::IndexSearcher::searchWithFilter | ( | const IndexReaderPtr & | reader,
|  | const WeightPtr & | weight,
|  | const FilterPtr & | filter,
|  | const CollectorPtr & | collector )

protected

References reader.

## ◆ setDefaultFieldSortScoring()

virtual void Lucene::IndexSearcher::setDefaultFieldSortScoring | ( | bool | doTrackScores,
|  | bool | doMaxScore )

virtual

By default, no scores are computed when sorting by field (using `search(QueryPtr, FilterPtr, int32_t, SortPtr)`). You can change that, per IndexSearcher instance, by calling this method. Note that this will incur a CPU cost.

Parameters

  doTrackScores | If true, then scores are returned for every matching document in `TopFieldDocs`.
  doMaxScore | If true, then the max score for all matching docs is computed.

## ◆ shared_from_this()

boost::shared_ptr< IndexSearcher > Lucene::IndexSearcher::shared_from_this | ( |  | ) |

inline

## Field Documentation

## ◆ closeReader

bool Lucene::IndexSearcher::closeReader

protected

Referenced by ConstructSearcher().

## ◆ docStarts

Collection<int32_t> Lucene::IndexSearcher::docStarts

protected

Referenced by IndexSearcher().

## ◆ fieldSortDoMaxScore

bool Lucene::IndexSearcher::fieldSortDoMaxScore

protected

## ◆ fieldSortDoTrackScores

bool Lucene::IndexSearcher::fieldSortDoTrackScores

protected

## ◆ reader

IndexReaderPtr Lucene::IndexSearcher::reader

Referenced by ConstructSearcher(), gatherSubReaders(), IndexSearcher(), IndexSearcher(), and searchWithFilter().

## ◆ subReaders

Collection<IndexReaderPtr> Lucene::IndexSearcher::subReaders

protected

Referenced by IndexSearcher().

The documentation for this class was generated from the following file:

- IndexSearcher.h

clucene.sourceforge.net