org.apache.lucene.search
Class Weight
java.lang.Object org.apache.lucene.search.Weight
-
All Implemented Interfaces:
- Serializable
-
Direct Known Subclasses:
- BooleanQuery.BooleanWeight, ConstantScoreQuery.ConstantWeight, DisjunctionMaxQuery.DisjunctionMaxWeight, SpanWeight
public abstract class Weightextends Object implements Serializable
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. Searcher dependent state of the query should reside in the Weight. IndexReader dependent state should reside in the Scorer.
A Weight is used in the following way:
- A
Weightis constructed by a top-level query, given aSearcher(Query.createWeight(Searcher)). - The
sumOfSquaredWeights()method is called on theWeightto compute the query normalization factorSimilarity.queryNorm(float)of the query clauses contained in the query. - The query normalization factor is passed to
normalize(float). At this point the weighting is complete. - A
Scoreris constructed byscorer(IndexReader,boolean,boolean).
本文深入解析了org.apache.lucene.search下的Weight类,阐述了其在Lucene搜索机制中的关键作用,包括查询权重计算、归一化及评分器创建过程。通过理解Weight的工作原理,读者将能更好地掌握Lucene搜索引擎内部实现。
1万+

被折叠的 条评论
为什么被折叠?



