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


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

Query that sets document score as a programmatic function of several (sub) scores: More...

#include <CustomScoreQuery.h>

+ Inheritance diagram for Lucene::CustomScoreQuery:

Public Member Functions

 CustomScoreQuery (const QueryPtr &subQuery)
 Create a CustomScoreQuery over input subQuery.
 
 CustomScoreQuery (const QueryPtr &subQuery, const ValueSourceQueryPtr &valSrcQuery)
 Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.
 
 CustomScoreQuery (const QueryPtr &subQuery, Collection< ValueSourceQueryPtr > valSrcQueries)
 Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.
 
virtual ~CustomScoreQuery ()
 
virtual String getClassName ()
 
boost::shared_ptr< CustomScoreQueryshared_from_this ()
 
virtual QueryPtr rewrite (const IndexReaderPtr &reader)
 Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
 
virtual void extractTerms (SetTerm terms)
 Adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form.
 
virtual LuceneObjectPtr clone (const LuceneObjectPtr &other=LuceneObjectPtr())
 Returns a clone of this query.
 
virtual String toString (const String &field)
 Prints a query to a string, with field assumed to be the default field and omitted.
 
virtual bool equals (const LuceneObjectPtr &other)
 Return whether two objects are equal.
 
virtual int32_t hashCode ()
 Return hash code for this object.
 
virtual double customScore (int32_t doc, double subQueryScore, Collection< double > valSrcScores)
 Compute a custom score by the subQuery score and a number of ValueSourceQuery scores.
 
virtual double customScore (int32_t doc, double subQueryScore, double valSrcScore)
 Compute a custom score by the subQuery score and the ValueSourceQuery score.
 
virtual ExplanationPtr customExplain (int32_t doc, const ExplanationPtr &subQueryExpl, Collection< ExplanationPtr > valSrcExpls)
 Explain the custom score.
 
virtual ExplanationPtr customExplain (int32_t doc, const ExplanationPtr &subQueryExpl, const ExplanationPtr &valSrcExpl)
 Explain the custom score.
 
virtual WeightPtr createWeight (const SearcherPtr &searcher)
 Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries, which re-write to themselves.
 
virtual bool isStrict ()
 Checks if this is strict custom scoring. In strict custom scoring, the ValueSource part does not participate in weight normalization. This may be useful when one wants full control over how scores are modified, and does not care about normalizing by the ValueSource part. One particular case where this is useful if for testing this query.
 
virtual void setStrict (bool strict)
 Set the strict mode of this query.
 
virtual String name ()
 A short name of this query, used in toString(String).
 
virtual String toString (const String &field)
 Prints a query to a string, with field assumed to be the default field and omitted.
 
virtual String toString ()
 Prints a query to a string.
 
- Public Member Functions inherited from Lucene::Query
 Query ()
 
virtual ~Query ()
 
boost::shared_ptr< Queryshared_from_this ()
 
virtual void setBoost (double b)
 Sets the boost for this query clause to b. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b.
 
virtual double getBoost ()
 Gets the boost for this clause. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. The boost is 1.0 by default.
 
virtual WeightPtr weight (const SearcherPtr &searcher)
 Constructs and initializes a Weight for a top-level query.
 
virtual QueryPtr combine (Collection< QueryPtr > queries)
 Called when re-writing queries under MultiSearcher.
 
virtual SimilarityPtr getSimilarity (const SearcherPtr &searcher)
 Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned.
 
String boostString ()
 Return given boost value as a string.
 
- 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 int32_t compareTo (const LuceneObjectPtr &other)
 Compare two objects.
 
- 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::Query
static String _getClassName ()
 
static QueryPtr mergeBooleanQueries (Collection< BooleanQueryPtr > queries)
 Merges the clauses of a set of BooleanQuery's into a single BooleanQuery.
 

Protected Member Functions

void ConstructQuery (const QueryPtr &subQuery, Collection< ValueSourceQueryPtr > valSrcQueries)
 
