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

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

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< SimilarityDelegator > | shared_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). More...
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. More...
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). More...
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. More...
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). More...
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. More...
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. More...
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. More...
Public Member Functions inherited from Lucene::Similarity
| Similarity ()
virtual | ~Similarity ()
boost::shared_ptr< Similarity > | shared_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. More...
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. More...
virtual IDFExplanationPtr | idfExplain (Collection< TermPtr > terms, const SearcherPtr &searcher)
| Computes a score factor for a phrase. More...
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::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. More...
static double | decodeNorm (uint8_t b)
| Decodes a normalization factor stored in an index. More...
static const Collection< double > | getNormDecoder ()
| Returns a table for decoding normalization bytes. More...
static uint8_t | encodeNorm (double f)
| Encodes a normalization factor for storage in an index. More...

## Protected Attributes

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

## Additional Inherited Members

Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()
Static Protected Member Functions inherited from Lucene::Similarity
static const Collection< double > | NORM_TABLE ()
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

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

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

virtual

## Member Function Documentation

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

inline static

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

  field | Field name
  state | Current processing state for this field

Returns
  The calculated float norm

Reimplemented from Lucene::Similarity.

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

  overlap | The number of query terms matched in the document
  maxOverlap | The total number of terms in the query

Returns
  A score factor based on term overlap with the query

Implements Lucene::Similarity.

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

inline virtual

Reimplemented from Lucene::Similarity.

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

  docFreq | The number of documents which contain the term
  numDocs | The total number of documents in the collection

Returns
  A score factor based on the term's document frequency

Implements Lucene::Similarity.

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

  fieldName | The name of the field
  numTokens | The 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.

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

  sumOfSquaredWeights | The sum of the squares of query term weights

Returns
  a normalization factor for query weights

Implements Lucene::Similarity.

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

  docId | The 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
  fieldName | The fieldName of the term this payload belongs to
  start | The start position of the payload
  end | The end position of the payload
  payload | The payload byte array to be scored
  offset | The offset into the payload array
  length | The length in the array

Returns
  An implementation dependent float to be used as a scoring factor

Reimplemented from Lucene::Similarity.

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

inline

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

  distance | The edit distance of this sloppy phrase match

Returns
  The frequency increment for this match

Implements Lucene::Similarity.

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

  freq | The frequency of a term within a document

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

Implements Lucene::Similarity.

## Field Documentation

SimilarityPtr Lucene::SimilarityDelegator::delegee

protected

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

- SimilarityDelegator.h

clucene.sourceforge.net