19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
22 using Term = Lucene.Net.Index.Term;
26 namespace Lucene.Net.Search
63 public override int TermCountCutoff
65 set {
throw new System.NotSupportedException(
"Please create a private instance"); }
68 public override double DocCountPercent
70 set {
throw new System.NotSupportedException(
"Please create a private instance"); }
74 protected internal virtual System.Object ReadResolve()
76 return Lucene.Net.Search.MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
79 protected internal RewriteMethod internalRewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
81 internal int numberOfTerms = 0;
84 private sealed
class ConstantScoreFilterRewrite:RewriteMethod
88 Query result =
new ConstantScoreQuery(
new MultiTermQueryWrapperFilter<MultiTermQuery>(query));
89 result.Boost = query.Boost;
94 internal System.Object ReadResolve()
96 return Lucene.Net.Search.MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
114 public static readonly
RewriteMethod CONSTANT_SCORE_FILTER_REWRITE =
new ConstantScoreFilterRewrite();
138 while (enumerator.
Next());
144 query.IncTotalNumberOfTerms(count);
149 protected internal virtual System.Object ReadResolve()
151 return Lucene.Net.Search.MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
170 public static readonly
RewriteMethod SCORING_BOOLEAN_QUERY_REWRITE =
new ScoringBooleanQueryRewrite();
173 private class ConstantScoreBooleanQueryRewrite:ScoringBooleanQueryRewrite
184 protected internal override System.Object ReadResolve()
186 return Lucene.Net.Search.MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
202 public static readonly
RewriteMethod CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE =
new ConstantScoreBooleanQueryRewrite();
220 private void InitBlock()
222 termCountCutoff = DEFAULT_TERM_COUNT_CUTOFF;
223 docCountPercent = DEFAULT_DOC_COUNT_PERCENT;
229 public static int DEFAULT_TERM_COUNT_CUTOFF = 350;
233 public static double DEFAULT_DOC_COUNT_PERCENT = 0.1;
235 private int termCountCutoff;
236 private double docCountPercent;
242 public virtual int TermCountCutoff
244 get {
return termCountCutoff; }
245 set { termCountCutoff = value; }
254 public virtual double DocCountPercent
256 get {
return docCountPercent; }
257 set { docCountPercent = value; }
266 ICollection<Term> pendingTerms =
new List<Term>();
267 int docCountCutoff = (int) ((docCountPercent / 100.0) * reader.MaxDoc);
269 int docVisitCount = 0;
284 docVisitCount += reader.DocFreq(t);
287 if (pendingTerms.Count >= termCountLimit || docVisitCount >= docCountCutoff)
294 else if (!enumerator.
Next())
300 foreach(
Term term
in pendingTerms)
303 bq.Add(tq,
Occur.SHOULD);
308 query.IncTotalNumberOfTerms(pendingTerms.Count);
319 public override int GetHashCode()
322 return (
int) (prime * termCountCutoff + BitConverter.DoubleToInt64Bits(docCountPercent));
325 public override bool Equals(System.Object obj)
331 if (GetType() != obj.GetType())
335 if (other.termCountCutoff != termCountCutoff)
340 if (BitConverter.DoubleToInt64Bits(other.docCountPercent) != BitConverter.DoubleToInt64Bits(docCountPercent))
389 public virtual int TotalNumberOfTerms
391 get {
return numberOfTerms; }
399 public virtual void ClearTotalNumberOfTerms()
404 protected internal virtual void IncTotalNumberOfTerms(
int inc)
406 numberOfTerms += inc;
411 return internalRewriteMethod.
Rewrite(reader,
this);
420 get {
return internalRewriteMethod; }
421 set { internalRewriteMethod = value; }
425 public override int GetHashCode()
429 result = prime * result + System.Convert.ToInt32(Boost);
430 result = prime * result;
436 public override bool Equals(System.Object obj)
442 if (GetType() != obj.GetType())
445 if (System.Convert.ToInt32(Boost) != System.Convert.ToInt32(other.
Boost))
447 if (!internalRewriteMethod.Equals(other.internalRewriteMethod))
455 CONSTANT_SCORE_AUTO_REWRITE_DEFAULT =
new AnonymousClassConstantScoreAutoRewrite();