From 7acabfecf0298498e9a9e5cbb3a24669d18da4b3 Mon Sep 17 00:00:00 2001
From: Uwe Schindler
- * In {@link RangeQuery}s, QueryParser tries to detect date values, e.g. + * In {@link TermRangeQuery}s, QueryParser tries to detect date values, e.g. * date:[6/1/2005 TO 6/4/2005] produces a range query that searches * for "date" fields between 2005-06-01 and 2005-06-04. Note that the format * of the accepted input depends on {@link #setLocale(Locale) the locale}. @@ -1626,6 +1625,12 @@ public class QueryParser implements QueryParserConstants { finally { jj_save(0, xla); } } + private boolean jj_3R_3() { + if (jj_scan_token(STAR)) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + private boolean jj_3R_2() { if (jj_scan_token(TERM)) return true; if (jj_scan_token(COLON)) return true; @@ -1642,12 +1647,6 @@ public class QueryParser implements QueryParserConstants { return false; } - private boolean jj_3R_3() { - if (jj_scan_token(STAR)) return true; - if (jj_scan_token(COLON)) return true; - return false; - } - /** Generated Token Manager. */ public QueryParserTokenManager token_source; /** Current token. */ diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jj index 74b587258d3..cfd60b3eb3e 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParser.jj +++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj @@ -48,7 +48,6 @@ import org.apache.lucene.document.DateTools; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.ConstantScoreRangeQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MultiPhraseQuery; @@ -95,7 +94,7 @@ import org.apache.lucene.util.Parameter; *
* *- * In {@link RangeQuery}s, QueryParser tries to detect date values, e.g. + * In {@link TermRangeQuery}s, QueryParser tries to detect date values, e.g. * date:[6/1/2005 TO 6/4/2005] produces a range query that searches * for "date" fields between 2005-06-01 and 2005-06-04. Note that the format * of the accepted input depends on {@link #setLocale(Locale) the locale}. diff --git a/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java b/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java index f3992bce6f3..215950a15b6 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java +++ b/src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java @@ -22,7 +22,6 @@ import org.apache.lucene.document.DateTools; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.ConstantScoreRangeQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MultiPhraseQuery; diff --git a/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java b/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java index a558f2cedbb..0f8b7cbaf20 100644 --- a/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java +++ b/src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java @@ -21,13 +21,17 @@ import java.text.Collator; /** * A range query that returns a constant score equal to its boost for - * all documents in the range. - *
- * It does not have an upper bound on the number of clauses covered in the range. - *
- * If an endpoint is null, it is said to be "open". - * Either or both endpoints may be open. Open endpoints may not be exclusive - * (you can't select all but the first or last term without explicitly specifying the term to exclude.) + * all documents in the exclusive range of terms. + * + *
It does not have an upper bound on the number of clauses covered in the range. + * + *
This query matches the documents looking for terms that fall into the + * supplied range according to {@link String#compareTo(String)}. It is not intended + * for numerical ranges, use {@link NumericRangeQuery} instead. + * + *
This query is in + * {@linkplain MultiTermQuery#setConstantScoreRewrite(boolean) constant score rewrite mode}. + * If you want to change this, use the new {@link TermRangeQuery} instead. * * @deprecated Use {@link TermRangeQuery} for term ranges or * {@link NumericRangeQuery} for numeric ranges instead. @@ -40,14 +44,14 @@ public class ConstantScoreRangeQuery extends TermRangeQuery public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) { super(fieldName, lowerVal, upperVal, includeLower, includeUpper); - setConstantScoreRewrite(true); + this.constantScoreRewrite = true; } public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper, Collator collator) { super(fieldName, lowerVal, upperVal, includeLower, includeUpper, collator); - setConstantScoreRewrite(true); + this.constantScoreRewrite = true; } public String getLowerVal() { @@ -57,4 +61,10 @@ public class ConstantScoreRangeQuery extends TermRangeQuery public String getUpperVal() { return getUpperTerm(); } + + /** Changes of mode are not supported by this class (fixed to constant score rewrite mode) */ + public void setConstantScoreRewrite(boolean constantScoreRewrite) { + if (!constantScoreRewrite) + throw new UnsupportedOperationException("Use TermRangeQuery instead to enable boolean query rewrite."); + } } diff --git a/src/java/org/apache/lucene/search/RangeQuery.java b/src/java/org/apache/lucene/search/RangeQuery.java index b4247fb3874..8b81fcd996e 100644 --- a/src/java/org/apache/lucene/search/RangeQuery.java +++ b/src/java/org/apache/lucene/search/RangeQuery.java @@ -27,11 +27,12 @@ import org.apache.lucene.index.Term; * A Query that matches documents within an exclusive range of terms. * *
This query matches the documents looking for terms that fall into the - * supplied range according to {@link String#compareTo(String)}. It is not intended + * supplied range according to {@link Term#compareTo(Term)}. It is not intended * for numerical ranges, use {@link NumericRangeQuery} instead. * - *
See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between - * enabling and disabling constantScoreRewrite mode. + *
This query is in + * {@linkplain MultiTermQuery#setConstantScoreRewrite(boolean) boolean query rewrite mode}. + * If you want to change this, use the new {@link TermRangeQuery} instead. * * @deprecated Use {@link TermRangeQuery} for term ranges or * {@link NumericRangeQuery} for numeric ranges instead. diff --git a/src/java/org/apache/lucene/search/TermRangeFilter.java b/src/java/org/apache/lucene/search/TermRangeFilter.java index 44ff6489c2e..973396b9ddf 100644 --- a/src/java/org/apache/lucene/search/TermRangeFilter.java +++ b/src/java/org/apache/lucene/search/TermRangeFilter.java @@ -29,6 +29,7 @@ import java.text.Collator; * *
If you construct a large number of range filters with different ranges but on the * same field, {@link FieldCacheRangeFilter} may have significantly better performance. + * @since 2.9 */ public class TermRangeFilter extends MultiTermQueryWrapperFilter { diff --git a/src/java/org/apache/lucene/search/TermRangeQuery.java b/src/java/org/apache/lucene/search/TermRangeQuery.java index b588551aefa..9d8b1a595f9 100644 --- a/src/java/org/apache/lucene/search/TermRangeQuery.java +++ b/src/java/org/apache/lucene/search/TermRangeQuery.java @@ -34,6 +34,7 @@ import org.apache.lucene.util.ToStringUtils; *
This query is in constant score mode per default. * See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between * enabling and disabling constantScoreRewrite mode. + * @since 2.9 */ public class TermRangeQuery extends MultiTermQuery { @@ -109,7 +110,7 @@ public class TermRangeQuery extends MultiTermQuery { this.includeLower = includeLower; this.includeUpper = includeUpper; this.collator = collator; - setConstantScoreRewrite(true); + this.constantScoreRewrite = true; } /** Returns the field name for this query */ diff --git a/src/java/org/apache/lucene/search/TermRangeTermEnum.java b/src/java/org/apache/lucene/search/TermRangeTermEnum.java index c5f65c92249..9a3977627cb 100644 --- a/src/java/org/apache/lucene/search/TermRangeTermEnum.java +++ b/src/java/org/apache/lucene/search/TermRangeTermEnum.java @@ -29,6 +29,7 @@ import org.apache.lucene.index.Term; *
* Term enumerations are always ordered by Term.compareTo(). Each term in * the enumeration is greater than all that precede it. + * @since 2.9 */ public class TermRangeTermEnum extends FilteredTermEnum {