/// <summary>macro for readability </summary> public static Query Csrq(System.String f, System.String l, System.String h, bool il, bool ih, System.Globalization.CompareInfo c) { TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih, c); query.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); return(query); }
public static Query Csrq(System.String f, System.String l, System.String h, bool il, bool ih, MultiTermQuery.RewriteMethod method) { TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih); query.SetRewriteMethod(method); return(query); }
/// <summary> /// macro for readability </summary> public static Query Csrq(string f, string l, string h, bool il, bool ih) { TermRangeQuery query = TermRangeQuery.NewStringRange(f, l, h, il, ih); query.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); if (VERBOSE) { Console.WriteLine("TEST: query=" + query); } return(query); }
public static Query Csrq(string f, string l, string h, bool il, bool ih, MultiTermQuery.RewriteMethod method) { TermRangeQuery query = TermRangeQuery.NewStringRange(f, l, h, il, ih); query.SetRewriteMethod(method); if (VERBOSE) { Console.WriteLine("TEST: query=" + query + " method=" + method); } return(query); }
/// <summary> /// check that the # of hits is the same as if the query /// is run against the inverted index /// </summary> protected internal virtual void AssertSame(BytesRef lowerVal, BytesRef upperVal, bool includeLower, bool includeUpper) { Query docValues = new ConstantScoreQuery(DocTermOrdsRangeFilter.NewBytesRefRange(FieldName, lowerVal, upperVal, includeLower, includeUpper)); MultiTermQuery inverted = new TermRangeQuery(FieldName, lowerVal, upperVal, includeLower, includeUpper); inverted.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); TopDocs invertedDocs = Searcher1.Search(inverted, 25); TopDocs docValuesDocs = Searcher2.Search(docValues, 25); CheckHits.CheckEqual(inverted, invertedDocs.ScoreDocs, docValuesDocs.ScoreDocs); }
/// <summary>Constructs a query selecting all terms greater than /// <code>lowerTerm</code> but less than <code>upperTerm</code>. /// There must be at least one term and either term may be null, /// in which case there is no bound on that side, but if there are /// two terms, both terms <b>must</b> be for the same field. /// <p/> /// If <code>collator</code> is not null, it will be used to decide whether /// index terms are within the given range, rather than using the Unicode code /// point order in which index terms are stored. /// <p/> /// <strong>WARNING:</strong> Using this constructor and supplying a non-null /// value in the <code>collator</code> parameter will cause every single /// index Term in the Field referenced by lowerTerm and/or upperTerm to be /// examined. Depending on the number of index Terms in this Field, the /// operation could be very slow. /// /// </summary> /// <param name="lowerTerm">The Term at the lower end of the range /// </param> /// <param name="upperTerm">The Term at the upper end of the range /// </param> /// <param name="inclusive">If true, both <code>lowerTerm</code> and /// <code>upperTerm</code> will themselves be included in the range. /// </param> /// <param name="collator">The collator to use to collate index Terms, to determine /// their membership in the range bounded by <code>lowerTerm</code> and /// <code>upperTerm</code>. /// </param> public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive, System.Globalization.CompareInfo collator) { if (lowerTerm == null && upperTerm == null) { throw new System.ArgumentException("At least one term must be non-null"); } if (lowerTerm != null && upperTerm != null && (System.Object)lowerTerm.Field() != (System.Object)upperTerm.Field()) { throw new System.ArgumentException("Both terms must have the same field"); } delegate_Renamed = new TermRangeQuery((lowerTerm == null)?upperTerm.Field():lowerTerm.Field(), (lowerTerm == null)?null:lowerTerm.Text(), (upperTerm == null)?null:upperTerm.Text(), inclusive, inclusive, collator); delegate_Renamed.SetRewriteMethod(TermRangeQuery.SCORING_BOOLEAN_QUERY_REWRITE); }
private void CheckBooleanTerms(IndexSearcher searcher, TermRangeQuery query, params string[] terms) { query.SetRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(50)); BooleanQuery bq = (BooleanQuery)searcher.Rewrite(query); var allowedTerms = AsSet(terms); Assert.AreEqual(allowedTerms.Count, bq.Clauses.Length); foreach (BooleanClause c in bq.Clauses) { Assert.IsTrue(c.Query is TermQuery); TermQuery tq = (TermQuery)c.Query; string term = tq.Term.Text(); Assert.IsTrue(allowedTerms.Contains(term), "invalid term: " + term); allowedTerms.Remove(term); // remove to fail on double terms } Assert.AreEqual(0, allowedTerms.Count); }
/// <summary> /// check that the # of hits is the same as if the query /// is run against the inverted index /// </summary> protected internal virtual void AssertSame(BytesRef lowerVal, BytesRef upperVal, bool includeLower, bool includeUpper) { Query docValues = new ConstantScoreQuery(DocTermOrdsRangeFilter.NewBytesRefRange(FieldName, lowerVal, upperVal, includeLower, includeUpper)); MultiTermQuery inverted = new TermRangeQuery(FieldName, lowerVal, upperVal, includeLower, includeUpper); inverted.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); TopDocs invertedDocs = Searcher1.Search(inverted, 25); TopDocs docValuesDocs = Searcher2.Search(docValues, 25); CheckHits.CheckEqual(inverted, invertedDocs.ScoreDocs, docValuesDocs.ScoreDocs); }
/// <summary>Constructs a query selecting all terms greater than /// <c>lowerTerm</c> but less than <c>upperTerm</c>. /// There must be at least one term and either term may be null, /// in which case there is no bound on that side, but if there are /// two terms, both terms <b>must</b> be for the same field. /// <p/> /// If <c>collator</c> is not null, it will be used to decide whether /// index terms are within the given range, rather than using the Unicode code /// point order in which index terms are stored. /// <p/> /// <strong>WARNING:</strong> Using this constructor and supplying a non-null /// value in the <c>collator</c> parameter will cause every single /// index Term in the Field referenced by lowerTerm and/or upperTerm to be /// examined. Depending on the number of index Terms in this Field, the /// operation could be very slow. /// /// </summary> /// <param name="lowerTerm">The Term at the lower end of the range /// </param> /// <param name="upperTerm">The Term at the upper end of the range /// </param> /// <param name="inclusive">If true, both <c>lowerTerm</c> and /// <c>upperTerm</c> will themselves be included in the range. /// </param> /// <param name="collator">The collator to use to collate index Terms, to determine /// their membership in the range bounded by <c>lowerTerm</c> and /// <c>upperTerm</c>. /// </param> public RangeQuery(Term lowerTerm, Term upperTerm, bool inclusive, System.Globalization.CompareInfo collator) { if (lowerTerm == null && upperTerm == null) throw new System.ArgumentException("At least one term must be non-null"); if (lowerTerm != null && upperTerm != null && (System.Object) lowerTerm.Field() != (System.Object) upperTerm.Field()) throw new System.ArgumentException("Both terms must have the same field"); delegate_Renamed = new TermRangeQuery((lowerTerm == null)?upperTerm.Field():lowerTerm.Field(), (lowerTerm == null)?null:lowerTerm.Text(), (upperTerm == null)?null:upperTerm.Text(), inclusive, inclusive, collator); delegate_Renamed.SetRewriteMethod(TermRangeQuery.SCORING_BOOLEAN_QUERY_REWRITE); }
/// <summary>macro for readability </summary> public static Query Csrq(System.String f, System.String l, System.String h, bool il, bool ih, System.Globalization.CompareInfo c) { TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih, c); query.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE); return query; }
public static Query Csrq(System.String f, System.String l, System.String h, bool il, bool ih, MultiTermQuery.RewriteMethod method) { TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih); query.SetRewriteMethod(method); return query; }
private void CheckBooleanTerms(IndexSearcher searcher, TermRangeQuery query, params string[] terms) { query.SetRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(50)); BooleanQuery bq = (BooleanQuery)searcher.Rewrite(query); var allowedTerms = AsSet(terms); Assert.AreEqual(allowedTerms.Count, bq.Clauses.Length); foreach (BooleanClause c in bq.Clauses) { Assert.IsTrue(c.Query is TermQuery); TermQuery tq = (TermQuery)c.Query; string term = tq.Term.Text(); Assert.IsTrue(allowedTerms.Contains(term), "invalid term: " + term); allowedTerms.Remove(term); // remove to fail on double terms } Assert.AreEqual(0, allowedTerms.Count); }
/// <summary> /// Builds a new {@link TermRangeQuery} instance /// </summary> /// <param name="field">Field</param> /// <param name="part1">min</param> /// <param name="part2">max</param> /// <param name="startInclusive">true if the start of the range is inclusive</param> /// <param name="endInclusive">true if the end of the range is inclusive</param> /// <returns>new <see cref="T:TermRangeQuery"/> instance</returns> protected internal virtual Query NewRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive) { BytesRef start; BytesRef end; if (part1 == null) { start = null; } else { start = AnalyzeRangeTerms ? AnalyzeMultitermTerm(field, part1) : new BytesRef(part1); } if (part2 == null) { end = null; } else { end = AnalyzeRangeTerms ? AnalyzeMultitermTerm(field, part2) : new BytesRef(part2); } TermRangeQuery query = new TermRangeQuery(field, start, end, startInclusive, endInclusive); query.SetRewriteMethod(MultiTermRewriteMethod); return query; }