Class DefaultSimilarity
Expert: Default scoring implementation which encodes (EncodeNormValue(float))
norm values as a single byte before being stored. At search time,
the norm byte value is read from the index
Directory and
decoded (DecodeNormValue(long)) back to a float norm value.
this encoding/decoding, while reducing index size, comes with the price of
precision loss - it is not guaranteed that Decode(Encode(x)) = x. For
instance, Decode(Encode(0.89)) = 0.75.
Compression of norm values to a single byte saves memory at search time,
because once a field is referenced at search time, its norms - for all
documents - are maintained in memory.
The rationale supporting such lossy compression of norm values is that given
the difficulty (and inaccuracy) of users to express their true information
need by a query, only big differences matter.
Last, note that search time is too late to modify this
norm part of
scoring, e.g. by using a different
Similarity for search.
Inheritance
DefaultSimilarity
Assembly: Lucene.Net.dll
Syntax
public class DefaultSimilarity : TFIDFSimilarity
Constructors
DefaultSimilarity()
Sole constructor: parameter-free
Declaration
public DefaultSimilarity()
Fields
m_discountOverlaps
True
if overlap tokens (tokens with a position of increment of zero) are
discounted from the document's length.
Declaration
protected bool m_discountOverlaps
Field Value
Properties
DiscountOverlaps
Determines whether overlap tokens (Tokens with
0 position increment) are ignored when computing
norm. By default this is true, meaning overlap
tokens do not count when computing norms.
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public virtual bool DiscountOverlaps { get; set; }
Property Value
See Also
Methods
Coord(int, int)
Implemented as overlap / maxOverlap
.
Declaration
public override float Coord(int overlap, int maxOverlap)
Parameters
Type |
Name |
Description |
int |
overlap |
|
int |
maxOverlap |
|
Returns
Overrides
DecodeNormValue(long)
Decodes the norm value, assuming it is a single byte.
Declaration
public override sealed float DecodeNormValue(long norm)
Parameters
Type |
Name |
Description |
long |
norm |
|
Returns
Overrides
See Also
EncodeNormValue(float)
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.
Declaration
public override sealed long EncodeNormValue(float f)
Parameters
Type |
Name |
Description |
float |
f |
|
Returns
Overrides
See Also
Idf(long, long)
Implemented as log(numDocs/(docFreq+1)) + 1
.
Declaration
public override float Idf(long docFreq, long numDocs)
Parameters
Type |
Name |
Description |
long |
docFreq |
|
long |
numDocs |
|
Returns
Overrides
LengthNorm(FieldInvertState)
Implemented as
state.Boost * LengthNorm(numTerms)
, where
numTerms
is Length if
DiscountOverlaps is false
, else it's
Length -
NumOverlap.
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public override float LengthNorm(FieldInvertState state)
Parameters
Returns
Overrides
QueryNorm(float)
Implemented as 1/sqrt(sumOfSquaredWeights)
.
Declaration
public override float QueryNorm(float sumOfSquaredWeights)
Parameters
Type |
Name |
Description |
float |
sumOfSquaredWeights |
|
Returns
Overrides
ScorePayload(int, int, int, BytesRef)
The default implementation returns 1
Declaration
public override float ScorePayload(int doc, int start, int end, BytesRef payload)
Parameters
Returns
Overrides
SloppyFreq(int)
Implemented as 1 / (distance + 1)
.
Declaration
public override float SloppyFreq(int distance)
Parameters
Type |
Name |
Description |
int |
distance |
|
Returns
Overrides
Tf(float)
Implemented as Math.Sqrt(freq)
.
Declaration
public override float Tf(float freq)
Parameters
Type |
Name |
Description |
float |
freq |
|
Returns
Overrides
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type |
Description |
string |
A string that represents the current object.
|
Overrides