search

package
v0.0.0-...-3a4838d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2021 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const BUCKET_TABLE_MASK = BUCKET_TABLE_SIZE - 1
View Source
const BUCKET_TABLE_SIZE = 1 << 11
View Source
const PROHIBITED_MASK = 1

Any time a prohibited clause matches we set bit 0:

Variables

View Source
var (
	MUST     = Occur(1)
	SHOULD   = Occur(2)
	MUST_NOT = Occur(3)
)
View Source
var NORM_TABLE []float32 = buildNormTable()

* Cache of decoded bytes.

Functions

This section is empty.

Types

type AbstractQuery

type AbstractQuery struct {
	// contains filtered or unexported fields
}

func NewAbstractQuery

func NewAbstractQuery(self interface{}) *AbstractQuery

func (*AbstractQuery) Boost

func (q *AbstractQuery) Boost() float32

func (*AbstractQuery) CreateWeight

func (q *AbstractQuery) CreateWeight(ss *IndexSearcher) (w Weight, err error)

func (*AbstractQuery) Rewrite

func (q *AbstractQuery) Rewrite(r index.IndexReader) Query

func (*AbstractQuery) SetBoost

func (q *AbstractQuery) SetBoost(b float32)

func (*AbstractQuery) String

func (q *AbstractQuery) String() string

type BooleanClause

type BooleanClause struct {
	// contains filtered or unexported fields
}

func NewBooleanClause

func NewBooleanClause(query Query, occur Occur) *BooleanClause

func (*BooleanClause) IsProhibited

func (c *BooleanClause) IsProhibited() bool

func (*BooleanClause) IsRequired

func (c *BooleanClause) IsRequired() bool

type BooleanQuery

type BooleanQuery struct {
	*AbstractQuery
	// contains filtered or unexported fields
}

func NewBooleanQuery

func NewBooleanQuery() *BooleanQuery

func NewBooleanQueryDisableCoord

func NewBooleanQueryDisableCoord(disableCoord bool) *BooleanQuery

func (*BooleanQuery) Add

func (q *BooleanQuery) Add(query Query, occur Occur)

func (*BooleanQuery) AddClause

func (q *BooleanQuery) AddClause(clause *BooleanClause)

func (*BooleanQuery) CreateWeight

func (q *BooleanQuery) CreateWeight(searcher *IndexSearcher) (Weight, error)

func (*BooleanQuery) Rewrite

func (q *BooleanQuery) Rewrite(reader index.IndexReader) Query

func (*BooleanQuery) ToString

func (q *BooleanQuery) ToString(field string) string

type BooleanScorer

type BooleanScorer struct {
	*BulkScorerImpl
	// contains filtered or unexported fields
}

func (*BooleanScorer) ScoreAndCollectUpto

func (s *BooleanScorer) ScoreAndCollectUpto(collector Collector, max int) (more bool, err error)

func (*BooleanScorer) String

func (s *BooleanScorer) String() string

type BooleanScorerCollector

type BooleanScorerCollector struct {
	// contains filtered or unexported fields
}

func (*BooleanScorerCollector) AcceptsDocsOutOfOrder

func (c *BooleanScorerCollector) AcceptsDocsOutOfOrder() bool

func (*BooleanScorerCollector) Collect

func (c *BooleanScorerCollector) Collect(doc int) (err error)

func (*BooleanScorerCollector) SetNextReader

func (*BooleanScorerCollector) SetScorer

func (c *BooleanScorerCollector) SetScorer(scorer Scorer)

type BooleanWeight

type BooleanWeight struct {
	// contains filtered or unexported fields
}

func (*BooleanWeight) BulkScorer

func (w *BooleanWeight) BulkScorer(context *index.AtomicReaderContext,
	scoreDocsInOrder bool, acceptDocs util.Bits) (BulkScorer, error)

func (*BooleanWeight) Explain

func (w *BooleanWeight) Explain(context *index.AtomicReaderContext, doc int) (Explanation, error)

func (*BooleanWeight) IsScoresDocsOutOfOrder

