19 using Lucene.Net.Index;
22 namespace Lucene.Net.Search
31 protected internal Filter internalFilter;
35 this.internalFilter = filter;
41 get {
return internalFilter; }
49 public override void ExtractTerms(System.Collections.Generic.ISet<
Term> terms)
56 protected internal class ConstantWeight:
Weight
60 this.enclosingInstance = enclosingInstance;
62 private ConstantScoreQuery enclosingInstance;
63 public ConstantScoreQuery Enclosing_Instance
67 return enclosingInstance;
72 private float queryNorm;
73 private float queryWeight;
75 public ConstantWeight(ConstantScoreQuery enclosingInstance,
Searcher searcher)
77 InitBlock(enclosingInstance);
78 this.similarity = Enclosing_Instance.GetSimilarity(searcher);
83 get {
return Enclosing_Instance; }
86 public override float Value
88 get {
return queryWeight; }
91 public override float GetSumOfSquaredWeights()
93 queryWeight = Enclosing_Instance.Boost;
94 return queryWeight*queryWeight;
97 public override void Normalize(
float norm)
99 this.queryNorm = norm;
100 queryWeight *= this.queryNorm;
105 return new ConstantScorer(enclosingInstance, similarity, reader,
this);
111 var cs =
new ConstantScorer(enclosingInstance, similarity, reader,
this);
112 bool exists = cs.docIdSetIterator.Advance(doc) == doc;
118 result.Description =
"ConstantScoreQuery(" + Enclosing_Instance.internalFilter +
"), product of:";
119 result.Value = queryWeight;
120 System.Boolean tempAux =
true;
121 result.Match = tempAux;
122 result.AddDetail(
new Explanation(Enclosing_Instance.Boost,
"boost"));
123 result.AddDetail(
new Explanation(queryNorm,
"queryNorm"));
127 result.Description =
"ConstantScoreQuery(" + Enclosing_Instance.internalFilter +
") doesn't match id " + doc;
129 System.Boolean tempAux2 =
false;
130 result.Match = tempAux2;
136 protected internal class ConstantScorer :
Scorer
138 private void InitBlock(ConstantScoreQuery enclosingInstance)
140 this.enclosingInstance = enclosingInstance;
142 private ConstantScoreQuery enclosingInstance;
143 public ConstantScoreQuery Enclosing_Instance
147 return enclosingInstance;
152 internal float theScore;
153 internal int doc = - 1;
157 InitBlock(enclosingInstance);
159 DocIdSet docIdSet = Enclosing_Instance.internalFilter.GetDocIdSet(reader);
160 if (docIdSet == null)
162 docIdSetIterator =
DocIdSet.EMPTY_DOCIDSET.Iterator();
169 docIdSetIterator =
DocIdSet.EMPTY_DOCIDSET.Iterator();
173 docIdSetIterator = iter;
178 public override int NextDoc()
180 return docIdSetIterator.NextDoc();
183 public override int DocID()
185 return docIdSetIterator.DocID();
188 public override float Score()
193 public override int Advance(
int target)
195 return docIdSetIterator.Advance(target);
205 public override System.String ToString(
string field)
207 return "ConstantScore(" + internalFilter + (Boost == 1.0?
")":
"^" + Boost);
211 public override bool Equals(System.Object o)
217 ConstantScoreQuery other = (ConstantScoreQuery) o;
218 return this.Boost == other.
Boost && internalFilter.Equals(other.internalFilter);
222 public override int GetHashCode()
225 return internalFilter.GetHashCode() + BitConverter.ToInt32(BitConverter.GetBytes(Boost), 0);
228 override public System.Object Clone()
232 clone.internalFilter = (
Filter)this.internalFilter;