Class SimilarityBase
A subclass of Similarity that provides a simplified API for its descendants. Subclasses are only required to implement the Score(BasicStats, Single, Single) and ToString() methods. Implementing Explain(Explanation, BasicStats, Int32, Single, Single) is optional, inasmuch as SimilarityBase already provides a basic explanation of the score and the term frequency. However, implementers of a subclass are encouraged to include as much detail about the scoring method as possible.
Note: multi-word queries such as phrase queries are scored in a different way than Lucene's default ranking algorithm: whereas it "fakes" an IDF value for the phrase as a whole (since it does not know it), this class instead scores phrases as a summation of the individual term scores.
Note
This API is experimental and might change in incompatible ways in the next release.
Inherited Members
Namespace: Lucene.Net.Search.Similarities
Assembly: Lucene.Net.dll
Syntax
public abstract class SimilarityBase : Similarity
Constructors
| Improve this Doc View SourceSimilarityBase()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
Declaration
protected SimilarityBase()
Properties
| Improve this Doc View SourceDiscountOverlaps
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
Type | Description |
---|---|
System.Boolean |
See Also
Methods
| Improve this Doc View SourceComputeNorm(FieldInvertState)
Encodes the document length in the same way as TFIDFSimilarity.
Declaration
public override long ComputeNorm(FieldInvertState state)
Parameters
Type | Name | Description |
---|---|---|
FieldInvertState | state |
Returns
Type | Description |
---|---|
System.Int64 |
Overrides
| Improve this Doc View SourceComputeWeight(Single, CollectionStatistics, TermStatistics[])
Declaration
public sealed override Similarity.SimWeight ComputeWeight(float queryBoost, CollectionStatistics collectionStats, params TermStatistics[] termStats)
Parameters
Type | Name | Description |
---|---|---|
System.Single | queryBoost | |
CollectionStatistics | collectionStats | |
TermStatistics[] | termStats |
Returns
Type | Description |
---|---|
Similarity.SimWeight |
Overrides
| Improve this Doc View SourceDecodeNormValue(Byte)
Decodes a normalization factor (document length) stored in an index.
Declaration
protected virtual float DecodeNormValue(byte norm)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | norm |
Returns
Type | Description |
---|---|
System.Single |
EncodeNormValue(Single, Single)
Encodes the length to a byte via SmallSingle.
Declaration
protected virtual byte EncodeNormValue(float boost, float length)
Parameters
Type | Name | Description |
---|---|---|
System.Single | boost | |
System.Single | length |
Returns
Type | Description |
---|---|
System.Byte |
Explain(Explanation, BasicStats, Int32, Single, Single)
Subclasses should implement this method to explain the score. expl
already contains the score, the name of the class and the doc id, as well
as the term frequency and its explanation; subclasses can add additional
clauses to explain details of their scoring formulae.
The default implementation does nothing.
Declaration
protected virtual void Explain(Explanation expl, BasicStats stats, int doc, float freq, float docLen)
Parameters
Type | Name | Description |
---|---|---|
Explanation | expl | the explanation to extend with details. |
BasicStats | stats | the corpus level statistics. |
System.Int32 | doc | the document id. |
System.Single | freq | the term frequency. |
System.Single | docLen | the document length. |
Explain(BasicStats, Int32, Explanation, Single)
Explains the score. The implementation here provides a basic explanation in the format Score(name-of-similarity, doc=doc-id, freq=term-frequency), computed from:, and attaches the score (computed via the Score(BasicStats, Single, Single) method) and the explanation for the term frequency. Subclasses content with this format may add additional details in Explain(Explanation, BasicStats, Int32, Single, Single).
Declaration
public virtual Explanation Explain(BasicStats stats, int doc, Explanation freq, float docLen)
Parameters
Type | Name | Description |
---|---|---|
BasicStats | stats | the corpus level statistics. |
System.Int32 | doc | the document id. |
Explanation | freq | the term frequency and its explanation. |
System.Single | docLen | the document length. |
Returns
Type | Description |
---|---|
Explanation | the explanation. |
FillBasicStats(BasicStats, CollectionStatistics, TermStatistics)
Fills all member fields defined in BasicStats in stats
.
Subclasses can override this method to fill additional stats.
Declaration
protected virtual void FillBasicStats(BasicStats stats, CollectionStatistics collectionStats, TermStatistics termStats)
Parameters
Type | Name | Description |
---|---|---|
BasicStats | stats | |
CollectionStatistics | collectionStats | |
TermStatistics | termStats |
GetSimScorer(Similarity.SimWeight, AtomicReaderContext)
Declaration
public override Similarity.SimScorer GetSimScorer(Similarity.SimWeight stats, AtomicReaderContext context)
Parameters
Type | Name | Description |
---|---|---|
Similarity.SimWeight | stats | |
AtomicReaderContext | context |
Returns
Type | Description |
---|---|
Similarity.SimScorer |
Overrides
| Improve this Doc View SourceLog2(Double)
Returns the base two logarithm of x
.
Declaration
public static double Log2(double x)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x |
Returns
Type | Description |
---|---|
System.Double |
NewStats(String, Single)
Factory method to return a custom stats object
Declaration
protected virtual BasicStats NewStats(string field, float queryBoost)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.Single | queryBoost |
Returns
Type | Description |
---|---|
BasicStats |
Score(BasicStats, Single, Single)
Scores the document doc
.
Subclasses must apply their scoring formula in this class.
Declaration
public abstract float Score(BasicStats stats, float freq, float docLen)
Parameters
Type | Name | Description |
---|---|---|
BasicStats | stats | the corpus level statistics. |
System.Single | freq | the term frequency. |
System.Single | docLen | the document length. |
Returns
Type | Description |
---|---|
System.Single | the score. |
ToString()
Subclasses must override this method to return the name of the Similarity and preferably the values of parameters (if any) as well.
Declaration
public abstract override string ToString()
Returns
Type | Description |
---|---|
System.String |