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


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

Delegating scoring implementation. Useful in Query#getSimilarity(Searcher) implementations, to override only certain methods of a Searcher's Similarity implementation. More...

#include <SimilarityDelegator.h>

+ Inheritance diagram for Lucene::SimilarityDelegator:

Public Member Functions

 SimilarityDelegator (const SimilarityPtr &delegee)
 
virtual ~SimilarityDelegator ()
 
virtual String getClassName ()
 
boost::shared_ptr< SimilarityDelegatorshared_from_this ()
 
virtual double computeNorm (const String &field, const FieldInvertStatePtr &state)
 Compute the normalization value for a field, given the accumulated state of term processing for this field (see FieldInvertState).
 
virtual double lengthNorm (const String &fieldName, int32_t numTokens)
 Computes the normalization value for a field given the total number of terms contained in a field. These values, together with field boosts, are stored in an index and multiplied into scores for hits on each field by the search code.
 
virtual double queryNorm (double sumOfSquaredWeights)
 Computes the normalization value for a query given the sum of the squared weights of each of the query terms. This value is multiplied into the weight of each query term. While the classic query normalization factor is computed as 1/sqrt(sumOfSquaredWeights), other implementations might completely ignore sumOfSquaredWeights (ie return 1).
 
virtual double tf (double freq)
 Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the idf(int32_t, int32_t) factor for each term in the query and these products are then summed to form the initial score for a document.
 
virtual double sloppyFreq (int32_t distance)
 Computes the amount of a sloppy phrase match, based on an edit distance. This value is summed for each sloppy phrase match in a document to form the frequency that is passed to tf(double).
 
virtual double idf (int32_t docFreq, int32_t numDocs)
 Computes a score factor based on a term's document frequency (the number of documents which contain the term). This value is multiplied by the tf(int32_t) factor for each term in the query and these products are then summed to form the initial score for a document.
 
virtual double coord (int32_t overlap, int32_t maxOverlap)
 Computes a score factor based on the fraction of all query terms that a document contains. This value is multiplied into scores.
 
virtual double scorePayload (int32_t docId, const String &fieldName, int32_t start, int32_t end, ByteArray payload, int32_t offset, int32_t length)
 Calculate a scoring factor based on the data in the payload. Overriding implementations are responsible for interpreting what is in the payload. Lucene makes no assumptions about what is in the byte array.
 
- Public Member Functions inherited from Lucene::Similarity
 Similarity ()
 
virtual ~Similarity ()
 
boost::shared_ptr< Similarityshared_from_this ()
 
virtual double tf (int32_t freq)
 Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the idf(int32_t, int32_t) factor for each term in the query and these products are then summed to form the initial score for a document.
 
virtual IDFExplanationPtr idfExplain (const TermPtr &term, const SearcherPtr &searcher)
 Computes a score factor for a simple term and returns an explanation for that score factor.
 
virtual IDFExplanationPtr idfExplain (Collection< TermPtr > terms, const SearcherPtr &searcher)
 Computes a score factor for a phrase.
 
- 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::Similarity
static String _getClassName ()
 
static SimilarityPtr getDefault ()
 Return the default Similarity implementation used by indexing and search code. This is initially an instance of DefaultSimilarity.
 
static double decodeNorm (uint8_t b)
 Decodes a normalization factor stored in an index.
 
static const Collection< double > & getNormDecoder ()
 Returns a table for decoding normalization bytes.
 
static uint8_t encodeNorm (double f)
 Encodes a normalization factor for storage in an index.
 

Protected Attributes

SimilarityPtr delegee
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

Additional Inherited Members

- Static Public Attributes inherited from Lucene::Similarity
static const Collection< double > NORM_TABLE
 
- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 
- Static Protected Attributes inherited from Lucene::Similarity
static const int32_t NO_DOC_ID_PROVIDED
 

Detailed Description

Delegating scoring implementation. Useful in Query#getSimilarity(Searcher) implementations, to override only certain methods of a Searcher's Similarity implementation.

Constructor & Destructor Documentation

◆ SimilarityDelegator()

Lucene::SimilarityDelegator::SimilarityDelegator ( const SimilarityPtr delegee)

◆ ~SimilarityDelegator()

virtual Lucene::SimilarityDelegator::~SimilarityDelegator ( )
virtual

Member Function Documentation

◆ _getClassName()

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

◆ computeNorm()

virtual double Lucene::SimilarityDelegator::computeNorm ( const String &  fieldName,
const FieldInvertStatePtr state 
)
virtual

Compute the normalization value for a field, given the accumulated state of term processing for this field (see FieldInvertState).

Implementations should calculate a float value based on the field state and then return that value.

For backward compatibility this method by default calls lengthNorm(String, int32_t) passing FieldInvertState#getLength() as the second argument, and then multiplies this value by FieldInvertState#getBoost().

Parameters
fieldField name
stateCurrent processing state for this field
Returns
The calculated float norm

Reimplemented from Lucene::Similarity.

◆ coord()

