19 using Lucene.Net.Index;
20 using Lucene.Net.Support;
23 namespace Lucene.Net.Search
44 private EquatableList<Query> disjuncts =
new EquatableList<Query>();
47 private float tieBreakerMultiplier = 0.0f;
57 this.tieBreakerMultiplier = tieBreakerMultiplier;
67 this.tieBreakerMultiplier = tieBreakerMultiplier;
74 public virtual void Add(
Query query)
82 public virtual void Add(System.Collections.Generic.ICollection<
Query> disjuncts)
84 this.disjuncts.AddRange(disjuncts);
88 public virtual System.Collections.Generic.IEnumerator<
Query> GetEnumerator()
90 return disjuncts.GetEnumerator();
93 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
95 return GetEnumerator();
105 protected internal class DisjunctionMaxWeight:
Weight
109 this.enclosingInstance = enclosingInstance;
116 return enclosingInstance;
124 protected internal System.Collections.Generic.List<
Weight> weights =
new System.Collections.Generic.List<
Weight>();
129 InitBlock(enclosingInstance);
130 this.similarity = searcher.Similarity;
131 foreach(
Query disjunctQuery
in enclosingInstance.disjuncts)
133 weights.Add(disjunctQuery.CreateWeight(searcher));
141 get {
return Enclosing_Instance; }
146 public override float Value
148 get {
return Enclosing_Instance.Boost; }
153 public override float GetSumOfSquaredWeights()
155 float max = 0.0f, sum = 0.0f;
156 foreach (
Weight currentWeight
in weights)
158 float sub = currentWeight.GetSumOfSquaredWeights();
160 max = System.Math.Max(max, sub);
162 float boost = Enclosing_Instance.Boost;
163 return (((sum - max) * Enclosing_Instance.tieBreakerMultiplier * Enclosing_Instance.tieBreakerMultiplier) + max) *
168 public override void Normalize(
float norm)
170 norm *= Enclosing_Instance.Boost;
171 foreach(
Weight wt
in weights)
182 foreach(
Weight w
in weights)
184 Scorer subScorer = w.Scorer(reader,
true,
false);
185 if (subScorer != null && subScorer.NextDoc() !=
DocIdSetIterator.NO_MORE_DOCS)
187 scorers[idx++] = subScorer;
192 DisjunctionMaxScorer result =
new DisjunctionMaxScorer(Enclosing_Instance.tieBreakerMultiplier, similarity, scorers, idx);
199 if (Enclosing_Instance.disjuncts.Count == 1)
200 return weights[0].Explain(reader, doc);
202 float max = 0.0f, sum = 0.0f;
203 result.Description = Enclosing_Instance.tieBreakerMultiplier == 0.0f?
"max of:":
"max plus " + Enclosing_Instance.tieBreakerMultiplier +
" times others of:";
204 foreach(
Weight wt
in weights)
209 System.Boolean tempAux =
true;
210 result.Match = tempAux;
213 max = System.Math.Max(max, e.Value);
216 result.Value = max + (sum - max) * Enclosing_Instance.tieBreakerMultiplier;
224 return new DisjunctionMaxWeight(
this, searcher);
234 int numDisjunctions = disjuncts.Count;
235 if (numDisjunctions == 1)
237 Query singleton = disjuncts[0];
241 if (result == singleton)
248 for (
int i = 0; i < numDisjunctions; i++)
250 Query clause = disjuncts[i];
252 if (rewrite != clause)
256 clone.disjuncts[i] = rewrite;
268 public override System.Object Clone()
271 clone.disjuncts = (EquatableList<Query>) this.disjuncts.Clone();
276 public override void ExtractTerms(System.Collections.Generic.ISet<
Term> terms)
278 foreach(
Query query
in disjuncts)
289 public override System.String ToString(System.String field)
291 System.Text.StringBuilder buffer =
new System.Text.StringBuilder();
293 int numDisjunctions = disjuncts.Count;
294 for (
int i = 0; i < numDisjunctions; i++)
296 Query subquery = disjuncts[i];
301 buffer.Append(subquery.
ToString(field));
305 buffer.Append(subquery.
ToString(field));
306 if (i != numDisjunctions - 1)
307 buffer.Append(
" | ");
310 if (tieBreakerMultiplier != 0.0f)
313 buffer.Append(tieBreakerMultiplier);
318 buffer.Append(Boost);
328 public override bool Equals(System.Object o)
333 return this.Boost == other.
Boost && this.tieBreakerMultiplier == other.tieBreakerMultiplier && this.disjuncts.Equals(other.disjuncts);
339 public override int GetHashCode()
341 return BitConverter.ToInt32(BitConverter.GetBytes(Boost), 0) + BitConverter.ToInt32(BitConverter.GetBytes(tieBreakerMultiplier), 0) + disjuncts.GetHashCode();