func (w *BooleanWeight) IsScoresDocsOutOfOrder() bool

func (*BooleanWeight) Normalize

func (w *BooleanWeight) Normalize(norm, topLevelBoost float32)

func (*BooleanWeight) ValueForNormalization

func (w *BooleanWeight) ValueForNormalization() (sum float32)

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

type BucketTable

type BucketTable struct {
	// contains filtered or unexported fields
}

type BulkScorer

type BulkScorer interface {
	ScoreAndCollect(Collector) error
	BulkScorerImplSPI
}

This class is used to score a range of documents at once, and is returned by Weight.BulkScorer(). Only queries that have a more optimized means of scoring across a range of documents need to override this. Otherwise, a default implementation is wrapped around the Scorer returned by Weight.Scorer().

type BulkScorerImpl

type BulkScorerImpl struct {
	// contains filtered or unexported fields
}

func (*BulkScorerImpl) ScoreAndCollect

func (bs *BulkScorerImpl) ScoreAndCollect(collector Collector) (err error)

type BulkScorerImplSPI

type BulkScorerImplSPI interface {
	ScoreAndCollectUpto(Collector, int) (bool, error)
}

type CollectionStatistics

type CollectionStatistics struct {
	// contains filtered or unexported fields
}

func NewCollectionStatistics

func NewCollectionStatistics(field string, maxDoc, docCount, sumTotalTermFreq, sumDocFreq int64) CollectionStatistics

type Collector

type Collector interface {
	SetScorer(s Scorer)
	Collect(doc int) error
	SetNextReader(ctx *index.AtomicReaderContext)
	AcceptsDocsOutOfOrder() bool
}

type ComplexExplanation

type ComplexExplanation struct {
	*ExplanationImpl
	// contains filtered or unexported fields
}

Expert: Describes the score computation for the doucment and query, and can distinguish a match independent of a postive value.

func (*ComplexExplanation) IsMatch

func (e *ComplexExplanation) IsMatch() bool

Indicates whether or not this Explanation models a good match.

If the match status is explicitly set (i.e.: not nil) this method uses it; otherwise it defers to the superclass.

func (*ComplexExplanation) Summary

func (e *ComplexExplanation) Summary() string

type DefaultBulkScorer

type DefaultBulkScorer struct {
	*BulkScorerImpl
	// contains filtered or unexported fields
}

Just wraps a Scorer and performs top scoring using it.

func (*DefaultBulkScorer) ScoreAndCollectUpto

func (s *DefaultBulkScorer) ScoreAndCollectUpto(collector Collector, max int) (ok bool, err error)

type DefaultSimilarity

type DefaultSimilarity struct {
	*TFIDFSimilarity
	// contains filtered or unexported fields
}

func NewDefaultSimilarity

func NewDefaultSimilarity() *DefaultSimilarity

func (*DefaultSimilarity) Coord

func (ds *DefaultSimilarity) Coord(overlap, maxOverlap int) float32

func (*DefaultSimilarity) QueryNorm

func (ds *DefaultSimilarity) QueryNorm(sumOfSquaredWeights float32) float32

func (*DefaultSimilarity) String

func (ds *DefaultSimilarity) String() string

type Explanation

type Explanation interface {
	// Indicate whether or not this Explanation models a good match.
	// By default, an Explanation represents a "match" if the value is positive.
	IsMatch() bool
	// The value assigned to this explanation node.
	Value() float32
}

type ExplanationImpl

type ExplanationImpl struct {
	// contains filtered or unexported fields
}

Expert: Describes the score computation for document and query.

func (*ExplanationImpl) Description

func (exp *ExplanationImpl) Description() string

func (*ExplanationImpl) Details

func (exp *ExplanationImpl) Details() []Explanation

The sub-nodes of this explanation node.

func (*ExplanationImpl) IsMatch

func (exp *ExplanationImpl) IsMatch() bool

func (*ExplanationImpl) String

func (exp *ExplanationImpl) String() string

Render an explanation as text.