virtual CustomScoreProviderPtr getCustomScoreProvider (const IndexReaderPtr &reader)
 Returns a CustomScoreProvider that calculates the custom scores for the given IndexReader. The default implementation returns a default implementation as specified in the docs of CustomScoreProvider.
 
- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 

Protected Attributes

QueryPtr subQuery
 
Collection< ValueSourceQueryPtrvalSrcQueries
 
bool strict
 
- Protected Attributes inherited from Lucene::Query
double boost
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

Detailed Description

Query that sets document score as a programmatic function of several (sub) scores:

  1. the score of its subQuery (any query)
  2. (optional) the score of its ValueSourceQuery (or queries). For most simple/convenient use cases this query is likely to be a FieldScoreQuery

Subclasses can modify the computation by overriding getCustomScoreProvider.

Constructor & Destructor Documentation

◆ CustomScoreQuery() [1/3]

Lucene::CustomScoreQuery::CustomScoreQuery ( const QueryPtr subQuery)

Create a CustomScoreQuery over input subQuery.

Parameters
subQuerythe sub query whose scored is being customed. Must not be null.

◆ CustomScoreQuery() [2/3]

Lucene::CustomScoreQuery::CustomScoreQuery ( const QueryPtr subQuery,
const ValueSourceQueryPtr valSrcQuery 
)

Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.

Parameters
subQuerythe sub query whose score is being customized. Must not be null.
valSrcQuerya value source query whose scores are used in the custom score computation. For most simple/convenient use case this would be a FieldScoreQuery. This parameter is optional - it can be null.

◆ CustomScoreQuery() [3/3]

Lucene::CustomScoreQuery::CustomScoreQuery ( const QueryPtr subQuery,
Collection< ValueSourceQueryPtr valSrcQueries 
)

Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.

Parameters
subQuerythe sub query whose score is being customized. Must not be null.
valSrcQueriesvalue source queries whose scores are used in the custom score computation. For most simple/convenient use case these would be FieldScoreQueries. This parameter is optional - it can be null or even an empty array.

◆ ~CustomScoreQuery()

virtual Lucene::CustomScoreQuery::~CustomScoreQuery ( )
virtual

Member Function Documentation

◆ _getClassName()

static String Lucene::CustomScoreQuery::_getClassName ( )
inlinestatic

◆ clone()

virtual LuceneObjectPtr Lucene::CustomScoreQuery::clone ( const LuceneObjectPtr other = LuceneObjectPtr())
virtual

Returns a clone of this query.

Reimplemented from Lucene::Query.

◆ ConstructQuery()

void Lucene::CustomScoreQuery::ConstructQuery ( const QueryPtr subQuery,
Collection< ValueSourceQueryPtr valSrcQueries 
)
protected

◆ createWeight()

virtual WeightPtr Lucene::CustomScoreQuery::createWeight ( const SearcherPtr searcher)
virtual

Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries, which re-write to themselves.

Reimplemented from Lucene::Query.

◆ customExplain() [1/2]

virtual ExplanationPtr Lucene::CustomScoreQuery::customExplain ( int32_t  doc,
const ExplanationPtr subQueryExpl,
Collection< ExplanationPtr valSrcExpls 
)
virtual

Explain the custom score.

Deprecated: Will be removed in Lucene 3.1.

The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override getCustomScoreProvider and return a subclass of CustomScoreProvider for the given IndexReader.

◆ customExplain() [2/2]

virtual ExplanationPtr Lucene::CustomScoreQuery::customExplain ( int32_t  doc,
const ExplanationPtr subQueryExpl,
const ExplanationPtr valSrcExpl 
)
virtual

Explain the custom score.

Deprecated Will be removed in Lucene 3.1.

The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override getCustomScoreProvider and return a subclass of CustomScoreProvider for the given IndexReader.

◆ customScore() [1/2]

virtual double Lucene::CustomScoreQuery::customScore ( int32_t  doc,
double  subQueryScore,
Collection< double >  valSrcScores 
)
virtual

Compute a custom score by the subQuery score and a number of ValueSourceQuery scores.

Deprecated: Will be removed in Lucene 3.1.

