Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Properties | List of all members
Lucene.Net.Search.Similarity Class Referenceabstract

Expert: Scoring API. Subclasses implement search scoring. More...

Inherited by Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

Public Member Functions

virtual float ComputeNorm (System.String field, FieldInvertState state)
 Compute the normalization value for a field, given the accumulated state of term processing for this field (see FieldInvertState).
 
abstract float LengthNorm (System.String fieldName, int 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 multipled into scores for hits on each field by the search code.
 
abstract float QueryNorm (float sumOfSquaredWeights)
 Computes the normalization value for a query given the sum of the squared weights of each of the query terms. This value is then multipled into the weight of each query term.
 
virtual float Tf (int freq)
 Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the Idf(int, int) factor for each term in the query and these products are then summed to form the initial score for a document.
 
abstract float SloppyFreq (int 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(float).
 
abstract float Tf (float freq)
 Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the Idf(int, int) factor for each term in the query and these products are then summed to form the initial score for a document.
 
virtual IDFExplanation IdfExplain (Term term, Searcher searcher)
 Computes a score factor for a simple term and returns an explanation for that score factor.
 
virtual IDFExplanation IdfExplain (ICollection< Term > terms, Searcher searcher)
 Computes a score factor for a phrase.
 
abstract float Idf (int docFreq, int 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(int) factor for each term in the query and these products are then summed to form the initial score for a document.
 
abstract float Coord (int overlap, int maxOverlap)
 Computes a score factor based on the fraction of all query terms that a document contains. This value is multiplied into scores.
 
virtual float ScorePayload (int docId, System.String fieldName, int start, int end, byte[] payload, int offset, int 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. The default implementation returns 1.
 

Static Public Member Functions

static float DecodeNorm (byte b)
 Decodes a normalization factor stored in an index.
 
static float[] GetNormDecoder ()
 Returns a table for decoding normalization bytes.
 
static byte EncodeNorm (float f)
 Encodes a normalization factor for storage in an index.
 

Public Attributes

const int NO_DOC_ID_PROVIDED = - 1
 

Protected Member Functions

 Similarity ()
 

Properties

static Similarity Default [get, set]
 Gets or sets the default Similarity implementation used by indexing and search code. This is initially an instance of DefaultSimilarity.
 

Detailed Description

Expert: Scoring API.

Subclasses implement search scoring.

The score of query q for document d correlates to the cosine-distance or dot-product between document and query vectors in a Vector Space Model (VSM) of Information Retrieval. A document whose vector is closer to the query vector in that model is scored higher.

The score is computed as follows:

score(q,d) &#160; = &#160; coord(q,d) &#160;&#183;&#160; queryNorm(q) &#160;&#183;&#160; <big><big><big>&#8721;</big></big></big> <big><big>(</big></big> tf(t in d) &#160;&#183;&#160; idf(t)2 &#160;&#183;&#160; t.Boost&#160;&#183;&#160; norm(t,d) <big><big>)</big></big>
t in q

where

See Also
Default
See Also
Lucene.Net.Index.IndexWriter.Similarity
See Also
Searcher.Similarity

Definition at line 293 of file Similarity.cs.

Constructor & Destructor Documentation

Lucene.Net.Search.Similarity.Similarity ( )
protected

Definition at line 295 of file Similarity.cs.

Member Function Documentation

virtual float Lucene.Net.Search.Similarity.ComputeNorm ( System.String  field,
FieldInvertState  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, int) passing FieldInvertState.Length as the second argument, and then multiplies this value by FieldInvertState.Boost.

WARNING: This API is new and experimental and may suddenly change.

Parameters
fieldfield name
statecurrent processing state for this field
Returns
the calculated float norm

Reimplemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

Definition at line 437 of file Similarity.cs.

abstract float Lucene.Net.Search.Similarity.Coord ( int  overlap,
int  maxOverlap 
)
pure 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

Implemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

static float Lucene.Net.Search.Similarity.DecodeNorm ( byte  b)
static

Decodes a normalization factor stored in an index.

See Also
EncodeNorm(float)

Definition at line 403 of file Similarity.cs.

static byte Lucene.Net.Search.Similarity.EncodeNorm ( float  f)
static

Encodes a normalization factor for storage in an index.

The encoding uses a three-bit mantissa, a five-bit exponent, and the zero-exponent point at 15, thus representing values from around 7x10^9 to 2x10^-9 with about one significant decimal digit of accuracy. Zero is also represented. Negative numbers are rounded up to zero. Values too large to represent are rounded down to the largest representable value. Positive values too small to represent are rounded up to the smallest positive representable value.

See Also
Lucene.Net.Documents.AbstractField.Boost, Lucene.Net.Util.SmallFloat

Definition at line 498 of file Similarity.cs.

static float [] Lucene.Net.Search.Similarity.GetNormDecoder ( )
static

Returns a table for decoding normalization bytes.

See Also
EncodeNorm(float)

Definition at line 411 of file Similarity.cs.

abstract float Lucene.Net.Search.Similarity.Idf ( int  docFreq,
int  numDocs 
)
pure 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(int) 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

Implemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

virtual IDFExplanation Lucene.Net.Search.Similarity.IdfExplain ( Term  term,
Searcher  searcher 
)
virtual

Computes a score factor for a simple term and returns an explanation for that score factor.

The default implementation uses:

idf(searcher.docFreq(term), searcher.MaxDoc);

Note that Searcher.MaxDoc is used instead of Lucene.Net.Index.IndexReader.NumDocs() because it is proportional to Searcher.DocFreq(Term) , i.e., when one is inaccurate, so is the other, and in the same direction.

Parameters
termthe term in question
searcherthe document collection being searched
Returns
an IDFExplain object that includes both an idf score factor and an explanation for the term.

<throws> IOException </throws>

Definition at line 582 of file Similarity.cs.

virtual IDFExplanation Lucene.Net.Search.Similarity.IdfExplain ( ICollection< Term terms,
Searcher  searcher 
)
virtual

Computes a score factor for a phrase.

The default implementation sums the idf factor for each term in the phrase.

Parameters
termsthe terms in the phrase
searcherthe document collection being searched
Returns
an IDFExplain object that includes both an idf score factor for the phrase and an explanation for each term.

<throws> IOException </throws>

Definition at line 606 of file Similarity.cs.

abstract float Lucene.Net.Search.Similarity.LengthNorm ( System.String  fieldName,
int  numTokens 
)
pure 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 multipled 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 Lucene.Net.Index.IndexWriter.AddDocument(Lucene.Net.Documents.Document) and then stored using EncodeNorm(float). 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
Lucene.Net.Documents.AbstractField.Boost

Implemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

abstract float Lucene.Net.Search.Similarity.QueryNorm ( float  sumOfSquaredWeights)
pure virtual

Computes the normalization value for a query given the sum of the squared weights of each of the query terms. This value is then multipled into the weight of each query term.

This does not affect ranking, but rather just attempts to make scores from different queries comparable.

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

Implemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

virtual float Lucene.Net.Search.Similarity.ScorePayload ( int  docId,
System.String  fieldName,
int  start,
int  end,
byte[]  payload,
int  offset,
int  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

Definition at line 684 of file Similarity.cs.

abstract float Lucene.Net.Search.Similarity.SloppyFreq ( int  distance)
pure 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(float).

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.Slop
Parameters
distancethe edit distance of this sloppy phrase match
Returns
the frequency increment for this match

Implemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

virtual float Lucene.Net.Search.Similarity.Tf ( int  freq)
virtual

Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the Idf(int, int) 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.

The default implementation calls Tf(float).

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

Definition at line 521 of file Similarity.cs.

abstract float Lucene.Net.Search.Similarity.Tf ( float  freq)
pure virtual

Computes a score factor based on a term or phrase's frequency in a document. This value is multiplied by the Idf(int, int) 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

Implemented in Lucene.Net.Search.DefaultSimilarity, and Lucene.Net.Search.SimilarityDelegator.

Member Data Documentation

const int Lucene.Net.Search.Similarity.NO_DOC_ID_PROVIDED = - 1

Definition at line 381 of file Similarity.cs.

Property Documentation

Similarity Lucene.Net.Search.Similarity.Default
staticgetset

Gets or sets the default Similarity implementation used by indexing and search code. This is initially an instance of DefaultSimilarity.

See Also
Searcher.Similarity
See Also
Lucene.Net.Index.IndexWriter.SetSimilarity(Similarity)

Definition at line 392 of file Similarity.cs.


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