func (*ExplanationImpl) Summary

func (exp *ExplanationImpl) Summary() string

func (*ExplanationImpl) Value

func (exp *ExplanationImpl) Value() float32

type ExplanationSPI

type ExplanationSPI interface {
	Explanation
	// A short one line summary which should contian all high level information
	// about this Explanation, without the Details.
	Summary() string
	Details() []Explanation
}

type FakeScorer

type FakeScorer struct {
	// contains filtered or unexported fields
}

func (*FakeScorer) Advance

func (s *FakeScorer) Advance(int) (int, error)

func (*FakeScorer) DocId

func (s *FakeScorer) DocId() int

func (*FakeScorer) Freq

func (s *FakeScorer) Freq() (int, error)

func (*FakeScorer) NextDoc

func (s *FakeScorer) NextDoc() (int, error)

func (*FakeScorer) Score

func (s *FakeScorer) Score() (float32, error)

type Filter

type Filter interface {
}

type IScorer

type IScorer interface {
	Score() (float32, error)
}

type ITFIDFSimilarity

type ITFIDFSimilarity interface {
	// contains filtered or unexported methods
}

type InOrderTopScoreDocCollector

type InOrderTopScoreDocCollector struct {
	*TopScoreDocCollector
}

Assumes docs are scored in order.

func (*InOrderTopScoreDocCollector) AcceptsDocsOutOfOrder

func (c *InOrderTopScoreDocCollector) AcceptsDocsOutOfOrder() bool

func (*InOrderTopScoreDocCollector) Collect

func (c *InOrderTopScoreDocCollector) Collect(doc int) (err error)

func (InOrderTopScoreDocCollector) TopDocs

func (c InOrderTopScoreDocCollector) TopDocs() TopDocs

func (InOrderTopScoreDocCollector) TopDocsRange

func (c InOrderTopScoreDocCollector) TopDocsRange(start, howMany int) TopDocs

type IndexSearcher

type IndexSearcher struct {
	// contains filtered or unexported fields
}

IndexSearcher

func NewIndexSearcher

func NewIndexSearcher(r index.IndexReader) *IndexSearcher

func NewIndexSearcherFromContext

func NewIndexSearcherFromContext(context index.IndexReaderContext) *IndexSearcher

func (*IndexSearcher) CollectionStatistics

func (ss *IndexSearcher) CollectionStatistics(field string) CollectionStatistics

func (*IndexSearcher) CreateNormalizedWeight

func (ss *IndexSearcher) CreateNormalizedWeight(q Query) (w Weight, err error)

func (*IndexSearcher) Explain

func (ss *IndexSearcher) Explain(query Query, doc int) (exp Explanation, err error)

Returns an Explanation that describes how doc scored against query.

This is intended to be used in developing Similiarity implemenations, and, for good performance, should not be displayed with every hit. Computing an explanation is as expensive as executing the query over the entire index.

func (*IndexSearcher) Rewrite

func (ss *IndexSearcher) Rewrite(q Query) (Query, error)

func (*IndexSearcher) Search

func (ss *IndexSearcher) Search(q Query, f Filter, n int) (topDocs TopDocs, err error)

func (*IndexSearcher) SearchLWC

func (ss *IndexSearcher) SearchLWC(leaves []*index.AtomicReaderContext, w Weight, c Collector) (err error)

func (*IndexSearcher) SearchTop

func (ss *IndexSearcher) SearchTop(q Query, n int) (topDocs TopDocs, err error)

func (*IndexSearcher) SetSimilarity

func (ss *IndexSearcher) SetSimilarity(similarity Similarity)

Expert: set the similarity implementation used by this IndexSearcher.

func (*IndexSearcher) String

func (ss *IndexSearcher) String() string

func (*IndexSearcher) TermStatistics

func (ss *IndexSearcher) TermStatistics(term *index.Term, context *index.TermContext) TermStatistics

func (*IndexSearcher) TopReaderContext

func (ss *IndexSearcher) TopReaderContext() index.IndexReaderContext

