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

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Lucene::Searcher Class Referenceabstract

An abstract base class for search implementations. Implements the main search methods. More...

`#include <Searcher.h>`

Inheritance diagram for Lucene::Searcher:

## Public Member Functions

| Searcher ()
virtual | ~Searcher ()
virtual String | getClassName ()
boost::shared_ptr< Searcher > | shared_from_this ()
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. More...
virtual void | search (const QueryPtr &query, const CollectorPtr &results)
| Lower-level search API. More...
virtual void | search (const QueryPtr &query, const FilterPtr &filter, const CollectorPtr &results)
| Lower-level search API. More...
virtual TopDocsPtr | search (const QueryPtr &query, const FilterPtr &filter, int32_t n)
| Finds the top n hits for query, applying filter if non-null. More...
virtual TopDocsPtr | search (const QueryPtr &query, int32_t n)
| Finds the top n hits for query. More...
virtual ExplanationPtr | explain (const QueryPtr &query, int32_t doc)
| Returns an Explanation that describes how doc scored against query. More...
virtual void | setSimilarity (const SimilarityPtr &similarity)
| Set the Similarity implementation used by this Searcher. More...
virtual SimilarityPtr | getSimilarity ()
| Return the Similarity implementation used by this Searcher. More...
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. More...
virtual void | search (const WeightPtr &weight, const FilterPtr &filter, const CollectorPtr &results)=0
| Lower-level search API. More...
virtual void | close ()=0
| Frees resources associated with this Searcher. Be careful not to call this method while you are still using objects that reference this Searchable. More...
virtual int32_t | docFreq (const TermPtr &term)=0
| Returns the number of documents containing term. More...
virtual int32_t | maxDoc ()=0
| Returns one greater than the largest possible document number. More...
virtual TopDocsPtr | search (const WeightPtr &weight, const FilterPtr &filter, int32_t n)=0
| 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 {} instead. More...
virtual DocumentPtr | doc (int32_t n)=0
| Returns the stored fields of document i. More...
virtual DocumentPtr | doc (int32_t n, const FieldSelectorPtr &fieldSelector)=0
| Get the Document at the n'th position. The FieldSelector may be used to determine what Fields to load and how they should be loaded. More...
virtual QueryPtr | rewrite (const QueryPtr &query)=0
| Called to re-write queries into primitive queries. More...
virtual ExplanationPtr | explain (const WeightPtr &weight, int32_t doc)=0
| Low-level implementation method. Returns an Explanation that describes how doc scored against weight. More...
virtual TopFieldDocsPtr | search (const WeightPtr &weight, const FilterPtr &filter, int32_t n, const SortPtr &sort)=0
| 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. More...
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. More...
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr())
| Return clone of this object. More...
virtual int32_t | hashCode ()
| Return hash code for this object. More...
virtual bool | equals (const LuceneObjectPtr &other)
| Return whether two objects are equal. More...
virtual int32_t | compareTo (const LuceneObjectPtr &other)
| Compare two objects. More...
virtual String | toString ()
| Returns a string representation of the object. More...
Public Member Functions inherited from Lucene::LuceneSync
virtual | ~LuceneSync ()
virtual SynchronizePtr | getSync ()
| Return this object synchronize lock. More...
virtual LuceneSignalPtr | getSignal ()
| Return this object signal. More...
virtual void | lock (int32_t timeout=0)
| Lock this object using an optional timeout. More...
virtual void | unlock ()
| Unlock this object. More...
virtual bool | holdsLock ()
| Returns true if this object is currently locked by current thread. More...
virtual void | wait (int32_t timeout=0)
| Wait for signal using an optional timeout. More...
virtual void | notifyAll ()
| Notify all threads waiting for signal. More...

## Static Public Member Functions

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

## Protected Member Functions

virtual WeightPtr | createWeight (const QueryPtr &query)
| Creates a weight for query. More...
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

SimilarityPtr | similarity
| The Similarity implementation used by this searcher. More...
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

## Detailed Description

An abstract base class for search implementations. Implements the main search methods.

Note that you can only access hits from a Searcher as long as it is not yet closed, otherwise an IO exception will be thrown.

## Constructor & Destructor Documentation

## ◆ Searcher()

Lucene::Searcher::Searcher | ( |  | ) |

## ◆ ~Searcher()

virtual Lucene::Searcher::~Searcher | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

static String Lucene::Searcher::_getClassName | ( |  | ) |

inline static

## ◆ close()

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

pure virtual

Frees resources associated with this Searcher. Be careful not to call this method while you are still using objects that reference this Searchable.

Implements Lucene::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ createWeight()

virtual WeightPtr Lucene::Searcher::createWeight | ( | const QueryPtr & | query | ) |

protected virtual

Creates a weight for query.

Returns
  New weight

Reimplemented in Lucene::MultiSearcher.

## ◆ doc() [1/2]

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

pure virtual

Returns the stored fields of document i.

See also
  IndexReader::document(int32_t)

Implements Lucene::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ doc() [2/2]

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

pure virtual

Get the Document at the n'th position. The FieldSelector may be used to determine what Fields 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::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ docFreq()

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

pure virtual

Returns the number of documents containing term.

See also
  IndexReader::docFreq(TermPtr)

Implements Lucene::Searchable.

Implemented in Lucene::IndexSearcher, Lucene::MultiSearcher, and Lucene::ParallelMultiSearcher.

## ◆ docFreqs()

virtual Collection<int32_t> Lucene::Searcher::docFreqs | ( | Collection< TermPtr > | terms | ) |

virtual

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.

Implements Lucene::Searchable.

## ◆ 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.

## ◆ explain() [2/2]

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

pure 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::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ getClassName()

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

inline virtual

Reimplemented from Lucene::Searchable.

Reimplemented in Lucene::IndexSearcher, Lucene::MultiSearcher, and Lucene::ParallelMultiSearcher.

## ◆ getSimilarity()

virtual SimilarityPtr Lucene::Searcher::getSimilarity | ( |  | ) |

virtual

Return the Similarity implementation used by this Searcher.

This defaults to the current value of Similarity#getDefault().

## ◆ maxDoc()

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

pure virtual

Returns one greater than the largest possible document number.

See also
  IndexReader::maxDoc()

Implements Lucene::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ rewrite()

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

pure virtual

Called to re-write queries into primitive queries.

Implements Lucene::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ search() [1/8]

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.

## ◆ search() [2/8]

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

## ◆ search() [3/8]

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.

## ◆ search() [4/8]

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.

## ◆ search() [5/8]

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

virtual

Finds the top n hits for query.

## ◆ search() [6/8]

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

pure 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::Searchable.

Implemented in Lucene::IndexSearcher, and Lucene::MultiSearcher.

## ◆ search() [7/8]

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

pure 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 {} instead.

Implements Lucene::Searchable.

Implemented in Lucene::IndexSearcher, Lucene::MultiSearcher, and Lucene::ParallelMultiSearcher.

## ◆ search() [8/8]

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

pure 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::Searchable.

Implemented in Lucene::IndexSearcher, Lucene::MultiSearcher, and Lucene::ParallelMultiSearcher.

## ◆ setSimilarity()

virtual void Lucene::Searcher::setSimilarity | ( | const SimilarityPtr & | similarity | ) |

virtual

Set the Similarity implementation used by this Searcher.

## ◆ shared_from_this()

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

inline

## Field Documentation

## ◆ similarity

SimilarityPtr Lucene::Searcher::similarity

protected

The Similarity implementation used by this searcher.

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

- Searcher.h

clucene.sourceforge.net