The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override getCustomScoreProvider and return a subclass of CustomScoreProvider for the given IndexReader.

◆ customScore() [2/2]

virtual double Lucene::CustomScoreQuery::customScore ( int32_t  doc,
double  subQueryScore,
double  valSrcScore 
)
virtual

Compute a custom score by the subQuery score and the ValueSourceQuery score.

Deprecated: Will be removed in Lucene 3.1.

The doc is relative to the current reader, which is unknown to CustomScoreQuery when using per-segment search (since Lucene 2.9). Please override getCustomScoreProvider and return a subclass of CustomScoreProvider for the given IndexReader.

◆ equals()

virtual bool Lucene::CustomScoreQuery::equals ( const LuceneObjectPtr other)
virtual

Return whether two objects are equal.

Reimplemented from Lucene::Query.

◆ extractTerms()

virtual void Lucene::CustomScoreQuery::extractTerms ( SetTerm  terms)
virtual

Adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form.

Reimplemented from Lucene::Query.

◆ getClassName()

virtual String Lucene::CustomScoreQuery::getClassName ( )
inlinevirtual

Reimplemented from Lucene::Query.

◆ getCustomScoreProvider()

virtual CustomScoreProviderPtr Lucene::CustomScoreQuery::getCustomScoreProvider ( const IndexReaderPtr reader)
protectedvirtual

Returns a CustomScoreProvider that calculates the custom scores for the given IndexReader. The default implementation returns a default implementation as specified in the docs of CustomScoreProvider.

◆ hashCode()

virtual int32_t Lucene::CustomScoreQuery::hashCode ( )
virtual

Return hash code for this object.

Reimplemented from Lucene::Query.

◆ isStrict()

virtual bool Lucene::CustomScoreQuery::isStrict ( )
virtual

Checks if this is strict custom scoring. In strict custom scoring, the ValueSource part does not participate in weight normalization. This may be useful when one wants full control over how scores are modified, and does not care about normalizing by the ValueSource part. One particular case where this is useful if for testing this query.

Note: only has effect when the ValueSource part is not null.

◆ name()

virtual String Lucene::CustomScoreQuery::name ( )
virtual

A short name of this query, used in toString(String).

◆ rewrite()

virtual QueryPtr Lucene::CustomScoreQuery::rewrite ( const IndexReaderPtr reader)
virtual

Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.

Reimplemented from Lucene::Query.

◆ setStrict()

virtual void Lucene::CustomScoreQuery::setStrict ( bool  strict)
virtual

Set the strict mode of this query.

Parameters
strictThe strict mode to set.
See also
isStrict()

◆ shared_from_this()

boost::shared_ptr< CustomScoreQuery > Lucene::CustomScoreQuery::shared_from_this ( )
inline

◆ toString() [1/3]

virtual String Lucene::Query::toString ( )
virtual

Prints a query to a string.

Reimplemented from Lucene::Query.

◆ toString() [2/3]

virtual String Lucene::Query::toString ( const String &  field)
virtual

Prints a query to a string, with field assumed to be the default field and omitted.

The representation used is one that is supposed to be readable by QueryParser. However, there are the following limitations:

If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.

Some of the more complicated queries (eg. span queries) don't have a representation that can be parsed by QueryParser.

Reimplemented from Lucene::Query.

◆ toString() [3/3]

virtual String Lucene::CustomScoreQuery::toString ( const String &  field)
virtual

Prints a query to a string, with field assumed to be the default field and omitted.

The representation used is one that is supposed to be readable by QueryParser. However, there are the following limitations:

If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.

Some of the more complicated queries (eg. span queries) don't have a representation that can be parsed by QueryParser.

Reimplemented from Lucene::Query.

Field Documentation

◆ strict

bool Lucene::CustomScoreQuery::strict
protected

◆ subQuery

QueryPtr Lucene::CustomScoreQuery::subQuery
protected

◆ valSrcQueries

Collection<ValueSourceQueryPtr> Lucene::CustomScoreQuery::valSrcQueries
protected

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

clucene.sourceforge.net