Returns this searhcers the top-level IndexReaderContext

func (*IndexSearcher) WrapFilter

func (ss *IndexSearcher) WrapFilter(q Query, f Filter) Query

type IndexSearcherSPI

type IndexSearcherSPI interface {
	CreateNormalizedWeight(Query) (Weight, error)
	Rewrite(Query) (Query, error)
	WrapFilter(Query, Filter) Query
	SearchLWC([]*index.AtomicReaderContext, Weight, Collector) error
}

Define service that can be overrided

type Occur

type Occur int

func (Occur) String

func (occur Occur) String() string

type OutOfOrderTopScoreDocCollector

type OutOfOrderTopScoreDocCollector struct {
	*TopScoreDocCollector
}

func (*OutOfOrderTopScoreDocCollector) AcceptsDocsOutOfOrder

func (c *OutOfOrderTopScoreDocCollector) AcceptsDocsOutOfOrder() bool

func (*OutOfOrderTopScoreDocCollector) Collect

func (c *OutOfOrderTopScoreDocCollector) Collect(doc int) (err error)

func (OutOfOrderTopScoreDocCollector) TopDocs

func (c OutOfOrderTopScoreDocCollector) TopDocs() TopDocs

func (OutOfOrderTopScoreDocCollector) TopDocsRange

func (c OutOfOrderTopScoreDocCollector) TopDocsRange(start, howMany int) TopDocs

type PerFieldSimWeight

type PerFieldSimWeight struct {
	// contains filtered or unexported fields
}

func (*PerFieldSimWeight) Normalize

func (w *PerFieldSimWeight) Normalize(queryNorm, topLevelBoost float32)

func (*PerFieldSimWeight) ValueForNormalization

func (w *PerFieldSimWeight) ValueForNormalization() float32

type PerFieldSimilarityWrapper

type PerFieldSimilarityWrapper struct {
	// contains filtered or unexported fields
}

Provides the ability to use a different Similarity for different fields.

Subclasses should implement Get() to return an appropriate Similarity (for example, using field-specific parameter values) for the field.

func (*PerFieldSimilarityWrapper) ComputeNorm

func (wrapper *PerFieldSimilarityWrapper) ComputeNorm(state *index.FieldInvertState) int64

type PerFieldSimilarityWrapperSPI

type PerFieldSimilarityWrapperSPI interface {
	Get(name string) Similarity
}

type PriorityQueue

type PriorityQueue struct {
	// contains filtered or unexported fields
}

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

type Query

type Query interface {
	SetBoost(b float32)
	Boost() float32
	QuerySPI
	CreateWeight(ss *IndexSearcher) (w Weight, err error)
	Rewrite(r index.IndexReader) Query
}

The abstract base class for queries.

type QuerySPI

type QuerySPI interface {
	ToString(string) string
}

type ScoreDoc

type ScoreDoc struct {
	/** The score of this document for the query. */
	Score float32
	/** A hit document's number.
	 * @see IndexSearcher#doc(int) */
	Doc int
	// contains filtered or unexported fields
}

* Holds one hit in {@link TopDocs}.

func (*ScoreDoc) String

func (d *ScoreDoc) String() string

type Scorer

type Scorer interface {
	DocsEnum
	IScorer
}

type ScorerSPI

type ScorerSPI interface {
	DocId() int
	NextDoc() (int, error)
}

type SimScorer

type SimScorer interface {
	/**
	 * Score a single document
	 * @param doc document id within the inverted index segment
	 * @param freq sloppy term frequency
	 * @return document's score
	 */
	Score(doc int, freq float32) float32
	// contains filtered or unexported methods
}