virtual double Lucene::SimilarityDelegator::coord ( int32_t  overlap,
int32_t  maxOverlap 
)
virtual

Computes a score factor based on the fraction of all query terms that a document contains. This value is multiplied into scores.

The presence of a large portion of the query terms indicates a better match with the query, so implementations of this method usually return larger values when the ratio between these parameters is large and smaller values when the ratio between them is small.

Parameters
overlapThe number of query terms matched in the document
maxOverlapThe total number of terms in the query
Returns
A score factor based on term overlap with the query

Implements Lucene::Similarity.

◆ getClassName()

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

Reimplemented from Lucene::Similarity.

◆ idf()

virtual double Lucene::SimilarityDelegator::idf ( int32_t  docFreq,
int32_t  numDocs 
)
virtual

Computes a score factor based on a term's document frequency (the number of documents which contain the term). This value is multiplied by the tf(int32_t) factor for each term in the query and these products are then summed to form the initial score for a document.

Terms that occur in fewer documents are better indicators of topic, so implementations of this method usually return larger values for rare terms, and smaller values for common terms.

Parameters
docFreqThe number of documents which contain the term
numDocsThe total number of documents in the collection
Returns
A score factor based on the term's document frequency

Implements Lucene::Similarity.

◆ lengthNorm()

virtual double Lucene::SimilarityDelegator::lengthNorm ( const String &  fieldName,
int32_t  numTokens 
)
virtual

Computes the normalization value for a field given the total number of terms contained in a field. These values, together with field boosts, are stored in an index and multiplied into scores for hits on each field by the search code.

Matches in longer fields are less precise, so implementations of this method usually return smaller values when numTokens is large, and larger values when numTokens is small.

Note that the return values are computed under IndexWriter#addDocument(DocumentPtr) and then stored using encodeNorm(double). Thus they have limited precision, and documents must be re-indexed if this method is altered.

Parameters
fieldNameThe name of the field
numTokensThe total number of tokens contained in fields named fieldName of doc.
Returns
A normalization factor for hits on this field of this document
See also
Field::setBoost(double)

Implements Lucene::Similarity.

◆ queryNorm()

virtual double Lucene::SimilarityDelegator::queryNorm ( double  sumOfSquaredWeights)
virtual

Computes the normalization value for a query given the sum of the squared weights of each of the query terms. This value is multiplied into the weight of each query term. While the classic query normalization factor is computed as 1/sqrt(sumOfSquaredWeights), other implementations might completely ignore sumOfSquaredWeights (ie return 1).

This does not affect ranking, but the default implementation does make scores from different queries more comparable than they would be by eliminating the magnitude of the Query vector as a factor in the score.

Parameters
sumOfSquaredWeightsThe sum of the squares of query term weights
Returns
a normalization factor for query weights

Implements Lucene::Similarity.

◆ scorePayload()

virtual double Lucene::SimilarityDelegator::scorePayload ( int32_t  docId,
const String &  fieldName,
int32_t  start,
int32_t  end,
ByteArray  payload,
int32_t  offset,
int32_t  length 
)
virtual

Calculate a scoring factor based on the data in the payload. Overriding implementations are responsible for interpreting what is in the payload. Lucene makes no assumptions about what is in the byte array.

The default implementation returns 1.

Parameters
docIdThe docId currently being scored. If this value is NO_DOC_ID_PROVIDED, then it should be assumed that the PayloadQuery implementation does not provide document information
fieldNameThe fieldName of the term this payload belongs to
startThe start position of the payload
endThe end position of the payload
payloadThe payload byte array to be scored
offsetThe offset into the payload array
lengthThe length in the array
Returns
An implementation dependent float to be used as a scoring factor

Reimplemented from Lucene::Similarity.

◆ shared_from_this()

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

◆ sloppyFreq()

virtual double Lucene::SimilarityDelegator::sloppyFreq ( int32_t  distance)
virtual

Computes the amount of a sloppy phrase match, based on an edit distance. This value is summed for each sloppy phrase match in a document to form the frequency that is passed to tf(double).

A phrase match with a small edit distance to a document passage more closely matches the document, so implementations of this method usually return larger values when the edit distance is small and smaller values when it is large.

See also
PhraseQuery::setSlop(int32_t)
Parameters
distanceThe edit distance of this sloppy phrase match
Returns
The frequency increment for this match

Implements Lucene::Similarity.

◆ tf()

virtual double Lucene::SimilarityDelegator::tf ( double  freq)
virtual

Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the idf(int32_t, int32_t) factor for each term in the query and these products are then summed to form the initial score for a document.

Terms and phrases repeated in a document indicate the topic of the document, so implementations of this method usually return larger values when freq is large, and smaller values when freq is small.

Parameters
freqThe frequency of a term within a document
Returns
A score factor based on a term's within-document frequency

Implements Lucene::Similarity.

Field Documentation

◆ delegee

SimilarityPtr Lucene::SimilarityDelegator::delegee
protected

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

clucene.sourceforge.net