private readonly Query match; // query to match #endregion Fields #region Constructors public BoostingQuery(Query match, Query context, float boost) { this.match = match; this.context = (Query) context.Clone(); // clone before boost this.boost = boost; this.context.Boost = 0.0f; // ignore context-only matches }
/// <summary> /// check very basic hashCode and equals </summary> public static void CheckHashEquals(Query q) { Query q2 = (Query)q.Clone(); CheckEqual(q, q2); Query q3 = (Query)q.Clone(); q3.Boost = 7.21792348f; CheckUnequal(q, q3); // test that a class check is done so that no exception is thrown // in the implementation of equals() Query whacky = new QueryAnonymousInnerClassHelper(); whacky.Boost = q.Boost; CheckUnequal(q, whacky); // null test Assert.IsFalse(q.Equals(null)); }
/// <summary> /// Check very basic <see cref="object.GetHashCode()"/> and <see cref="object.Equals(object)"/>. </summary> public static void CheckHashEquals(Query q) { Query q2 = (Query)q.Clone(); CheckEqual(q, q2); Query q3 = (Query)q.Clone(); q3.Boost = 7.21792348f; CheckUnequal(q, q3); // test that a class check is done so that no exception is thrown // in the implementation of equals() Query whacky = new QueryAnonymousInnerClassHelper(); whacky.Boost = q.Boost; CheckUnequal(q, whacky); // null test Assert.IsFalse(q.Equals(null)); }
public override Query Rewrite(IndexReader reader) { if (minNrShouldMatch == 0 && clauses.Count == 1) { // optimize 1-clause queries BooleanClause c = (BooleanClause)clauses[0]; if (!c.IsProhibited()) { // just return clause Query query = c.GetQuery().Rewrite(reader); // rewrite first if (GetBoost() != 1.0f) { // incorporate boost if (query == c.GetQuery()) { // if rewrite was no-op query = (Query)query.Clone(); // then clone before boost } query.SetBoost(GetBoost() * query.GetBoost()); } return(query); } } BooleanQuery clone = null; // recursively rewrite for (int i = 0; i < clauses.Count; i++) { BooleanClause c = (BooleanClause)clauses[i]; Query query = c.GetQuery().Rewrite(reader); if (query != c.GetQuery()) { // clause rewrote: must clone if (clone == null) { clone = (BooleanQuery)this.Clone(); } clone.clauses[i] = new BooleanClause(query, c.GetOccur()); } } if (clone != null) { return(clone); // some clauses rewrote } else { return(this); // no clauses rewrote } }
public override Query Rewrite(IndexReader reader) { if (MinNrShouldMatch == 0 && clauses.Count == 1) // optimize 1-clause queries { BooleanClause c = clauses[0]; if (!c.Prohibited) // just return clause { Query query = c.Query.Rewrite(reader); // rewrite first if (Boost != 1.0f) // incorporate boost { if (query == c.Query) // if rewrite was no-op { query = (Query)query.Clone(); // then clone before boost } // Since the BooleanQuery only has 1 clause, the BooleanQuery will be // written out. Therefore the rewritten Query's boost must incorporate both // the clause's boost, and the boost of the BooleanQuery itself query.Boost = Boost * query.Boost; } return(query); } } BooleanQuery clone = null; // recursively rewrite for (int i = 0; i < clauses.Count; i++) { BooleanClause c = clauses[i]; Query query = c.Query.Rewrite(reader); if (query != c.Query) // clause rewrote: must clone { if (clone == null) { // The BooleanQuery clone is lazily initialized so only initialize // it if a rewritten clause differs from the original clause (and hasn't been // initialized already). If nothing differs, the clone isn't needlessly created clone = (BooleanQuery)this.Clone(); } clone.clauses[i] = new BooleanClause(query, c.Occur_); } } if (clone != null) { return(clone); // some clauses rewrote } else { return(this); // no clauses rewrote } }
/// <summary>Optimize our representation and our subqueries representations</summary> /// <param name="reader">the IndexReader we query /// </param> /// <returns> an optimized copy of us (which may not be a copy if there is nothing to optimize) /// </returns> public override Query Rewrite(IndexReader reader) { int numDisjunctions = disjuncts.Count; if (numDisjunctions == 1) { Query singleton = (Query)disjuncts[0]; Query result = singleton.Rewrite(reader); if (GetBoost() != 1.0f) { if (result == singleton) { result = (Query)result.Clone(); } result.SetBoost(GetBoost() * result.GetBoost()); } return(result); } DisjunctionMaxQuery clone = null; for (int i = 0; i < numDisjunctions; i++) { Query clause = (Query)disjuncts[i]; Query rewrite = clause.Rewrite(reader); if (rewrite != clause) { if (clone == null) { clone = (DisjunctionMaxQuery)this.Clone(); } clone.disjuncts[i] = rewrite; } } if (clone != null) { return(clone); } else { return(this); } }
private static void Check(Query q1, Searcher s, bool wrap) { try { Check(q1); if (s != null) { if (s is IndexSearcher) { IndexSearcher is_Renamed = (IndexSearcher)s; CheckFirstSkipTo(q1, is_Renamed); CheckSkipTo(q1, is_Renamed); if (wrap) { Check(q1, WrapUnderlyingReader(is_Renamed, -1), false); Check(q1, WrapUnderlyingReader(is_Renamed, 0), false); Check(q1, WrapUnderlyingReader(is_Renamed, +1), false); } } if (wrap) { Check(q1, WrapSearcher(s, -1), false); Check(q1, WrapSearcher(s, 0), false); Check(q1, WrapSearcher(s, +1), false); } CheckExplanations(q1, s); CheckSerialization(q1, s); Query q2 = (Query)q1.Clone(); CheckEqual(s.Rewrite(q1, null), s.Rewrite(q2, null)); } } catch (System.IO.IOException e) { throw new System.SystemException("", e); } }
/// <summary>check very basic hashCode and equals </summary> public static void CheckHashEquals(Query q) { Query q2 = (Query) q.Clone(); CheckEqual(q, q2); Query q3 = (Query) q.Clone(); q3.SetBoost(7.21792348f); CheckUnequal(q, q3); // test that a class check is done so that no exception is thrown // in the implementation of equals() Query whacky = new AnonymousClassQuery(); whacky.SetBoost(q.GetBoost()); CheckUnequal(q, whacky); }
public override object Clone() { return(Wrap(new Random(Random.Next()), (Query)@in.Clone())); }
public static void Check(Random random, Query q1, IndexSearcher s, bool wrap) { try { Check(q1); if (s != null) { CheckFirstSkipTo(q1, s); CheckSkipTo(q1, s); if (wrap) { Check(random, q1, WrapUnderlyingReader(random, s, -1), false); Check(random, q1, WrapUnderlyingReader(random, s, 0), false); Check(random, q1, WrapUnderlyingReader(random, s, +1), false); } CheckExplanations(q1, s); Query q2 = (Query)q1.Clone(); CheckEqual(s.Rewrite(q1), s.Rewrite(q2)); } } catch (IOException e) { throw new Exception(e.Message, e); } }
private static void Check(Query q1, Searcher s, bool wrap) { try { Check(q1); if (s != null) { if (s is IndexSearcher) { IndexSearcher is_Renamed = (IndexSearcher) s; CheckFirstSkipTo(q1, is_Renamed); CheckSkipTo(q1, is_Renamed); if (wrap) { Check(q1, WrapUnderlyingReader(is_Renamed, - 1), false); Check(q1, WrapUnderlyingReader(is_Renamed, 0), false); Check(q1, WrapUnderlyingReader(is_Renamed, + 1), false); } } if (wrap) { Check(q1, WrapSearcher(s, - 1), false); Check(q1, WrapSearcher(s, 0), false); Check(q1, WrapSearcher(s, + 1), false); } CheckExplanations(q1, s); CheckSerialization(q1, s); Query q2 = (Query) q1.Clone(); CheckEqual(s.Rewrite(q1), s.Rewrite(q2)); } } catch (System.IO.IOException e) { throw new System.SystemException("", e); } }
public override object Clone() { return(Wrap(new J2N.Randomizer(random.NextInt64()), (Query)@in.Clone())); }