*

  • API for scoring "sloppy" queries such as {@link TermQuery},
  • {@link SpanQuery}, and {@link PhraseQuery}.
  • <p>
  • Frequencies are floating-point values: an approximate
  • within-document frequency adjusted for "sloppiness" by
  • {@link SimScorer#computeSlopFactor(int)}.

type SimWeight

type SimWeight interface {
	ValueForNormalization() float32
	Normalize(norm float32, topLevelBoost float32)
}

type Similarity

type Similarity interface {
	Coord(int, int) float32
	// Computes the normalization value for a query given the sum of
	// the normalized weights SimWeight.ValueForNormalization of each
	// of the query terms. This value is passed back to the weight
	// (SimWeight.normalize()) of each query term, to provide a  hook
	// to attempt to make scores from different queries comparable.
	QueryNorm(valueForNormalization float32) float32
	/*
		Computes the normalization value for a field, given the
		accumulated state of term processing for this field (see
		FieldInvertState).

		Matches in longer fields are less precise, so implementations
		of this method usually set smaller values when state.Lenght() is
		larger, and larger values when state.Lenght() is smaller.
	*/
	ComputeNorm(state *index.FieldInvertState) int64
	// contains filtered or unexported methods
}

Similarity defines the components of Lucene scoring.

Expert: Scoring API.

This is a low-level API, you should only extend this API if you want to implement an information retrieval model. If you are instead looking for a convenient way to alter Lucene's scoring, consider extending a high-level implementation such as TFIDFSimilarity, which implements the vector space model with this API, or just tweaking the default implementation: DefaultSimilarity.

Similarity determines how Lucene weights terms, and Lucene interacts with this class at both index-time and query-time.

######Index-time

At indexing time, the indexer calls computeNorm(), allowing the Similarity implementation to set a per-document value for the field that will be later accessible via AtomicReader.NormValues(). Lucene makes no assumption about what is in this norm, but it is most useful for encoding length normalization information.

Implementations should carefully consider how the normalization is encoded: while Lucene's classical TFIDFSimilarity encodes a combination of index-time boost and length normalization information with SmallFLoat into a single byte, this might not be suitble for all purposes.

Many formulas require the use of average document length, which can be computed via a combination of CollectionStatistics.SumTotalTermFreq() and CollectionStatistics.MaxDoc() or CollectionStatistics.DocCount(), depending upon whether the average should reflect field sparsity.

Additional scoring factors can be stored in named NumericDocValuesFields and accessed at query-time with AtomicReader.NumericDocValues().

Finally, using index-time boosts (either via folding into the normalization byte or via DocValues), is an inefficient way to boost the scores of different fields if the boost will be the same for every document, instead the Similarity can simply take a constant boost parameter C, and PerFieldSimilarityWrapper can return different instances with different boosts depending upon field name.

######Query-time

At query-time, Quries interact with the Similarity via these steps:

1. The computeWeight() method is called a single time, allowing the implementation to compute any statistics (such as IDF, average document length, etc) across the entire collection. The TermStatistics and CollectionStatistics passed in already contain all of the raw statistics involved, so a Similarity can freely use any combination of statistics without causing any additional I/O. Lucene makes no assumption about what is stored in the returned SimWeight object. 2. The query normalization process occurs a single time: SimWeight.ValueForNormalization() is called for each query leaf node, queryNorm() is called for the top-level query, and finally SimWeight.Normalize() passes down the normalization value and any top-level boosts (e.g. from enclosing BooleanQuerys). 3. For each sgment in the index, the Query creates a SimScorer. The score() method is called for each matching document.

######Exlain-time When IndexSearcher.explain() is called, queries consult the Similarity's DocScorer for an explanation of how it computed its score. The query passes in a the document id and an explanation of how the frequency was computed.

type SubScorer

type SubScorer struct {
	// contains filtered or unexported fields
}

type TFIDFSimilarity

type TFIDFSimilarity struct {
	// contains filtered or unexported fields
}

func (*TFIDFSimilarity) ComputeNorm

func (ts *TFIDFSimilarity) ComputeNorm(state *index.FieldInvertState) int64

type TermQuery

type TermQuery struct {
	*AbstractQuery
	// contains filtered or unexported fields
}

func NewTermQuery

func NewTermQuery(t *index.Term) *TermQuery

func NewTermQueryWithDocFreq

func NewTermQueryWithDocFreq(t *index.Term, docFreq int) *TermQuery

func (*TermQuery) CreateWeight

func (q *TermQuery) CreateWeight(ss *IndexSearcher) (w Weight, err error)

func (*TermQuery) ToString

func (q *TermQuery) ToString(field string) string

type TermScorer

type TermScorer struct {
	// contains filtered or unexported fields
}

search/TermScorer.java * Expert: A <code>Scorer</code> for documents matching a <code>Term</code>.

func (*TermScorer) Advance

func (ts *TermScorer) Advance(target int) (int, error)

Advances to the first match beyond the current whose document number is greater than or equal to a given target.

func (*TermScorer) DocId

func (ts *TermScorer) DocId() int

func (*TermScorer) Freq

func (ts *TermScorer) Freq() (int, error)

func (*TermScorer) NextDoc

func (ts *TermScorer) NextDoc() (d int, err error)

*

  • Advances to the next document matching the query. <br> *
  • @return the document matching the query or NO_MORE_DOCS if there are no more documents.

func (*TermScorer) Score

func (ts *TermScorer) Score() (s float32, err error)

func (*TermScorer) String

func (ts *TermScorer) String() string

type TermStatistics

type TermStatistics struct {
	Term                   []byte
	DocFreq, TotalTermFreq int64
}

func NewTermStatistics

func NewTermStatistics(term []byte, docFreq, totalTermFreq int64) TermStatistics

type TermWeight

type TermWeight struct {
	*WeightImpl
	*TermQuery
	// contains filtered or unexported fields
}

func NewTermWeight

func NewTermWeight(owner *TermQuery, ss *IndexSearcher, termStates *index.TermContext) *TermWeight

func (*TermWeight) Explain

func (tw *TermWeight) Explain(ctx *index.AtomicReaderContext, doc int) (Explanation, error)

func (*TermWeight) IsScoresDocsOutOfOrder

func (tw *TermWeight) IsScoresDocsOutOfOrder() bool

func (*TermWeight) Normalize

func (tw *TermWeight) Normalize(norm float32, topLevelBoost float32)

func (*TermWeight) Scorer

func (tw *TermWeight) Scorer(context *index.AtomicReaderContext,
	acceptDocs util.Bits) (Scorer, error)

func (*TermWeight) String

func (tw *TermWeight) String() string

func (*TermWeight) ValueForNormalization

func (tw *TermWeight) ValueForNormalization() float32

type TopDocs

type TopDocs struct {
	TotalHits int
	ScoreDocs []*ScoreDoc
	// contains filtered or unexported fields
}

type TopDocsCollector

type TopDocsCollector interface {
	Collector
	/** Returns the top docs that were collected by this collector. */
	TopDocs() TopDocs
	/**
	 * Returns the documents in the rage [start .. start+howMany) that were
	 * collected by this collector. Note that if start >= pq.size(), an empty
	 * TopDocs is returned, and if pq.size() - start &lt; howMany, then only the
	 * available documents in [start .. pq.size()) are returned.<br>
	 * This method is useful to call in case pagination of search results is
	 * allowed by the search application, as well as it attempts to optimize the
	 * memory used by allocating only as much as requested by howMany.<br>
	 * <b>NOTE:</b> you cannot call this method more than once for each search
	 * execution. If you need to call it more than once, passing each time a
	 * different range, you should call {@link #topDocs()} and work with the
	 * returned {@link TopDocs} object, which will contain all the results this
	 * search execution collected.
	 */
	TopDocsRange(start, howMany int) TopDocs
}

search/TopDocsCollector.java *

  • A base class for all collectors that return a {@link TopDocs} output. This
  • collector allows easy extension by providing a single constructor which
  • accepts a {@link PriorityQueue} as well as protected members for that
  • priority queue and a counter of the number of total hits.<br>
  • Extending classes can override any of the methods to provide their own
  • implementation, as well as avoid the use of the priority queue entirely by
  • passing null to {@link #TopDocsCollector(PriorityQueue)}. In that case
  • however, you might want to consider overriding all methods, in order to avoid
  • a NullPointerException.

func NewTopScoreDocCollector

func NewTopScoreDocCollector(numHits int, after *ScoreDoc, docsScoredInOrder bool) TopDocsCollector

type TopDocsCreator

type TopDocsCreator interface {
	// contains filtered or unexported methods
}

type TopScoreDocCollector

type TopScoreDocCollector struct {
	// contains filtered or unexported fields
}

func (TopScoreDocCollector) AcceptsDocsOutOfOrder

func (c TopScoreDocCollector) AcceptsDocsOutOfOrder() bool

func (*TopScoreDocCollector) SetNextReader

func (c *TopScoreDocCollector) SetNextReader(ctx *index.AtomicReaderContext)

func (*TopScoreDocCollector) SetScorer

func (c *TopScoreDocCollector) SetScorer(scorer Scorer)

func (TopScoreDocCollector) TopDocs

func (c TopScoreDocCollector) TopDocs() TopDocs

func (TopScoreDocCollector) TopDocsRange

func (c TopScoreDocCollector) TopDocsRange(start, howMany int) TopDocs

type Weight

type Weight interface {
	// An explanation of the score computation for the named document.
	Explain(*index.AtomicReaderContext, int) (Explanation, error)
	/** The value for normalization of contained query clauses (e.g. sum of squared weights). */
	ValueForNormalization() float32
	/** Assigns the query normalization factor and boost from parent queries to this. */
	Normalize(norm float32, topLevelBoost float32)
	// Scorer(*index.AtomicReaderContext, util.Bits) (Scorer, error)
	/**
	 * Returns a {@link Scorer} which scores documents in/out-of order according
	 * to <code>scoreDocsInOrder</code>.
	 * <p>
	 * <b>NOTE:</b> even if <code>scoreDocsInOrder</code> is false, it is
	 * recommended to check whether the returned <code>Scorer</code> indeed scores
	 * documents out of order (i.e., call {@link #scoresDocsOutOfOrder()}), as
	 * some <code>Scorer</code> implementations will always return documents
	 * in-order.<br>
	 * <b>NOTE:</b> null can be returned if no documents will be scored by this
	 * query.
	 */
	BulkScorer(*index.AtomicReaderContext, bool, util.Bits) (BulkScorer, error)
	/**
	 * Returns true iff this implementation scores docs only out of order. This
	 * method is used in conjunction with {@link Collector}'s
	 * {@link Collector#acceptsDocsOutOfOrder() acceptsDocsOutOfOrder} and
	 * {@link #scorer(AtomicReaderContext, boolean, boolean, Bits)} to
	 * create a matching {@link Scorer} instance for a given {@link Collector}, or
	 * vice versa.
	 * <p>
	 * <b>NOTE:</b> the default implementation returns <code>false</code>, i.e.
	 * the <code>Scorer</code> scores documents in-order.
	 */
	IsScoresDocsOutOfOrder() bool // usually false
}

Expert: calculate query weights and build query scorers.

The purpose of Weight is to ensure searching does not modify a Qurey, 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 (scorer()), callers must maintain the relationship between the searcher's top-level IndexReaderCntext and context used to create a Scorer.

A Weight is used in the following way:

  1. A Weight is constructed by a top-level query, given a IndexSearcher (Query.createWeight()).
  2. The valueForNormalizatin() method is called on the Weight to compute the query normalization factor Similarity.queryNorm() of the query clauses contained in the query.
  3. The query normlaization factor is passed to normalize(). At this point the weighting is complete.
  4. A Scorer is constructed by scorer().

type WeightImpl

type WeightImpl struct {
	// contains filtered or unexported fields
}

func (*WeightImpl) BulkScorer

func (w *WeightImpl) BulkScorer(ctx *index.AtomicReaderContext,
	scoreDocsInOrder bool, acceptDoc util.Bits) (bs BulkScorer, err error)

type WeightImplSPI

type WeightImplSPI interface {
	Scorer(*index.AtomicReaderContext, util.Bits) (Scorer, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL