Index: contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java =================================================================== --- contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java (revision 790584) +++ contrib/collation/src/test/org/apache/lucene/collation/CollationTestBase.java (working copy) @@ -29,9 +29,9 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeFilter; +import org.apache.lucene.search.TermRangeFilter; import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.ConstantScoreRangeQuery; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.Sort; @@ -102,7 +102,7 @@ result = is.search(aqp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, result.length); - // Test RangeQuery + // Test TermRangeQuery aqp.setUseOldRangeQuery(true); result = is.search(aqp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, result.length); @@ -132,15 +132,15 @@ // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi // orders the U+0698 character before the U+0633 character, so the single - // index Term below should NOT be returned by a RangeFilter with a Farsi + // index Term below should NOT be returned by a TermRangeFilter with a Farsi // Collator (or an Arabic one for the case when Farsi searcher not // supported). ScoreDoc[] result = searcher.search - (query, new RangeFilter("content", firstBeg, firstEnd, true, true), 1).scoreDocs; + (query, new TermRangeFilter("content", firstBeg, firstEnd, true, true), 1).scoreDocs; assertEquals("The index Term should not be included.", 0, result.length); result = searcher.search - (query, new RangeFilter("content", secondBeg, secondEnd, true, true), 1).scoreDocs; + (query, new TermRangeFilter("content", secondBeg, secondEnd, true, true), 1).scoreDocs; assertEquals("The index Term should be included.", 1, result.length); searcher.close(); @@ -156,7 +156,7 @@ // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi // orders the U+0698 character before the U+0633 character, so the single - // index Term below should NOT be returned by a RangeQuery with a Farsi + // index Term below should NOT be returned by a TermRangeQuery with a Farsi // Collator (or an Arabic one for the case when Farsi is not supported). doc.add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES, Field.Index.ANALYZED)); @@ -164,13 +164,11 @@ writer.close(); IndexSearcher searcher = new IndexSearcher(ramDir); - Query query = new RangeQuery(new Term("content", firstBeg), - new Term("content", firstEnd), true); + Query query = new TermRangeQuery("content", firstBeg, firstEnd, true, true); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, hits.length); - query = new RangeQuery(new Term("content", secondBeg), - new Term("content", secondEnd), true); + query = new TermRangeQuery("content", secondBeg, secondEnd, true, true); hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, hits.length); searcher.close(); Index: contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java =================================================================== --- contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java (revision 790584) +++ contrib/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java (working copy) @@ -29,7 +29,7 @@ /** * Utility class used to extract the terms used in a query, plus any weights. - * This class will not find terms for MultiTermQuery, RangeQuery and PrefixQuery classes + * This class will not find terms for MultiTermQuery, TermRangeQuery and PrefixQuery classes * so the caller must pass a rewritten query (see Query.rewrite) to obtain a list of * expanded terms. * Index: contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java =================================================================== --- contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java (revision 790584) +++ contrib/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java (working copy) @@ -45,7 +45,7 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.spans.SpanNearQuery; @@ -145,8 +145,8 @@ query = mtq; } String field; - if(mtq instanceof RangeQuery) { - field = ((RangeQuery)mtq).getField(); + if(mtq instanceof TermRangeQuery) { + field = ((TermRangeQuery)mtq).getField(); } else { field = mtq.getTerm().field(); } @@ -472,10 +472,10 @@ } private MultiTermQuery copyMultiTermQuery(MultiTermQuery query) { - if(query instanceof RangeQuery) { - RangeQuery q = (RangeQuery)query; + if(query instanceof TermRangeQuery) { + TermRangeQuery q = (TermRangeQuery)query; q.setBoost(query.getBoost()); - return new RangeQuery(q.getField(), q.getLowerTermText(), q.getUpperTermText(), q.includesLower(), q.includesUpper()); + return new TermRangeQuery(q.getField(), q.getLowerTermText(), q.getUpperTermText(), q.includesLower(), q.includesUpper()); } else if(query instanceof WildcardQuery) { MultiTermQuery q = new WildcardQuery(query.getTerm()); q.setBoost(query.getBoost()); Index: contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java =================================================================== --- contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (revision 790584) +++ contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (working copy) @@ -59,7 +59,7 @@ import org.apache.lucene.search.MultiSearcher; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeFilter; +import org.apache.lucene.search.TermRangeFilter; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; @@ -484,7 +484,7 @@ numHighlights = 0; String queryString = FIELD_NAME + ":[kannedy TO kznnedy]"; - // Need to explicitly set the QueryParser property to use RangeQuery + // Need to explicitly set the QueryParser property to use TermRangeQuery // rather // than RangeFilters QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer()); @@ -701,7 +701,7 @@ public void run() throws Exception { numHighlights = 0; - RangeFilter rf = new RangeFilter("contents", "john", "john", true, true); + TermRangeFilter rf = new TermRangeFilter("contents", "john", "john", true, true); SpanQuery clauses[] = { new SpanTermQuery(new Term("contents", "john")), new SpanTermQuery(new Term("contents", "kennedy")), }; SpanNearQuery snq = new SpanNearQuery(clauses, 1, true); @@ -723,7 +723,7 @@ public void run() throws Exception { numHighlights = 0; - RangeFilter rf = new RangeFilter("contents", "john", "john", true, true); + TermRangeFilter rf = new TermRangeFilter("contents", "john", "john", true, true); PhraseQuery pq = new PhraseQuery(); pq.add(new Term("contents", "john")); pq.add(new Term("contents", "kennedy")); Index: contrib/miscellaneous/src/java/org/apache/lucene/queryParser/analyzing/AnalyzingQueryParser.java =================================================================== --- contrib/miscellaneous/src/java/org/apache/lucene/queryParser/analyzing/AnalyzingQueryParser.java (revision 790584) +++ contrib/miscellaneous/src/java/org/apache/lucene/queryParser/analyzing/AnalyzingQueryParser.java (working copy) @@ -295,7 +295,7 @@ // ignore } if (multipleTokens) { - throw new ParseException("Cannot build RangeQuery with analyzer " + getAnalyzer().getClass() + throw new ParseException("Cannot build TermRangeQuery with analyzer " + getAnalyzer().getClass() + " - tokens were added to part1"); } @@ -316,7 +316,7 @@ // ignore } if (multipleTokens) { - throw new ParseException("Cannot build RangeQuery with analyzer " + getAnalyzer().getClass() + throw new ParseException("Cannot build TermRangeQuery with analyzer " + getAnalyzer().getClass() + " - tokens were added to part2"); } return super.getRangeQuery(field, part1, part2, inclusive); Index: contrib/miscellaneous/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java =================================================================== --- contrib/miscellaneous/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java (revision 790584) +++ contrib/miscellaneous/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParser.java (working copy) @@ -21,7 +21,7 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.util.Parameter; @@ -431,9 +431,7 @@ } catch (Exception e) { } - return new RangeQuery(new Term(field, part1), - new Term(field, part2), - inclusive); + return new TermRangeQuery(field, part1, part2, inclusive, inclusive); } /** Index: contrib/miscellaneous/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java =================================================================== --- contrib/miscellaneous/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java (revision 790584) +++ contrib/miscellaneous/src/java/org/apache/lucene/queryParser/precedence/PrecedenceQueryParserTokenManager.java (working copy) @@ -19,7 +19,7 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.util.Parameter; Index: contrib/miscellaneous/src/test/org/apache/lucene/misc/ChainedFilterTest.java =================================================================== --- contrib/miscellaneous/src/test/org/apache/lucene/misc/ChainedFilterTest.java (revision 790584) +++ contrib/miscellaneous/src/test/org/apache/lucene/misc/ChainedFilterTest.java (working copy) @@ -40,7 +40,7 @@ private IndexSearcher searcher; private Query query; // private DateFilter dateFilter; DateFilter was deprecated and removed - private RangeFilter dateFilter; + private TermRangeFilter dateFilter; private QueryWrapperFilter bobFilter; private QueryWrapperFilter sueFilter; @@ -76,7 +76,7 @@ //Date pastTheEnd = parseDate("2099 Jan 1"); // dateFilter = DateFilter.Before("date", pastTheEnd); // just treat dates as strings and select the whole range for now... - dateFilter = new RangeFilter("date","","ZZZZ",true,true); + dateFilter = new TermRangeFilter("date","","ZZZZ",true,true); bobFilter = new QueryWrapperFilter( new TermQuery(new Term("owner", "bob"))); Index: contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java =================================================================== --- contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java (revision 790584) +++ contrib/miscellaneous/src/test/org/apache/lucene/queryParser/precedence/TestPrecedenceQueryParser.java (working copy) @@ -32,7 +32,7 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; @@ -349,7 +349,7 @@ public void testRange() throws Exception { assertQueryEquals("[ a TO z]", null, "[a TO z]"); - assertTrue(getQuery("[ a TO z]", null) instanceof RangeQuery); + assertTrue(getQuery("[ a TO z]", null) instanceof TermRangeQuery); assertQueryEquals("[ a TO z ]", null, "[a TO z]"); assertQueryEquals("{ a TO z}", null, "{a TO z}"); assertQueryEquals("{ a TO z }", null, "{a TO z}"); Index: contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java =================================================================== --- contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java (revision 790584) +++ contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java (working copy) @@ -30,7 +30,7 @@ import org.apache.lucene.search.BooleanFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.search.FilterClause; -import org.apache.lucene.search.RangeFilter; +import org.apache.lucene.search.TermRangeFilter; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.DocIdBitSet; @@ -84,7 +84,7 @@ private Filter getRangeFilter(String field,String lowerPrice, String upperPrice, boolean old) { - Filter f = new RangeFilter(field,lowerPrice,upperPrice,true,true); + Filter f = new TermRangeFilter(field,lowerPrice,upperPrice,true,true); if (old) { return getOldBitSetFilter(f); } Index: contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java =================================================================== --- contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java (revision 790584) +++ contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java (working copy) @@ -4,7 +4,7 @@ package org.apache.lucene.xmlparser.builders; import org.apache.lucene.search.Filter; -import org.apache.lucene.search.RangeFilter; +import org.apache.lucene.search.TermRangeFilter; import org.apache.lucene.xmlparser.DOMUtils; import org.apache.lucene.xmlparser.FilterBuilder; import org.apache.lucene.xmlparser.ParserException; @@ -39,7 +39,7 @@ String upperTerm=e.getAttribute("upperTerm"); boolean includeLower=DOMUtils.getAttribute(e,"includeLower",true); boolean includeUpper=DOMUtils.getAttribute(e,"includeUpper",true); - return new RangeFilter(fieldName,lowerTerm,upperTerm,includeLower,includeUpper); + return new TermRangeFilter(fieldName,lowerTerm,upperTerm,includeLower,includeUpper); } } Index: src/java/org/apache/lucene/document/DateField.java =================================================================== --- src/java/org/apache/lucene/document/DateField.java (revision 790584) +++ src/java/org/apache/lucene/document/DateField.java (working copy) @@ -18,7 +18,7 @@ */ import org.apache.lucene.search.PrefixQuery; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.NumericRangeQuery; // for javadocs import org.apache.lucene.util.NumericUtils; // for javadocs @@ -33,7 +33,7 @@ * which makes them suitable for use as field values and search terms. * *

Note that this class saves dates with millisecond granularity, - * which is bad for {@link RangeQuery} and {@link PrefixQuery}, as those + * which is bad for {@link TermRangeQuery} and {@link PrefixQuery}, as those * queries are expanded to a BooleanQuery with a potentially large number * of terms when searching. Thus you might want to use * {@link DateTools} instead. Index: src/java/org/apache/lucene/queryParser/QueryParser.java =================================================================== --- src/java/org/apache/lucene/queryParser/QueryParser.java (revision 790584) +++ src/java/org/apache/lucene/queryParser/QueryParser.java (working copy) @@ -31,7 +31,7 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.util.Parameter; @@ -71,7 +71,7 @@ *

* *

- * 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}. @@ -349,7 +349,7 @@ /** * By default QueryParser uses constant-score rewriting - * when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it + * when creating a PrefixQuery, WildcardQuery or TermRangeQuery. This implementation is generally preferable because it * a) Runs faster b) Does not have the scarcity of terms unduly influence score * c) avoids any "TooManyBooleanClauses" exception. * However, if your application really needs to use the @@ -877,22 +877,15 @@ } /** - * Builds a new RangeQuery instance + * Builds a new TermRangeQuery instance * @param field Field * @param part1 min * @param part2 max * @param inclusive true if range is inclusive - * @return new RangeQuery instance + * @return new TermRangeQuery instance */ protected Query newRangeQuery(String field, String part1, String part2, boolean inclusive) { - RangeQuery query; - - if (constantScoreRewrite) { - // TODO: remove in Lucene 3.0 - query = new ConstantScoreRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); - } else { - query = new RangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); - } + final TermRangeQuery query = new TermRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator); query.setConstantScoreRewrite(constantScoreRewrite); return query; } Index: src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java =================================================================== --- src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java (revision 790584) +++ src/java/org/apache/lucene/queryParser/QueryParserTokenManager.java (working copy) @@ -29,7 +29,6 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.util.Parameter; Index: src/java/org/apache/lucene/search/BooleanQuery.java =================================================================== --- src/java/org/apache/lucene/search/BooleanQuery.java (revision 790584) +++ src/java/org/apache/lucene/search/BooleanQuery.java (working copy) @@ -34,7 +34,7 @@ /** Thrown when an attempt is made to add more than {@link * #getMaxClauseCount()} clauses. This typically happens if - * a PrefixQuery, FuzzyQuery, WildcardQuery, or RangeQuery + * a PrefixQuery, FuzzyQuery, WildcardQuery, or TermRangeQuery * is expanded to many terms during search. */ public static class TooManyClauses extends RuntimeException { @@ -58,8 +58,8 @@ * so this parameter indirectly controls the maximum buffer requirements for * query search. *

When this parameter becomes a bottleneck for a Query one can use a - * Filter. For example instead of a {@link RangeQuery} one can use a - * {@link RangeFilter}. + * Filter. For example instead of a {@link TermRangeQuery} one can use a + * {@link TermRangeFilter}. *

Normally the buffers are allocated by the JVM. When using for example * {@link org.apache.lucene.store.MMapDirectory} the buffering is left to * the operating system. Index: src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java =================================================================== --- src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java (revision 790584) +++ src/java/org/apache/lucene/search/ConstantScoreRangeQuery.java (working copy) @@ -29,11 +29,11 @@ * 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.) * - * @deprecated Please use {@link RangeQuery}, and call - * {@link RangeQuery#setConstantScoreRewrite}, instead. + * @deprecated Please use {@link TermRangeQuery}, and call + * {@link TermRangeQuery#setConstantScoreRewrite}, instead. * @version $Id$ */ -public class ConstantScoreRangeQuery extends RangeQuery +public class ConstantScoreRangeQuery extends TermRangeQuery { public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) @@ -46,7 +46,7 @@ String upperVal, boolean includeLower, boolean includeUpper, Collator collator) { super(fieldName, lowerVal, upperVal, includeLower, includeUpper, collator); - this.constantScoreRewrite = true; + setConstantScoreRewrite(true); } public String getLowerVal() { Index: src/java/org/apache/lucene/search/FieldCacheRangeFilter.java =================================================================== --- src/java/org/apache/lucene/search/FieldCacheRangeFilter.java (revision 790584) +++ src/java/org/apache/lucene/search/FieldCacheRangeFilter.java (working copy) @@ -31,9 +31,9 @@ * even if the range itself changes. * *

This means that FieldCacheRangeFilter is much faster (sometimes more than 100x as fast) - * as building a {@link RangeFilter} (or {@link ConstantScoreRangeQuery} on a {@link RangeFilter}) + * as building a {@link TermRangeFilter} (or {@link ConstantScoreRangeQuery} on a {@link TermRangeFilter}) * for each query, if using a {@link #newStringRange}. However, if the range never changes it - * is slower (around 2x as slow) than building a CachingWrapperFilter on top of a single RangeFilter. + * is slower (around 2x as slow) than building a CachingWrapperFilter on top of a single TermRangeFilter. * * For numeric data types, this filter may be significantly faster than {@link NumericRangeFilter}. * Furthermore, it does not need the numeric values encoded by {@link NumericField}. But Index: src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java =================================================================== --- src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (revision 790584) +++ src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (working copy) @@ -34,7 +34,7 @@ * be used by itself. Normally you subclass it to provide a Filter * counterpart for a {@link MultiTermQuery} subclass. *

- * For example, {@link RangeFilter} and {@link PrefixFilter} extend + * For example, {@link TermRangeFilter} and {@link PrefixFilter} extend * MultiTermQueryWrapperFilter. * This class also provides the functionality behind * {@link MultiTermQuery#getFilter}, this is why it is not abstract. Index: src/java/org/apache/lucene/search/package.html =================================================================== --- src/java/org/apache/lucene/search/package.html (revision 790584) +++ src/java/org/apache/lucene/search/package.html (working copy) @@ -138,11 +138,11 @@

- RangeQuery + TermRangeQuery

The - RangeQuery + TermRangeQuery matches all documents that occur in the exclusive range of a lower Term Index: src/java/org/apache/lucene/search/Query.java =================================================================== --- src/java/org/apache/lucene/search/Query.java (revision 790584) +++ src/java/org/apache/lucene/search/Query.java (working copy) @@ -36,7 +36,8 @@

  • {@link PrefixQuery}
  • {@link MultiPhraseQuery}
  • {@link FuzzyQuery} -
  • {@link RangeQuery} +
  • {@link TermRangeQuery} +
  • {@link NumericRangeQuery}
  • {@link org.apache.lucene.search.spans.SpanQuery}

    A parser for queries is contained in: @@ -146,7 +147,7 @@ * correspondence with queries). This is an optimization of the OR of * all queries. We handle the common optimization cases of equal * queries and overlapping clauses of boolean OR queries (as generated - * by MultiTermQuery.rewrite() and RangeQuery.rewrite()). + * by MultiTermQuery.rewrite()). * Be careful overriding this method as queries[0] determines which * method will be called and is not necessarily of the same type as * the other queries. Index: src/java/org/apache/lucene/search/QueryWrapperFilter.java =================================================================== --- src/java/org/apache/lucene/search/QueryWrapperFilter.java (revision 790584) +++ src/java/org/apache/lucene/search/QueryWrapperFilter.java (working copy) @@ -26,10 +26,10 @@ * Constrains search results to only match those which also match a provided * query. * - *

    This could be used, for example, with a {@link RangeQuery} on a suitably + *

    This could be used, for example, with a {@link TermRangeQuery} on a suitably * formatted date field to implement date filtering. One could re-use a single * QueryFilter that matches, e.g., only documents modified within the last - * week. The QueryFilter and RangeQuery would only need to be reconstructed + * week. The QueryFilter and TermRangeQuery would only need to be reconstructed * once per day. * * @version $Id:$ Index: src/java/org/apache/lucene/search/RangeFilter.java =================================================================== --- src/java/org/apache/lucene/search/RangeFilter.java (revision 790584) +++ src/java/org/apache/lucene/search/RangeFilter.java (working copy) @@ -1,88 +0,0 @@ -package org.apache.lucene.search; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.text.Collator; - -/** - * A Filter that restricts search results to a range of values in a given - * field. - * - *

    This filter 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 NumericRangeFilter} instead. - * - *

    If you construct a large number of range filters with different ranges but on the - * same field, {@link FieldCacheRangeFilter} may have significantly better performance. - */ -public class RangeFilter extends MultiTermQueryWrapperFilter { - - /** - * @param fieldName The field this range applies to - * @param lowerTerm The lower bound on this range - * @param upperTerm The upper bound on this range - * @param includeLower Does this range include the lower bound? - * @param includeUpper Does this range include the upper bound? - * @throws IllegalArgumentException if both terms are null or if - * lowerTerm is null and includeLower is true (similar for upperTerm - * and includeUpper) - */ - public RangeFilter(String fieldName, String lowerTerm, String upperTerm, - boolean includeLower, boolean includeUpper) { - super(new RangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper)); - } - - /** - * WARNING: Using this constructor and supplying a non-null - * value in the collator 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. - * - * @param lowerTerm The lower bound on this range - * @param upperTerm The upper bound on this range - * @param includeLower Does this range include the lower bound? - * @param includeUpper Does this range include the upper bound? - * @param collator The collator to use when determining range inclusion; set - * to null to use Unicode code point ordering instead of collation. - * @throws IllegalArgumentException if both terms are null or if - * lowerTerm is null and includeLower is true (similar for upperTerm - * and includeUpper) - */ - public RangeFilter(String fieldName, String lowerTerm, String upperTerm, - boolean includeLower, boolean includeUpper, - Collator collator) { - super(new RangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator)); - } - - /** - * Constructs a filter for field fieldName matching - * less than or equal to upperTerm. - */ - public static RangeFilter Less(String fieldName, String upperTerm) { - return new RangeFilter(fieldName, null, upperTerm, false, true); - } - - /** - * Constructs a filter for field fieldName matching - * greater than or equal to lowerTerm. - */ - public static RangeFilter More(String fieldName, String lowerTerm) { - return new RangeFilter(fieldName, lowerTerm, null, true, false); - } -} Index: src/java/org/apache/lucene/search/RangeQuery.java =================================================================== --- src/java/org/apache/lucene/search/RangeQuery.java (revision 790584) +++ src/java/org/apache/lucene/search/RangeQuery.java (working copy) @@ -1,244 +0,0 @@ -package org.apache.lucene.search; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.IOException; -import java.text.Collator; - -import org.apache.lucene.index.Term; -import org.apache.lucene.index.IndexReader; - -/** - * A Query that matches documents within an exclusive 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. - * - *

    See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between - * enabling and disabling constantScoreRewrite mode. - */ - -public class RangeQuery extends MultiTermQuery { - private Term lowerTerm; - private Term upperTerm; - private Collator collator; - private String field; - private boolean includeLower; - private boolean includeUpper; - - - /** - * Constructs a query selecting all terms greater/equal than lowerTerm - * but less/equal than upperTerm. - * - *

    - * 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.) - * - * @param field The field that holds both lower and upper terms. - * @param lowerTerm - * The term text at the lower end of the range - * @param upperTerm - * The term text at the upper end of the range - * @param includeLower - * If true, the lowerTerm is - * included in the range. - * @param includeUpper - * If true, the upperTerm is - * included in the range. - */ - public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) { - init(new Term(field, lowerTerm), new Term(field, upperTerm), includeLower, includeUpper, null); - } - - /** Constructs a query selecting all terms greater/equal than - * lowerTerm but less/equal than upperTerm. - *

    - * 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.) - *

    - * If collator 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. - *

    - * WARNING: Using this constructor and supplying a non-null - * value in the collator 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. - * - * @param lowerTerm The Term text at the lower end of the range - * @param upperTerm The Term text at the upper end of the range - * @param includeLower - * If true, the lowerTerm is - * included in the range. - * @param includeUpper - * If true, the upperTerm is - * included in the range. - * @param collator The collator to use to collate index Terms, to determine - * their membership in the range bounded by lowerTerm and - * upperTerm. - */ - public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, - Collator collator) { - init(new Term(field, lowerTerm), new Term(field,upperTerm), includeLower, includeUpper, collator); - } - - /** @deprecated Please use {@link #RangeQuery(String, - * String, String, boolean, boolean, Collator)} instead */ - public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, - Collator collator) { - init(lowerTerm, upperTerm, inclusive, inclusive, collator); - } - - /** @deprecated Please use {@link #RangeQuery(String, - * String, String, boolean, boolean)} instead */ - public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) { - init(lowerTerm, upperTerm, inclusive, inclusive, null); - } - - private void init(Term lowerTerm, Term upperTerm, boolean includeLower, boolean includeUpper, Collator collator) { - if (lowerTerm == null && upperTerm == null) - throw new IllegalArgumentException("At least one term must be non-null"); - if (lowerTerm != null && upperTerm != null && lowerTerm.field() != upperTerm.field()) - throw new IllegalArgumentException("Both terms must be for the same field"); - - if (lowerTerm == null) - this.field = upperTerm.field(); - else - this.field = lowerTerm.field(); - this.lowerTerm = lowerTerm; - this.upperTerm = upperTerm; - this.includeLower = includeLower; - this.includeUpper = includeUpper; - this.collator = collator; - } - - /** Returns the field name for this query */ - public String getField() { - return field; - } - - /** Returns the lower term of this range query. - * @deprecated Use {@link #getLowerTermText} instead. */ - public Term getLowerTerm() { return lowerTerm; } - - /** Returns the upper term of this range query. - * @deprecated Use {@link #getUpperTermText} instead. */ - public Term getUpperTerm() { return upperTerm; } - - /** Returns the lower value of this range query */ - public String getLowerTermText() { return lowerTerm == null ? null : lowerTerm.text(); } - - /** Returns the upper value of this range query */ - public String getUpperTermText() { return upperTerm == null ? null : upperTerm.text(); } - - /** Returns true if the lower endpoint is inclusive */ - public boolean includesLower() { return includeLower; } - - /** Returns true if the upper endpoint is inclusive */ - public boolean includesUpper() { return includeUpper; } - - /** Returns true if the range query is inclusive - * @deprecated Use {@link #includesLower}, {@link #includesUpper} instead. - */ - public boolean isInclusive() { return includeUpper && includeLower; } - - /** Returns the collator used to determine range inclusion, if any. */ - public Collator getCollator() { return collator; } - - protected FilteredTermEnum getEnum(IndexReader reader) throws IOException { - //TODO: when the deprecated 'Term' constructors are removed we can remove these null checks - return new RangeTermEnum(reader, collator, getField(), lowerTerm == null ? null : lowerTerm.text(), - upperTerm == null ? null : upperTerm.text(), includeLower, includeUpper); - } - - /** Prints a user-readable version of this query. */ - public String toString(String field) { - StringBuffer buffer = new StringBuffer(); - if (!getField().equals(field)) { - buffer.append(getField()); - buffer.append(":"); - } - buffer.append(includeLower ? '[' : '{'); - buffer.append(lowerTerm != null ? lowerTerm.text() : "*"); - buffer.append(" TO "); - buffer.append(upperTerm != null ? upperTerm.text() : "*"); - buffer.append(includeUpper ? ']' : '}'); - if (getBoost() != 1.0f) { - buffer.append("^"); - buffer.append(Float.toString(getBoost())); - } - return buffer.toString(); - } - - //@Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((collator == null) ? 0 : collator.hashCode()); - result = prime * result + ((field == null) ? 0 : field.hashCode()); - result = prime * result + (includeLower ? 1231 : 1237); - result = prime * result + (includeUpper ? 1231 : 1237); - result = prime * result + ((lowerTerm == null) ? 0 : lowerTerm.hashCode()); - result = prime * result + ((upperTerm == null) ? 0 : upperTerm.hashCode()); - return result; - } - - //@Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - RangeQuery other = (RangeQuery) obj; - if (collator == null) { - if (other.collator != null) - return false; - } else if (!collator.equals(other.collator)) - return false; - if (field == null) { - if (other.field != null) - return false; - } else if (!field.equals(other.field)) - return false; - if (includeLower != other.includeLower) - return false; - if (includeUpper != other.includeUpper) - return false; - if (lowerTerm == null) { - if (other.lowerTerm != null) - return false; - } else if (!lowerTerm.equals(other.lowerTerm)) - return false; - if (upperTerm == null) { - if (other.upperTerm != null) - return false; - } else if (!upperTerm.equals(other.upperTerm)) - return false; - return true; - } - -} Index: src/java/org/apache/lucene/search/RangeTermEnum.java =================================================================== --- src/java/org/apache/lucene/search/RangeTermEnum.java (revision 790584) +++ src/java/org/apache/lucene/search/RangeTermEnum.java (working copy) @@ -1,149 +0,0 @@ -package org.apache.lucene.search; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.IOException; -import java.text.Collator; - -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; - -/** - * Subclass of FilteredTermEnum for enumerating all terms that match the - * specified range parameters. - *

    - * Term enumerations are always ordered by Term.compareTo(). Each term in - * the enumeration is greater than all that precede it. - */ -public class RangeTermEnum extends FilteredTermEnum { - - private Collator collator = null; - private boolean endEnum = false; - private String field; - private String upperTermText; - private String lowerTermText; - private boolean includeLower; - private boolean includeUpper; - - /** - * Enumerates all terms greater/equal than lowerTerm - * but less/equal than upperTerm. - * - * 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.) - * - * @param reader - * @param collator - * The collator to use to collate index Terms, to determine their - * membership in the range bounded by lowerTerm and - * upperTerm. - * @param field - * An interned field that holds both lower and upper terms. - * @param lowerTermText - * The term text at the lower end of the range - * @param upperTermText - * The term text at the upper end of the range - * @param includeLower - * If true, the lowerTerm is included in the range. - * @param includeUpper - * If true, the upperTerm is included in the range. - * - * @throws IOException - */ - public RangeTermEnum(IndexReader reader, Collator collator, String field, - String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper) throws IOException { - this.collator = collator; - this.upperTermText = upperTermText; - this.lowerTermText = lowerTermText; - this.includeLower = includeLower; - this.includeUpper = includeUpper; - this.field = field; - - // do a little bit of normalization... - // open ended range queries should always be inclusive. - if (this.lowerTermText == null) { - this.lowerTermText = ""; - this.includeLower = true; - } - - if (this.upperTermText == null) { - this.includeUpper = true; - } - - String startTermText = collator == null ? this.lowerTermText : ""; - setEnum(reader.terms(new Term(this.field, startTermText))); - } - - public float difference() { - return 1.0f; - } - - protected boolean endEnum() { - return endEnum; - } - - protected boolean termCompare(Term term) { - if (collator == null) { - // Use Unicode code point ordering - boolean checkLower = false; - if (!includeLower) // make adjustments to set to exclusive - checkLower = true; - if (term != null && term.field() == field) { // interned comparison - if (!checkLower || null==lowerTermText || term.text().compareTo(lowerTermText) > 0) { - checkLower = false; - if (upperTermText != null) { - int compare = upperTermText.compareTo(term.text()); - /* - * if beyond the upper term, or is exclusive and this is equal to - * the upper term, break out - */ - if ((compare < 0) || - (!includeUpper && compare==0)) { - endEnum = true; - return false; - } - } - return true; - } - } else { - // break - endEnum = true; - return false; - } - return false; - } else { - if (term != null && term.field() == field) { // interned comparison - if ((lowerTermText == null - || (includeLower - ? collator.compare(term.text(), lowerTermText) >= 0 - : collator.compare(term.text(), lowerTermText) > 0)) - && (upperTermText == null - || (includeUpper - ? collator.compare(term.text(), upperTermText) <= 0 - : collator.compare(term.text(), upperTermText) < 0))) { - return true; - } - return false; - } - endEnum = true; - return false; - } - } -} Index: src/java/org/apache/lucene/search/TermRangeFilter.java =================================================================== --- src/java/org/apache/lucene/search/TermRangeFilter.java (revision 790472) +++ src/java/org/apache/lucene/search/TermRangeFilter.java (working copy) @@ -30,59 +30,44 @@ *

    If you construct a large number of range filters with different ranges but on the * same field, {@link FieldCacheRangeFilter} may have significantly better performance. */ -public class RangeFilter extends MultiTermQueryWrapperFilter { +public class TermRangeFilter extends MultiTermQueryWrapperFilter { /** - * @param fieldName The field this range applies to - * @param lowerTerm The lower bound on this range - * @param upperTerm The upper bound on this range - * @param includeLower Does this range include the lower bound? - * @param includeUpper Does this range include the upper bound? - * @throws IllegalArgumentException if both terms are null or if - * lowerTerm is null and includeLower is true (similar for upperTerm - * and includeUpper) - */ - public RangeFilter(String fieldName, String lowerTerm, String upperTerm, - boolean includeLower, boolean includeUpper) { - super(new RangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper)); - } + * @param fieldName The field this range applies to + * @param lowerTerm The lower bound on this range + * @param upperTerm The upper bound on this range + * @param includeLower Does this range include the lower bound? + * @param includeUpper Does this range include the upper bound? + * @throws IllegalArgumentException if both terms are null or if + * lowerTerm is null and includeLower is true (similar for upperTerm + * and includeUpper) + */ + public TermRangeFilter(String fieldName, String lowerTerm, String upperTerm, + boolean includeLower, boolean includeUpper) { + super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper)); + } - /** - * WARNING: Using this constructor and supplying a non-null - * value in the collator 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. - * - * @param lowerTerm The lower bound on this range - * @param upperTerm The upper bound on this range - * @param includeLower Does this range include the lower bound? - * @param includeUpper Does this range include the upper bound? - * @param collator The collator to use when determining range inclusion; set - * to null to use Unicode code point ordering instead of collation. - * @throws IllegalArgumentException if both terms are null or if - * lowerTerm is null and includeLower is true (similar for upperTerm - * and includeUpper) - */ - public RangeFilter(String fieldName, String lowerTerm, String upperTerm, - boolean includeLower, boolean includeUpper, - Collator collator) { - super(new RangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator)); - } + /** + * WARNING: Using this constructor and supplying a non-null + * value in the collator 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. + * + * @param lowerTerm The lower bound on this range + * @param upperTerm The upper bound on this range + * @param includeLower Does this range include the lower bound? + * @param includeUpper Does this range include the upper bound? + * @param collator The collator to use when determining range inclusion; set + * to null to use Unicode code point ordering instead of collation. + * @throws IllegalArgumentException if both terms are null or if + * lowerTerm is null and includeLower is true (similar for upperTerm + * and includeUpper) + */ + public TermRangeFilter(String fieldName, String lowerTerm, String upperTerm, + boolean includeLower, boolean includeUpper, + Collator collator) { + super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator)); + } - /** - * Constructs a filter for field fieldName matching - * less than or equal to upperTerm. - */ - public static RangeFilter Less(String fieldName, String upperTerm) { - return new RangeFilter(fieldName, null, upperTerm, false, true); - } - - /** - * Constructs a filter for field fieldName matching - * greater than or equal to lowerTerm. - */ - public static RangeFilter More(String fieldName, String lowerTerm) { - return new RangeFilter(fieldName, lowerTerm, null, true, false); - } } Index: src/java/org/apache/lucene/search/TermRangeQuery.java =================================================================== --- src/java/org/apache/lucene/search/TermRangeQuery.java (revision 790472) +++ src/java/org/apache/lucene/search/TermRangeQuery.java (working copy) @@ -24,19 +24,20 @@ import org.apache.lucene.index.IndexReader; /** - * A Query that matches documents within an exclusive range. + * 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 * for numerical ranges, use {@link NumericRangeQuery} instead. * - *

    See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between + *

    This query is in constant score mode per default. + * See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between * enabling and disabling constantScoreRewrite mode. */ -public class RangeQuery extends MultiTermQuery { - private Term lowerTerm; - private Term upperTerm; +public class TermRangeQuery extends MultiTermQuery { + private String lowerTerm; + private String upperTerm; private Collator collator; private String field; private boolean includeLower; @@ -65,8 +66,8 @@ * If true, the upperTerm is * included in the range. */ - public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) { - init(new Term(field, lowerTerm), new Term(field, upperTerm), includeLower, includeUpper, null); + public TermRangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) { + this(field, lowerTerm, upperTerm, includeLower, includeUpper, null); } /** Constructs a query selecting all terms greater/equal than @@ -99,59 +100,27 @@ * their membership in the range bounded by lowerTerm and * upperTerm. */ - public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, + public TermRangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper, Collator collator) { - init(new Term(field, lowerTerm), new Term(field,upperTerm), includeLower, includeUpper, collator); - } - - /** @deprecated Please use {@link #RangeQuery(String, - * String, String, boolean, boolean, Collator)} instead */ - public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, - Collator collator) { - init(lowerTerm, upperTerm, inclusive, inclusive, collator); - } - - /** @deprecated Please use {@link #RangeQuery(String, - * String, String, boolean, boolean)} instead */ - public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) { - init(lowerTerm, upperTerm, inclusive, inclusive, null); - } - - private void init(Term lowerTerm, Term upperTerm, boolean includeLower, boolean includeUpper, Collator collator) { - if (lowerTerm == null && upperTerm == null) - throw new IllegalArgumentException("At least one term must be non-null"); - if (lowerTerm != null && upperTerm != null && lowerTerm.field() != upperTerm.field()) - throw new IllegalArgumentException("Both terms must be for the same field"); - - if (lowerTerm == null) - this.field = upperTerm.field(); - else - this.field = lowerTerm.field(); + this.field = field; this.lowerTerm = lowerTerm; this.upperTerm = upperTerm; this.includeLower = includeLower; this.includeUpper = includeUpper; this.collator = collator; + setConstantScoreRewrite(true); } - + /** Returns the field name for this query */ public String getField() { return field; } - - /** Returns the lower term of this range query. - * @deprecated Use {@link #getLowerTermText} instead. */ - public Term getLowerTerm() { return lowerTerm; } - - /** Returns the upper term of this range query. - * @deprecated Use {@link #getUpperTermText} instead. */ - public Term getUpperTerm() { return upperTerm; } /** Returns the lower value of this range query */ - public String getLowerTermText() { return lowerTerm == null ? null : lowerTerm.text(); } + public String getLowerTermText() { return lowerTerm; } /** Returns the upper value of this range query */ - public String getUpperTermText() { return upperTerm == null ? null : upperTerm.text(); } + public String getUpperTermText() { return upperTerm; } /** Returns true if the lower endpoint is inclusive */ public boolean includesLower() { return includeLower; } @@ -159,18 +128,12 @@ /** Returns true if the upper endpoint is inclusive */ public boolean includesUpper() { return includeUpper; } - /** Returns true if the range query is inclusive - * @deprecated Use {@link #includesLower}, {@link #includesUpper} instead. - */ - public boolean isInclusive() { return includeUpper && includeLower; } - /** Returns the collator used to determine range inclusion, if any. */ public Collator getCollator() { return collator; } protected FilteredTermEnum getEnum(IndexReader reader) throws IOException { - //TODO: when the deprecated 'Term' constructors are removed we can remove these null checks - return new RangeTermEnum(reader, collator, getField(), lowerTerm == null ? null : lowerTerm.text(), - upperTerm == null ? null : upperTerm.text(), includeLower, includeUpper); + return new TermRangeTermEnum(reader, collator, field, lowerTerm, + upperTerm, includeLower, includeUpper); } /** Prints a user-readable version of this query. */ @@ -181,9 +144,9 @@ buffer.append(":"); } buffer.append(includeLower ? '[' : '{'); - buffer.append(lowerTerm != null ? lowerTerm.text() : "*"); + buffer.append(lowerTerm != null ? lowerTerm : "*"); buffer.append(" TO "); - buffer.append(upperTerm != null ? upperTerm.text() : "*"); + buffer.append(upperTerm != null ? upperTerm : "*"); buffer.append(includeUpper ? ']' : '}'); if (getBoost() != 1.0f) { buffer.append("^"); @@ -213,7 +176,7 @@ return false; if (getClass() != obj.getClass()) return false; - RangeQuery other = (RangeQuery) obj; + TermRangeQuery other = (TermRangeQuery) obj; if (collator == null) { if (other.collator != null) return false; Index: src/java/org/apache/lucene/search/TermRangeTermEnum.java =================================================================== --- src/java/org/apache/lucene/search/TermRangeTermEnum.java (revision 790472) +++ src/java/org/apache/lucene/search/TermRangeTermEnum.java (working copy) @@ -1,5 +1,22 @@ package org.apache.lucene.search; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import java.io.IOException; import java.text.Collator; @@ -13,7 +30,7 @@ * Term enumerations are always ordered by Term.compareTo(). Each term in * the enumeration is greater than all that precede it. */ -public class RangeTermEnum extends FilteredTermEnum { +public class TermRangeTermEnum extends FilteredTermEnum { private Collator collator = null; private boolean endEnum = false; @@ -50,14 +67,14 @@ * * @throws IOException */ - public RangeTermEnum(IndexReader reader, Collator collator, String field, + public TermRangeTermEnum(IndexReader reader, Collator collator, String field, String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper) throws IOException { this.collator = collator; this.upperTermText = upperTermText; this.lowerTermText = lowerTermText; this.includeLower = includeLower; this.includeUpper = includeUpper; - this.field = field; + this.field = field.intern(); // do a little bit of normalization... // open ended range queries should always be inclusive. Index: src/test/org/apache/lucene/queryParser/TestQueryParser.java =================================================================== --- src/test/org/apache/lucene/queryParser/TestQueryParser.java (revision 790584) +++ src/test/org/apache/lucene/queryParser/TestQueryParser.java (working copy) @@ -50,7 +50,7 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.search.RangeQuery; +import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.WildcardQuery; @@ -431,11 +431,11 @@ public void testRange() throws Exception { assertQueryEquals("[ a TO z]", null, "[a TO z]"); - assertTrue(((RangeQuery)getQuery("[ a TO z]", null)).getConstantScoreRewrite()); + assertTrue(((TermRangeQuery)getQuery("[ a TO z]", null)).getConstantScoreRewrite()); QueryParser qp = new QueryParser("field", new SimpleAnalyzer()); qp.setConstantScoreRewrite(false); - assertFalse(((RangeQuery)qp.parse("[ a TO z]")).getConstantScoreRewrite()); + assertFalse(((TermRangeQuery)qp.parse("[ a TO z]")).getConstantScoreRewrite()); assertQueryEquals("[ a TO z ]", null, "[a TO z]"); assertQueryEquals("{ a TO z}", null, "{a TO z}"); @@ -481,7 +481,7 @@ result = is.search(qp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, result.length); - // Test RangeQuery + // Test TermRangeQuery qp.setConstantScoreRewrite(false); result = is.search(qp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, result.length); Index: src/test/org/apache/lucene/search/TestDateFilter.java =================================================================== --- src/test/org/apache/lucene/search/TestDateFilter.java (revision 790584) +++ src/test/org/apache/lucene/search/TestDateFilter.java (working copy) @@ -66,11 +66,11 @@ // filter that should preserve matches //DateFilter df1 = DateFilter.Before("datefield", now); - RangeFilter df1 = new RangeFilter("datefield", DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), + TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), false, true); // filter that should discard matches //DateFilter df2 = DateFilter.Before("datefield", now - 999999); - RangeFilter df2 = new RangeFilter("datefield", DateTools.timeToString(0, DateTools.Resolution.MILLISECOND), + TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.timeToString(0, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), true, false); // search something that doesn't exist with DateFilter @@ -127,11 +127,11 @@ // filter that should preserve matches //DateFilter df1 = DateFilter.After("datefield", now); - RangeFilter df1 = new RangeFilter("datefield", DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), + TermRangeFilter df1 = new TermRangeFilter("datefield", DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), true, false); // filter that should discard matches //DateFilter df2 = DateFilter.After("datefield", now + 999999); - RangeFilter df2 = new RangeFilter("datefield", DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), + TermRangeFilter df2 = new TermRangeFilter("datefield", DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), DateTools.timeToString(now + 999999999, DateTools.Resolution.MILLISECOND), false, true); // search something that doesn't exist with DateFilter Index: src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java =================================================================== --- src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java (revision 790584) +++ src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java (working copy) @@ -30,7 +30,7 @@ import org.apache.lucene.store.RAMDirectory; /** - * A basic 'positive' Unit test class for the RangeFilter class. + * A basic 'positive' Unit test class for the FieldCacheRangeFilter class. * *

    * NOTE: at the moment, this class only tests for 'positive' results, Index: src/test/org/apache/lucene/search/TestFilteredQuery.java =================================================================== --- src/test/org/apache/lucene/search/TestFilteredQuery.java (revision 790584) +++ src/test/org/apache/lucene/search/TestFilteredQuery.java (working copy) @@ -177,8 +177,8 @@ * This tests FilteredQuery's rewrite correctness */ public void testRangeQuery() throws Exception { - RangeQuery rq = new RangeQuery( - new Term("sorter", "b"), new Term("sorter", "d"), true); + TermRangeQuery rq = new TermRangeQuery( + "sorter", "b", "d", true, true); Query filteredquery = new FilteredQuery(rq, filter); ScoreDoc[] hits = searcher.search(filteredquery, null, 1000).scoreDocs; Index: src/test/org/apache/lucene/search/TestMultiTermConstantScore.java =================================================================== --- src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (revision 790584) +++ src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (working copy) @@ -87,7 +87,7 @@ /** macro for readability */ public static Query csrq(String f, String l, String h, boolean il, boolean ih) { - RangeQuery query = new RangeQuery(f, l, h, il, ih); + TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih); query.setConstantScoreRewrite(true); return query; } @@ -95,7 +95,7 @@ /** macro for readability */ public static Query csrq(String f, String l, String h, boolean il, boolean ih, Collator c) { - RangeQuery query = new RangeQuery(f, l, h, il, ih, c); + TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih, c); query.setConstantScoreRewrite(true); return query; } @@ -220,10 +220,10 @@ IndexReader reader = IndexReader.open(small); IndexSearcher search = new IndexSearcher(reader); - // first do a regular RangeQuery which uses term expansion so + // first do a regular TermRangeQuery which uses term expansion so // docs with more terms in range get higher scores - Query rq = new RangeQuery(new Term("data", "1"), new Term("data", "4"), T); + Query rq = new TermRangeQuery("data", "1", "4", T, T); ScoreDoc[] expected = search.search(rq, null, 1000).scoreDocs; int numHits = expected.length; Index: src/test/org/apache/lucene/search/TestNumericRangeQuery32.java =================================================================== --- src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (revision 790584) +++ src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (working copy) @@ -226,38 +226,38 @@ } // test inclusive range NumericRangeQuery tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), true, true); - RangeQuery cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, true); + TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, true); cq.setConstantScoreRewrite(true); TopDocs tTopDocs = searcher.search(tq, 1); TopDocs cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test exclusive range tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), false, false); - cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, false); + cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test left exclusive range tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), false, true); - cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, true); + cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), false, true); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test right exclusive range tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), true, false); - cq=new RangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, false); + cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper), true, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); } Index: src/test/org/apache/lucene/search/TestNumericRangeQuery64.java =================================================================== --- src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (revision 790584) +++ src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (working copy) @@ -226,38 +226,38 @@ } // test inclusive range NumericRangeQuery tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), true, true); - RangeQuery cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, true); + TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, true); cq.setConstantScoreRewrite(true); TopDocs tTopDocs = searcher.search(tq, 1); TopDocs cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test exclusive range tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), false, false); - cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, false); + cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test left exclusive range tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), false, true); - cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, true); + cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, true); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); // test right exclusive range tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), true, false); - cq=new RangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, false); + cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, false); cq.setConstantScoreRewrite(true); tTopDocs = searcher.search(tq, 1); cTopDocs = searcher.search(cq, 1); - assertEquals("Returned count for NumericRangeQuery and RangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); + assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits ); termCountT += tq.getTotalNumberOfTerms(); termCountC += cq.getTotalNumberOfTerms(); } Index: src/test/org/apache/lucene/search/TestRangeFilter.java =================================================================== --- src/test/org/apache/lucene/search/TestRangeFilter.java (revision 790584) +++ src/test/org/apache/lucene/search/TestRangeFilter.java (working copy) @@ -30,7 +30,7 @@ import org.apache.lucene.store.RAMDirectory; /** - * A basic 'positive' Unit test class for the RangeFilter class. + * A basic 'positive' Unit test class for the TermRangeFilter class. * *

    * NOTE: at the moment, this class only tests for 'positive' results, @@ -67,64 +67,64 @@ // test id, bounded on both ends - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,T), numDocs).scoreDocs; assertEquals("find all", numDocs, result.length); - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,F), numDocs).scoreDocs; assertEquals("all but last", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,T), numDocs).scoreDocs; assertEquals("all but first", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,F), numDocs).scoreDocs; assertEquals("all but ends", numDocs-2, result.length); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,T), numDocs).scoreDocs; assertEquals("med and up", 1+ maxId-medId, result.length); - result = search.search(q,new RangeFilter("id",minIP,medIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,medIP,T,T), numDocs).scoreDocs; assertEquals("up to med", 1+ medId-minId, result.length); // unbounded id - result = search.search(q,new RangeFilter("id",minIP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,null,T,F), numDocs).scoreDocs; assertEquals("min and up", numDocs, result.length); - result = search.search(q,new RangeFilter("id",null,maxIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,T), numDocs).scoreDocs; assertEquals("max and down", numDocs, result.length); - result = search.search(q,new RangeFilter("id",minIP,null,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,null,F,F), numDocs).scoreDocs; assertEquals("not min, but up", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",null,maxIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,F), numDocs).scoreDocs; assertEquals("not max, but down", numDocs-1, result.length); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,F), numDocs).scoreDocs; assertEquals("med and up, not max", maxId-medId, result.length); - result = search.search(q,new RangeFilter("id",minIP,medIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,medIP,F,T), numDocs).scoreDocs; assertEquals("not min, up to med", medId-minId, result.length); // very small sets - result = search.search(q,new RangeFilter("id",minIP,minIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,minIP,F,F), numDocs).scoreDocs; assertEquals("min,min,F,F", 0, result.length); - result = search.search(q,new RangeFilter("id",medIP,medIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,medIP,F,F), numDocs).scoreDocs; assertEquals("med,med,F,F", 0, result.length); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,F,F), numDocs).scoreDocs; assertEquals("max,max,F,F", 0, result.length); - result = search.search(q,new RangeFilter("id",minIP,minIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",minIP,minIP,T,T), numDocs).scoreDocs; assertEquals("min,min,T,T", 1, result.length); - result = search.search(q,new RangeFilter("id",null,minIP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",null,minIP,F,T), numDocs).scoreDocs; assertEquals("nul,min,F,T", 1, result.length); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,T,T), numDocs).scoreDocs; assertEquals("max,max,T,T", 1, result.length); - result = search.search(q,new RangeFilter("id",maxIP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",maxIP,null,T,F), numDocs).scoreDocs; assertEquals("max,nul,T,T", 1, result.length); - result = search.search(q,new RangeFilter("id",medIP,medIP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("id",medIP,medIP,T,T), numDocs).scoreDocs; assertEquals("med,med,T,T", 1, result.length); } @@ -151,64 +151,64 @@ // test id, bounded on both ends - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,T,c)); assertEquals("find all", numDocs, result.length()); - result = search.search(q,new RangeFilter("id",minIP,maxIP,T,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,F,c)); assertEquals("all but last", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,T,c)); assertEquals("all but first", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",minIP,maxIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,F,c)); assertEquals("all but ends", numDocs-2, result.length()); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,T,c)); assertEquals("med and up", 1+ maxId-medId, result.length()); - result = search.search(q,new RangeFilter("id",minIP,medIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,medIP,T,T,c)); assertEquals("up to med", 1+ medId-minId, result.length()); // unbounded id - result = search.search(q,new RangeFilter("id",minIP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,null,T,F,c)); assertEquals("min and up", numDocs, result.length()); - result = search.search(q,new RangeFilter("id",null,maxIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,T,c)); assertEquals("max and down", numDocs, result.length()); - result = search.search(q,new RangeFilter("id",minIP,null,F,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,null,F,F,c)); assertEquals("not min, but up", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",null,maxIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",null,maxIP,F,F,c)); assertEquals("not max, but down", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("id",medIP,maxIP,T,F,c)); + result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,F,c)); assertEquals("med and up, not max", maxId-medId, result.length()); - result = search.search(q,new RangeFilter("id",minIP,medIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,medIP,F,T,c)); assertEquals("not min, up to med", medId-minId, result.length()); // very small sets - result = search.search(q,new RangeFilter("id",minIP,minIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",minIP,minIP,F,F,c)); assertEquals("min,min,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("id",medIP,medIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",medIP,medIP,F,F,c)); assertEquals("med,med,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,F,F,c)); + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,F,F,c)); assertEquals("max,max,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("id",minIP,minIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",minIP,minIP,T,T,c)); assertEquals("min,min,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",null,minIP,F,T,c)); + result = search.search(q,new TermRangeFilter("id",null,minIP,F,T,c)); assertEquals("nul,min,F,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",maxIP,maxIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,T,T,c)); assertEquals("max,max,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",maxIP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("id",maxIP,null,T,F,c)); assertEquals("max,nul,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("id",medIP,medIP,T,T,c)); + result = search.search(q,new TermRangeFilter("id",medIP,medIP,T,T,c)); assertEquals("med,med,T,T", 1, result.length()); } @@ -229,47 +229,47 @@ // test extremes, bounded on both ends - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,T), numDocs).scoreDocs; assertEquals("find all", numDocs, result.length); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,F), numDocs).scoreDocs; assertEquals("all but biggest", numDocs-1, result.length); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,T), numDocs).scoreDocs; assertEquals("all but smallest", numDocs-1, result.length); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,F), numDocs).scoreDocs; assertEquals("all but extremes", numDocs-2, result.length); // unbounded - result = search.search(q,new RangeFilter("rand",minRP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,null,T,F), numDocs).scoreDocs; assertEquals("smallest and up", numDocs, result.length); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,T), numDocs).scoreDocs; assertEquals("biggest and down", numDocs, result.length); - result = search.search(q,new RangeFilter("rand",minRP,null,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,null,F,F), numDocs).scoreDocs; assertEquals("not smallest, but up", numDocs-1, result.length); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,F), numDocs).scoreDocs; assertEquals("not biggest, but down", numDocs-1, result.length); // very small sets - result = search.search(q,new RangeFilter("rand",minRP,minRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,F,F), numDocs).scoreDocs; assertEquals("min,min,F,F", 0, result.length); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,F,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,F,F), numDocs).scoreDocs; assertEquals("max,max,F,F", 0, result.length); - result = search.search(q,new RangeFilter("rand",minRP,minRP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,T,T), numDocs).scoreDocs; assertEquals("min,min,T,T", 1, result.length); - result = search.search(q,new RangeFilter("rand",null,minRP,F,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",null,minRP,F,T), numDocs).scoreDocs; assertEquals("nul,min,F,T", 1, result.length); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,T,T), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,T,T), numDocs).scoreDocs; assertEquals("max,max,T,T", 1, result.length); - result = search.search(q,new RangeFilter("rand",maxRP,null,T,F), numDocs).scoreDocs; + result = search.search(q,new TermRangeFilter("rand",maxRP,null,T,F), numDocs).scoreDocs; assertEquals("max,nul,T,T", 1, result.length); } @@ -294,47 +294,47 @@ // test extremes, bounded on both ends - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,T,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,T,c)); assertEquals("find all", numDocs, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,F,c)); assertEquals("all but biggest", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,T,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,T,c)); assertEquals("all but smallest", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,F,c)); assertEquals("all but extremes", numDocs-2, result.length()); // unbounded - result = search.search(q,new RangeFilter("rand",minRP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,null,T,F,c)); assertEquals("smallest and up", numDocs, result.length()); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,T,c)); + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,T,c)); assertEquals("biggest and down", numDocs, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,null,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,null,F,F,c)); assertEquals("not smallest, but up", numDocs-1, result.length()); - result = search.search(q,new RangeFilter("rand",null,maxRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,F,c)); assertEquals("not biggest, but down", numDocs-1, result.length()); // very small sets - result = search.search(q,new RangeFilter("rand",minRP,minRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,F,F,c)); assertEquals("min,min,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,F,F,c)); + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,F,F,c)); assertEquals("max,max,F,F", 0, result.length()); - result = search.search(q,new RangeFilter("rand",minRP,minRP,T,T,c)); + result = search.search(q,new TermRangeFilter("rand",minRP,minRP,T,T,c)); assertEquals("min,min,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("rand",null,minRP,F,T,c)); + result = search.search(q,new TermRangeFilter("rand",null,minRP,F,T,c)); assertEquals("nul,min,F,T", 1, result.length()); - result = search.search(q,new RangeFilter("rand",maxRP,maxRP,T,T,c)); + result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,T,T,c)); assertEquals("max,max,T,T", 1, result.length()); - result = search.search(q,new RangeFilter("rand",maxRP,null,T,F,c)); + result = search.search(q,new TermRangeFilter("rand",maxRP,null,T,F,c)); assertEquals("max,nul,T,T", 1, result.length()); } @@ -365,14 +365,14 @@ // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi // orders the U+0698 character before the U+0633 character, so the single - // index Term below should NOT be returned by a RangeFilter with a Farsi + // index Term below should NOT be returned by a TermRangeFilter with a Farsi // Collator (or an Arabic one for the case when Farsi is not supported). Hits result = search.search - (q, new RangeFilter("content", "\u062F", "\u0698", T, T, collator)); + (q, new TermRangeFilter("content", "\u062F", "\u0698", T, T, collator)); assertEquals("The index Term should not be included.", 0, result.length()); result = search.search - (q, new RangeFilter("content", "\u0633", "\u0638", T, T, collator)); + (q, new TermRangeFilter("content", "\u0633", "\u0638", T, T, collator)); assertEquals("The index Term should be included.", 1, result.length()); search.close(); } @@ -403,17 +403,17 @@ Query q = new TermQuery(new Term("body","body")); Collator collator = Collator.getInstance(new Locale("da", "dk")); - Query query = new RangeQuery + Query query = new TermRangeQuery ("content", "H\u00D8T", "MAND", false, false, collator); // Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ], // but Danish collation does. Hits result = search.search - (q, new RangeFilter("content", "H\u00D8T", "MAND", F, F, collator)); + (q, new TermRangeFilter("content", "H\u00D8T", "MAND", F, F, collator)); assertEquals("The index Term should be included.", 1, result.length()); result = search.search - (q, new RangeFilter("content", "H\u00C5T", "MAND", F, F, collator)); + (q, new TermRangeFilter("content", "H\u00C5T", "MAND", F, F, collator)); assertEquals ("The index Term should not be included.", 0, result.length()); search.close(); Index: src/test/org/apache/lucene/search/TestRangeQuery.java =================================================================== --- src/test/org/apache/lucene/search/TestRangeQuery.java (revision 790584) +++ src/test/org/apache/lucene/search/TestRangeQuery.java (working copy) @@ -46,7 +46,7 @@ } public void testExclusive() throws Exception { - Query query = new RangeQuery("content", "A", "C", false, false); + Query query = new TermRangeQuery("content", "A", "C", false, false); initializeIndex(new String[] {"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; @@ -84,7 +84,7 @@ } public void testInclusive() throws Exception { - Query query = new RangeQuery("content", "A", "C", true, true); + Query query = new TermRangeQuery("content", "A", "C", true, true); initializeIndex(new String[]{"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); @@ -106,10 +106,10 @@ } public void testEqualsHashcode() { - Query query = new RangeQuery("content", "A", "C", true, true); + Query query = new TermRangeQuery("content", "A", "C", true, true); query.setBoost(1.0f); - Query other = new RangeQuery("content", "A", "C", true, true); + Query other = new TermRangeQuery("content", "A", "C", true, true); other.setBoost(1.0f); assertEquals("query equals itself is true", query, query); @@ -119,40 +119,40 @@ other.setBoost(2.0f); assertFalse("Different boost queries are not equal", query.equals(other)); - other = new RangeQuery("notcontent", "A", "C", true, true); + other = new TermRangeQuery("notcontent", "A", "C", true, true); assertFalse("Different fields are not equal", query.equals(other)); - other = new RangeQuery("content", "X", "C", true, true); + other = new TermRangeQuery("content", "X", "C", true, true); assertFalse("Different lower terms are not equal", query.equals(other)); - other = new RangeQuery("content", "A", "Z", true, true); + other = new TermRangeQuery("content", "A", "Z", true, true); assertFalse("Different upper terms are not equal", query.equals(other)); - query = new RangeQuery("content", null, "C", true, true); - other = new RangeQuery("content", null, "C", true, true); + query = new TermRangeQuery("content", null, "C", true, true); + other = new TermRangeQuery("content", null, "C", true, true); assertEquals("equivalent queries with null lowerterms are equal()", query, other); assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode()); - query = new RangeQuery("content", "C", null, true, true); - other = new RangeQuery("content", "C", null, true, true); + query = new TermRangeQuery("content", "C", null, true, true); + other = new TermRangeQuery("content", "C", null, true, true); assertEquals("equivalent queries with null upperterms are equal()", query, other); assertEquals("hashcode returns same value", query.hashCode(), other.hashCode()); - query = new RangeQuery("content", null, "C", true, true); - other = new RangeQuery("content", "C", null, true, true); + query = new TermRangeQuery("content", null, "C", true, true); + other = new TermRangeQuery("content", "C", null, true, true); assertFalse("queries with different upper and lower terms are not equal", query.equals(other)); - query = new RangeQuery("content", "A", "C", false, false); - other = new RangeQuery("content", "A", "C", true, true); + query = new TermRangeQuery("content", "A", "C", false, false); + other = new TermRangeQuery("content", "A", "C", true, true); assertFalse("queries with different inclusive are not equal", query.equals(other)); - query = new RangeQuery("content", "A", "C", false, false); - other = new RangeQuery("content", "A", "C", false, false, Collator.getInstance()); + query = new TermRangeQuery("content", "A", "C", false, false); + other = new TermRangeQuery("content", "A", "C", false, false, Collator.getInstance()); assertFalse("a query with a collator is not equal to one without", query.equals(other)); } public void testExclusiveCollating() throws Exception { - Query query = new RangeQuery("content", "A", "C", false, false, Collator.getInstance(Locale.ENGLISH)); + Query query = new TermRangeQuery("content", "A", "C", false, false, Collator.getInstance(Locale.ENGLISH)); initializeIndex(new String[] {"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; @@ -173,7 +173,7 @@ } public void testInclusiveCollating() throws Exception { - Query query = new RangeQuery("content", "A", "C",true, true, Collator.getInstance(Locale.ENGLISH)); + Query query = new TermRangeQuery("content", "A", "C",true, true, Collator.getInstance(Locale.ENGLISH)); initializeIndex(new String[]{"A", "B", "C", "D"}); IndexSearcher searcher = new IndexSearcher(dir); @@ -199,17 +199,17 @@ // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi // characters properly. Collator collator = Collator.getInstance(new Locale("ar")); - Query query = new RangeQuery("content", "\u062F", "\u0698", true, true, collator); + Query query = new TermRangeQuery("content", "\u062F", "\u0698", true, true, collator); // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi // orders the U+0698 character before the U+0633 character, so the single - // index Term below should NOT be returned by a RangeQuery with a Farsi + // index Term below should NOT be returned by a TermRangeQuery with a Farsi // Collator (or an Arabic one for the case when Farsi is not supported). initializeIndex(new String[]{ "\u0633\u0627\u0628"}); IndexSearcher searcher = new IndexSearcher(dir); ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, hits.length); - query = new RangeQuery("content", "\u0633", "\u0638",true, true, collator); + query = new TermRangeQuery("content", "\u0633", "\u0638",true, true, collator); hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, hits.length); searcher.close(); @@ -220,7 +220,7 @@ // Danish collation orders the words below in the given order (example taken // from TestSort.testInternationalSort() ). String[] words = { "H\u00D8T", "H\u00C5T", "MAND" }; - Query query = new RangeQuery("content", "H\u00D8T", "MAND", false, false, collator); + Query query = new TermRangeQuery("content", "H\u00D8T", "MAND", false, false, collator); // Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ], // but Danish collation does. @@ -229,7 +229,7 @@ ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should be included.", 1, hits.length); - query = new RangeQuery("content", "H\u00C5T", "MAND", false, false, collator); + query = new TermRangeQuery("content", "H\u00C5T", "MAND", false, false, collator); hits = searcher.search(query, null, 1000).scoreDocs; assertEquals("The index Term should not be included.", 0, hits.length); searcher.close(); @@ -315,9 +315,8 @@ public void testExclusiveLowerNull() throws Exception { Analyzer analyzer = new SingleCharAnalyzer(); //http://issues.apache.org/jira/browse/LUCENE-38 - Query query = new RangeQuery(null, - new Term("content", "C"), - false); + Query query = new TermRangeQuery("content", null, "C", + false, false); initializeIndex(new String[] {"A", "B", "", "C", "D"}, analyzer); IndexSearcher searcher = new IndexSearcher(dir); Hits hits = searcher.search(query); @@ -349,9 +348,7 @@ public void testInclusiveLowerNull() throws Exception { //http://issues.apache.org/jira/browse/LUCENE-38 Analyzer analyzer = new SingleCharAnalyzer(); - Query query = new RangeQuery(null, - new Term("content", "C"), - true); + Query query = new TermRangeQuery("content", null, "C", true, true); initializeIndex(new String[]{"A", "B", "","C", "D"}, analyzer); IndexSearcher searcher = new IndexSearcher(dir); Hits hits = searcher.search(query);