Class Weight
Expert: Calculate query weights and build query scorers.
The purpose of Weight is to ensure searching does not modify a Query, so that a Query instance can be reused.
IndexSearcher dependent state of the query should reside in the Weight.
AtomicReader dependent state should reside in the Scorer.
Since Weight creates Scorer instances for a given AtomicReaderContext (GetScorer(AtomicReaderContext, IBits)) callers must maintain the relationship between the searcher's top-level IndexReaderContext and the context used to create a Scorer.
A Weight is used in the following way:
- A Weight is constructed by a top-level query, given a IndexSearcher (CreateWeight(IndexSearcher)).
- The GetValueForNormalization() method is called on the Weight to compute the query normalization factor QueryNorm(Single) of the query clauses contained in the query.
- The query normalization factor is passed to Normalize(Single, Single). At this point the weighting is complete.
- A Scorer is constructed by GetScorer(AtomicReaderContext, IBits).
@since 2.9
Inheritance
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public abstract class Weight : object
Properties
| Improve this Doc View SourceQuery
The query that this concerns.
Declaration
public abstract Query Query { get; }
Property Value
Type | Description |
---|---|
Query |
ScoresDocsOutOfOrder
Returns true if this implementation scores docs only out of order. This method is used in conjunction with ICollector's AcceptsDocsOutOfOrder and GetBulkScorer(AtomicReaderContext, Boolean, IBits) to create a matching Scorer instance for a given ICollector, or vice versa.
NOTE: the default implementation returns false
, i.e.
the Scorer scores documents in-order.
Declaration
public virtual bool ScoresDocsOutOfOrder { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceExplain(AtomicReaderContext, Int32)
An explanation of the score computation for the named document.
Declaration
public abstract Explanation Explain(AtomicReaderContext context, int doc)
Parameters
Type | Name | Description |
---|---|---|
AtomicReaderContext | context | The readers context to create the Explanation for. |
System.Int32 | doc | The document's id relative to the given context's reader |
Returns
Type | Description |
---|---|
Explanation | An Explanation for the score |
GetBulkScorer(AtomicReaderContext, Boolean, IBits)
Optional method, to return a BulkScorer to score the query and send hits to a ICollector. Only queries that have a different top-level approach need to override this; the default implementation pulls a normal Scorer and iterates and collects the resulting hits.
Declaration
public virtual BulkScorer GetBulkScorer(AtomicReaderContext context, bool scoreDocsInOrder, IBits acceptDocs)
Parameters
Type | Name | Description |
---|---|---|
AtomicReaderContext | context | The AtomicReaderContext for which to return the Scorer. |
System.Boolean | scoreDocsInOrder | Specifies whether in-order scoring of documents is required. Note
that if set to |
IBits | acceptDocs | IBits that represent the allowable docs to match (typically deleted docs but possibly filtering other documents) |
Returns
Type | Description |
---|---|
BulkScorer | A BulkScorer which scores documents and passes them to a collector. |
GetScorer(AtomicReaderContext, IBits)
Returns a Scorer which scores documents in/out-of order according
to scoreDocsInOrder
.
NOTE: even if scoreDocsInOrder
is false
, it is
recommended to check whether the returned Scorer indeed scores
documents out of order (i.e., call ScoresDocsOutOfOrder), as
some Scorer implementations will always return documents
in-order.
NOTE: null
can be returned if no documents will be scored by this
query.
Declaration
public abstract Scorer GetScorer(AtomicReaderContext context, IBits acceptDocs)
Parameters
Type | Name | Description |
---|---|---|
AtomicReaderContext | context | The AtomicReaderContext for which to return the Scorer. |
IBits | acceptDocs | IBits that represent the allowable docs to match (typically deleted docs but possibly filtering other documents) |
Returns
Type | Description |
---|---|
Scorer | A Scorer which scores documents in/out-of order. |
GetValueForNormalization()
The value for normalization of contained query clauses (e.g. sum of squared weights).
Declaration
public abstract float GetValueForNormalization()
Returns
Type | Description |
---|---|
System.Single |
Normalize(Single, Single)
Assigns the query normalization factor and boost from parent queries to this.
Declaration
public abstract void Normalize(float norm, float topLevelBoost)
Parameters
Type | Name | Description |
---|---|---|
System.Single | norm | |
System.Single | topLevelBoost |