mirror of https://github.com/apache/lucene.git
LUCENE-1713: Rename RangeQuery -> TermRangeQuery (part 1)
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@791175 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3442865534
commit
fed4bba63d
|
@ -67,7 +67,8 @@ Step 3) Install JavaCC
|
||||||
|
|
||||||
Building the Lucene distribution from the source does not require the JavaCC
|
Building the Lucene distribution from the source does not require the JavaCC
|
||||||
parser generator, but if you wish to regenerate any of the pre-generated
|
parser generator, but if you wish to regenerate any of the pre-generated
|
||||||
parser pieces, you will need to install JavaCC.
|
parser pieces, you will need to install JavaCC. Version 4.1 is tested to
|
||||||
|
work correctly.
|
||||||
|
|
||||||
http://javacc.dev.java.net
|
http://javacc.dev.java.net
|
||||||
|
|
||||||
|
|
|
@ -281,6 +281,12 @@ API Changes
|
||||||
includes more detailed status than previously. (Tim Smith via
|
includes more detailed status than previously. (Tim Smith via
|
||||||
Mike McCandless)
|
Mike McCandless)
|
||||||
|
|
||||||
|
28. LUCENE-1713: Deprecated RangeQuery and RangeFilter and renamed
|
||||||
|
to TermRangeQuery and TermRangeFilter. TermRangeQuery is in
|
||||||
|
constant score rewrite mode by default. The new classes also have
|
||||||
|
new ctors taking field and term ranges as Strings (see also
|
||||||
|
LUCENE-1424). (Uwe Schindler)
|
||||||
|
|
||||||
Bug fixes
|
Bug fixes
|
||||||
|
|
||||||
1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()
|
1. LUCENE-1415: MultiPhraseQuery has incorrect hashCode() and equals()
|
||||||
|
@ -374,7 +380,7 @@ New features
|
||||||
packaged as War file (Mark Harwood)
|
packaged as War file (Mark Harwood)
|
||||||
|
|
||||||
6. LUCENE-1424: Moved constant score query rewrite capability into
|
6. LUCENE-1424: Moved constant score query rewrite capability into
|
||||||
MultiTermQuery, allowing RangeQuery, PrefixQuery and WildcardQuery
|
MultiTermQuery, allowing TermRangeQuery, PrefixQuery and WildcardQuery
|
||||||
to switch betwen constant-score rewriting or BooleanQuery
|
to switch betwen constant-score rewriting or BooleanQuery
|
||||||
expansion rewriting via a new setConstantScoreRewrite method.
|
expansion rewriting via a new setConstantScoreRewrite method.
|
||||||
Deprecated ConstantScoreRangeQuery (Mark Miller via Mike
|
Deprecated ConstantScoreRangeQuery (Mark Miller via Mike
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
<property name="Name" value="Lucene"/>
|
<property name="Name" value="Lucene"/>
|
||||||
<property name="dev.version" value="2.9-dev"/>
|
<property name="dev.version" value="2.9-dev"/>
|
||||||
<property name="version" value="${dev.version}"/>
|
<property name="version" value="${dev.version}"/>
|
||||||
<property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090623a"/>
|
<property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090704"/>
|
||||||
<property name="spec.version" value="${version}"/>
|
<property name="spec.version" value="${version}"/>
|
||||||
<property name="year" value="2000-${current.year}"/>
|
<property name="year" value="2000-${current.year}"/>
|
||||||
<property name="final.name" value="lucene-${name}-${version}"/>
|
<property name="final.name" value="lucene-${name}-${version}"/>
|
||||||
|
|
|
@ -29,9 +29,9 @@ import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
import org.apache.lucene.search.ScoreDoc;
|
import org.apache.lucene.search.ScoreDoc;
|
||||||
import org.apache.lucene.search.Query;
|
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.TermQuery;
|
||||||
import org.apache.lucene.search.RangeQuery;
|
import org.apache.lucene.search.TermRangeQuery;
|
||||||
import org.apache.lucene.search.ConstantScoreRangeQuery;
|
import org.apache.lucene.search.ConstantScoreRangeQuery;
|
||||||
import org.apache.lucene.search.Searcher;
|
import org.apache.lucene.search.Searcher;
|
||||||
import org.apache.lucene.search.Sort;
|
import org.apache.lucene.search.Sort;
|
||||||
|
@ -102,7 +102,7 @@ public class CollationTestBase extends TestCase {
|
||||||
result = is.search(aqp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs;
|
result = is.search(aqp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should be included.", 1, result.length);
|
assertEquals("The index Term should be included.", 1, result.length);
|
||||||
|
|
||||||
// Test RangeQuery
|
// Test TermRangeQuery
|
||||||
aqp.setUseOldRangeQuery(true);
|
aqp.setUseOldRangeQuery(true);
|
||||||
result = is.search(aqp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;
|
result = is.search(aqp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should not be included.", 0, result.length);
|
assertEquals("The index Term should not be included.", 0, result.length);
|
||||||
|
@ -132,15 +132,15 @@ public class CollationTestBase extends TestCase {
|
||||||
|
|
||||||
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
|
// 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
|
// 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
|
// Collator (or an Arabic one for the case when Farsi searcher not
|
||||||
// supported).
|
// supported).
|
||||||
ScoreDoc[] result = searcher.search
|
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);
|
assertEquals("The index Term should not be included.", 0, result.length);
|
||||||
|
|
||||||
result = searcher.search
|
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);
|
assertEquals("The index Term should be included.", 1, result.length);
|
||||||
|
|
||||||
searcher.close();
|
searcher.close();
|
||||||
|
@ -156,7 +156,7 @@ public class CollationTestBase extends TestCase {
|
||||||
|
|
||||||
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
|
// 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
|
// 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).
|
// Collator (or an Arabic one for the case when Farsi is not supported).
|
||||||
doc.add(new Field("content", "\u0633\u0627\u0628",
|
doc.add(new Field("content", "\u0633\u0627\u0628",
|
||||||
Field.Store.YES, Field.Index.ANALYZED));
|
Field.Store.YES, Field.Index.ANALYZED));
|
||||||
|
@ -164,13 +164,11 @@ public class CollationTestBase extends TestCase {
|
||||||
writer.close();
|
writer.close();
|
||||||
IndexSearcher searcher = new IndexSearcher(ramDir);
|
IndexSearcher searcher = new IndexSearcher(ramDir);
|
||||||
|
|
||||||
Query query = new RangeQuery(new Term("content", firstBeg),
|
Query query = new TermRangeQuery("content", firstBeg, firstEnd, true, true);
|
||||||
new Term("content", firstEnd), true);
|
|
||||||
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should not be included.", 0, hits.length);
|
assertEquals("The index Term should not be included.", 0, hits.length);
|
||||||
|
|
||||||
query = new RangeQuery(new Term("content", secondBeg),
|
query = new TermRangeQuery("content", secondBeg, secondEnd, true, true);
|
||||||
new Term("content", secondEnd), true);
|
|
||||||
hits = searcher.search(query, null, 1000).scoreDocs;
|
hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should be included.", 1, hits.length);
|
assertEquals("The index Term should be included.", 1, hits.length);
|
||||||
searcher.close();
|
searcher.close();
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.apache.lucene.search.Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class used to extract the terms used in a query, plus any weights.
|
* 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
|
* so the caller must pass a rewritten query (see Query.rewrite) to obtain a list of
|
||||||
* expanded terms.
|
* expanded terms.
|
||||||
*
|
*
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.lucene.search.MultiTermQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
import org.apache.lucene.search.Query;
|
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.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.search.spans.SpanNearQuery;
|
import org.apache.lucene.search.spans.SpanNearQuery;
|
||||||
|
@ -145,8 +145,8 @@ public class WeightedSpanTermExtractor {
|
||||||
query = mtq;
|
query = mtq;
|
||||||
}
|
}
|
||||||
String field;
|
String field;
|
||||||
if(mtq instanceof RangeQuery) {
|
if(mtq instanceof TermRangeQuery) {
|
||||||
field = ((RangeQuery)mtq).getField();
|
field = ((TermRangeQuery)mtq).getField();
|
||||||
} else {
|
} else {
|
||||||
field = mtq.getTerm().field();
|
field = mtq.getTerm().field();
|
||||||
}
|
}
|
||||||
|
@ -472,10 +472,10 @@ public class WeightedSpanTermExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultiTermQuery copyMultiTermQuery(MultiTermQuery query) {
|
private MultiTermQuery copyMultiTermQuery(MultiTermQuery query) {
|
||||||
if(query instanceof RangeQuery) {
|
if(query instanceof TermRangeQuery) {
|
||||||
RangeQuery q = (RangeQuery)query;
|
TermRangeQuery q = (TermRangeQuery)query;
|
||||||
q.setBoost(query.getBoost());
|
q.setBoost(query.getBoost());
|
||||||
return new RangeQuery(q.getField(), q.getLowerTermText(), q.getUpperTermText(), q.includesLower(), q.includesUpper());
|
return new TermRangeQuery(q.getField(), q.getLowerTerm(), q.getUpperTerm(), q.includesLower(), q.includesUpper());
|
||||||
} else if(query instanceof WildcardQuery) {
|
} else if(query instanceof WildcardQuery) {
|
||||||
MultiTermQuery q = new WildcardQuery(query.getTerm());
|
MultiTermQuery q = new WildcardQuery(query.getTerm());
|
||||||
q.setBoost(query.getBoost());
|
q.setBoost(query.getBoost());
|
||||||
|
|
|
@ -59,7 +59,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
|
||||||
import org.apache.lucene.search.MultiSearcher;
|
import org.apache.lucene.search.MultiSearcher;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.Query;
|
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.Searcher;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.TopDocs;
|
import org.apache.lucene.search.TopDocs;
|
||||||
|
@ -484,7 +484,7 @@ public class HighlighterTest extends TestCase implements Formatter {
|
||||||
numHighlights = 0;
|
numHighlights = 0;
|
||||||
String queryString = FIELD_NAME + ":[kannedy TO kznnedy]";
|
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
|
// rather
|
||||||
// than RangeFilters
|
// than RangeFilters
|
||||||
QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
|
QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
|
||||||
|
@ -701,7 +701,7 @@ public class HighlighterTest extends TestCase implements Formatter {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
numHighlights = 0;
|
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")),
|
SpanQuery clauses[] = { new SpanTermQuery(new Term("contents", "john")),
|
||||||
new SpanTermQuery(new Term("contents", "kennedy")), };
|
new SpanTermQuery(new Term("contents", "kennedy")), };
|
||||||
SpanNearQuery snq = new SpanNearQuery(clauses, 1, true);
|
SpanNearQuery snq = new SpanNearQuery(clauses, 1, true);
|
||||||
|
@ -723,7 +723,7 @@ public class HighlighterTest extends TestCase implements Formatter {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
numHighlights = 0;
|
numHighlights = 0;
|
||||||
RangeFilter rf = new RangeFilter("contents", "john", "john", true, true);
|
TermRangeFilter rf = new TermRangeFilter("contents", "john", "john", true, true);
|
||||||
PhraseQuery pq = new PhraseQuery();
|
PhraseQuery pq = new PhraseQuery();
|
||||||
pq.add(new Term("contents", "john"));
|
pq.add(new Term("contents", "john"));
|
||||||
pq.add(new Term("contents", "kennedy"));
|
pq.add(new Term("contents", "kennedy"));
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ChainedFilterTest extends TestCase {
|
||||||
private IndexSearcher searcher;
|
private IndexSearcher searcher;
|
||||||
private Query query;
|
private Query query;
|
||||||
// private DateFilter dateFilter; DateFilter was deprecated and removed
|
// private DateFilter dateFilter; DateFilter was deprecated and removed
|
||||||
private RangeFilter dateFilter;
|
private TermRangeFilter dateFilter;
|
||||||
private QueryWrapperFilter bobFilter;
|
private QueryWrapperFilter bobFilter;
|
||||||
private QueryWrapperFilter sueFilter;
|
private QueryWrapperFilter sueFilter;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class ChainedFilterTest extends TestCase {
|
||||||
//Date pastTheEnd = parseDate("2099 Jan 1");
|
//Date pastTheEnd = parseDate("2099 Jan 1");
|
||||||
// dateFilter = DateFilter.Before("date", pastTheEnd);
|
// dateFilter = DateFilter.Before("date", pastTheEnd);
|
||||||
// just treat dates as strings and select the whole range for now...
|
// 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(
|
bobFilter = new QueryWrapperFilter(
|
||||||
new TermQuery(new Term("owner", "bob")));
|
new TermQuery(new Term("owner", "bob")));
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanFilter;
|
import org.apache.lucene.search.BooleanFilter;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.FilterClause;
|
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.store.RAMDirectory;
|
||||||
import org.apache.lucene.util.DocIdBitSet;
|
import org.apache.lucene.util.DocIdBitSet;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class BooleanFilterTest extends TestCase
|
||||||
|
|
||||||
private Filter getRangeFilter(String field,String lowerPrice, String upperPrice, boolean old)
|
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) {
|
if (old) {
|
||||||
return getOldBitSetFilter(f);
|
return getOldBitSetFilter(f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
package org.apache.lucene.xmlparser.builders;
|
package org.apache.lucene.xmlparser.builders;
|
||||||
|
|
||||||
import org.apache.lucene.search.Filter;
|
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.DOMUtils;
|
||||||
import org.apache.lucene.xmlparser.FilterBuilder;
|
import org.apache.lucene.xmlparser.FilterBuilder;
|
||||||
import org.apache.lucene.xmlparser.ParserException;
|
import org.apache.lucene.xmlparser.ParserException;
|
||||||
|
@ -39,7 +39,7 @@ public class RangeFilterBuilder implements FilterBuilder {
|
||||||
String upperTerm=e.getAttribute("upperTerm");
|
String upperTerm=e.getAttribute("upperTerm");
|
||||||
boolean includeLower=DOMUtils.getAttribute(e,"includeLower",true);
|
boolean includeLower=DOMUtils.getAttribute(e,"includeLower",true);
|
||||||
boolean includeUpper=DOMUtils.getAttribute(e,"includeUpper",true);
|
boolean includeUpper=DOMUtils.getAttribute(e,"includeUpper",true);
|
||||||
return new RangeFilter(fieldName,lowerTerm,upperTerm,includeLower,includeUpper);
|
return new TermRangeFilter(fieldName,lowerTerm,upperTerm,includeLower,includeUpper);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.lucene.document;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
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.search.NumericRangeQuery; // for javadocs
|
||||||
import org.apache.lucene.util.NumericUtils; // for javadocs
|
import org.apache.lucene.util.NumericUtils; // for javadocs
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import java.util.Calendar; // for javadoc
|
||||||
* which makes them suitable for use as field values and search terms.
|
* which makes them suitable for use as field values and search terms.
|
||||||
*
|
*
|
||||||
* <P>Note that this class saves dates with millisecond granularity,
|
* <P>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
|
* queries are expanded to a BooleanQuery with a potentially large number
|
||||||
* of terms when searching. Thus you might want to use
|
* of terms when searching. Thus you might want to use
|
||||||
* {@link DateTools} instead.
|
* {@link DateTools} instead.
|
||||||
|
|
|
@ -109,4 +109,4 @@ public interface CharStream {
|
||||||
void Done();
|
void Done();
|
||||||
|
|
||||||
}
|
}
|
||||||
/* JavaCC - OriginalChecksum=a83909a2403f969f94d18375f9f143e4 (do not edit this line) */
|
/* JavaCC - OriginalChecksum=32a89423891f765dde472f7ef0e3ef7b (do not edit this line) */
|
||||||
|
|
|
@ -195,4 +195,4 @@ public class ParseException extends Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/* JavaCC - OriginalChecksum=c63b396885c4ff44d7aa48d3feae60cd (do not edit this line) */
|
/* JavaCC - OriginalChecksum=c7631a240f7446940695eac31d9483ca (do not edit this line) */
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
import org.apache.lucene.search.Query;
|
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.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.util.Parameter;
|
import org.apache.lucene.util.Parameter;
|
||||||
|
@ -173,7 +173,6 @@ public class QueryParser implements QueryParserConstants {
|
||||||
return res!=null ? res : newBooleanQuery(false);
|
return res!=null ? res : newBooleanQuery(false);
|
||||||
}
|
}
|
||||||
catch (ParseException tme) {
|
catch (ParseException tme) {
|
||||||
// rethrow to include the original query:
|
|
||||||
// rethrow to include the original query:
|
// rethrow to include the original query:
|
||||||
ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
|
ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
|
||||||
e.initCause(tme);
|
e.initCause(tme);
|
||||||
|
@ -877,22 +876,15 @@ public class QueryParser implements QueryParserConstants {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a new RangeQuery instance
|
* Builds a new TermRangeQuery instance
|
||||||
* @param field Field
|
* @param field Field
|
||||||
* @param part1 min
|
* @param part1 min
|
||||||
* @param part2 max
|
* @param part2 max
|
||||||
* @param inclusive true if range is inclusive
|
* @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) {
|
protected Query newRangeQuery(String field, String part1, String part2, boolean inclusive) {
|
||||||
RangeQuery query;
|
final TermRangeQuery query = new TermRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
query.setConstantScoreRewrite(constantScoreRewrite);
|
query.setConstantScoreRewrite(constantScoreRewrite);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
import org.apache.lucene.search.Query;
|
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.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.util.Parameter;
|
import org.apache.lucene.util.Parameter;
|
||||||
|
@ -198,13 +198,19 @@ public class QueryParser {
|
||||||
}
|
}
|
||||||
catch (ParseException tme) {
|
catch (ParseException tme) {
|
||||||
// rethrow to include the original query:
|
// rethrow to include the original query:
|
||||||
throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
|
ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
|
||||||
|
e.initCause(tme);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
catch (TokenMgrError tme) {
|
catch (TokenMgrError tme) {
|
||||||
throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
|
ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
|
||||||
|
e.initCause(tme);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
catch (BooleanQuery.TooManyClauses tmc) {
|
catch (BooleanQuery.TooManyClauses tmc) {
|
||||||
throw new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
|
ParseException e = new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
|
||||||
|
e.initCause(tmc);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -894,22 +900,15 @@ public class QueryParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a new RangeQuery instance
|
* Builds a new TermRangeQuery instance
|
||||||
* @param field Field
|
* @param field Field
|
||||||
* @param part1 min
|
* @param part1 min
|
||||||
* @param part2 max
|
* @param part2 max
|
||||||
* @param inclusive true if range is inclusive
|
* @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) {
|
protected Query newRangeQuery(String field, String part1, String part2, boolean inclusive) {
|
||||||
RangeQuery query;
|
final TermRangeQuery query = new TermRangeQuery(field, part1, part2, inclusive, inclusive, rangeCollator);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
query.setConstantScoreRewrite(constantScoreRewrite);
|
query.setConstantScoreRewrite(constantScoreRewrite);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
import org.apache.lucene.search.Query;
|
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.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.util.Parameter;
|
import org.apache.lucene.util.Parameter;
|
||||||
|
|
|
@ -121,4 +121,4 @@ public class Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/* JavaCC - OriginalChecksum=37b1923f964a5a434f5ea3d6952ff200 (do not edit this line) */
|
/* JavaCC - OriginalChecksum=c147cc166a7cf8812c7c39bc8c5eb868 (do not edit this line) */
|
||||||
|
|
|
@ -137,4 +137,4 @@ public class TokenMgrError extends Error
|
||||||
this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
|
this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* JavaCC - OriginalChecksum=55cddb2336a66b376c0bb59d916b326d (do not edit this line) */
|
/* JavaCC - OriginalChecksum=186d5bcc64733844c7daab5ad5a6e349 (do not edit this line) */
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class BooleanQuery extends Query {
|
||||||
|
|
||||||
/** Thrown when an attempt is made to add more than {@link
|
/** Thrown when an attempt is made to add more than {@link
|
||||||
* #getMaxClauseCount()} clauses. This typically happens if
|
* #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.
|
* is expanded to many terms during search.
|
||||||
*/
|
*/
|
||||||
public static class TooManyClauses extends RuntimeException {
|
public static class TooManyClauses extends RuntimeException {
|
||||||
|
@ -58,8 +58,8 @@ public class BooleanQuery extends Query {
|
||||||
* so this parameter indirectly controls the maximum buffer requirements for
|
* so this parameter indirectly controls the maximum buffer requirements for
|
||||||
* query search.
|
* query search.
|
||||||
* <p>When this parameter becomes a bottleneck for a Query one can use a
|
* <p>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
|
* Filter. For example instead of a {@link TermRangeQuery} one can use a
|
||||||
* {@link RangeFilter}.
|
* {@link TermRangeFilter}.
|
||||||
* <p>Normally the buffers are allocated by the JVM. When using for example
|
* <p>Normally the buffers are allocated by the JVM. When using for example
|
||||||
* {@link org.apache.lucene.store.MMapDirectory} the buffering is left to
|
* {@link org.apache.lucene.store.MMapDirectory} the buffering is left to
|
||||||
* the operating system.
|
* the operating system.
|
||||||
|
|
|
@ -29,31 +29,32 @@ import java.text.Collator;
|
||||||
* Either or both endpoints may be open. Open endpoints may not be exclusive
|
* 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.)
|
* (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
|
* @deprecated Use {@link TermRangeQuery} for term ranges or
|
||||||
* {@link RangeQuery#setConstantScoreRewrite}, instead.
|
* {@link NumericRangeQuery} for numeric ranges instead.
|
||||||
|
* This class will be removed in Lucene 3.0.
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class ConstantScoreRangeQuery extends RangeQuery
|
public class ConstantScoreRangeQuery extends TermRangeQuery
|
||||||
{
|
{
|
||||||
|
|
||||||
public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper)
|
public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper)
|
||||||
{
|
{
|
||||||
super(fieldName, lowerVal, upperVal, includeLower, includeUpper);
|
super(fieldName, lowerVal, upperVal, includeLower, includeUpper);
|
||||||
this.constantScoreRewrite = true;
|
setConstantScoreRewrite(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstantScoreRangeQuery(String fieldName, String lowerVal,
|
public ConstantScoreRangeQuery(String fieldName, String lowerVal,
|
||||||
String upperVal, boolean includeLower,
|
String upperVal, boolean includeLower,
|
||||||
boolean includeUpper, Collator collator) {
|
boolean includeUpper, Collator collator) {
|
||||||
super(fieldName, lowerVal, upperVal, includeLower, includeUpper, collator);
|
super(fieldName, lowerVal, upperVal, includeLower, includeUpper, collator);
|
||||||
this.constantScoreRewrite = true;
|
setConstantScoreRewrite(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLowerVal() {
|
public String getLowerVal() {
|
||||||
return getLowerTermText();
|
return getLowerTerm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUpperVal() {
|
public String getUpperVal() {
|
||||||
return getUpperTermText();
|
return getUpperTerm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ import org.apache.lucene.document.NumericField; // for javadocs
|
||||||
* even if the range itself changes.
|
* even if the range itself changes.
|
||||||
*
|
*
|
||||||
* <p>This means that FieldCacheRangeFilter is much faster (sometimes more than 100x as fast)
|
* <p>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
|
* 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}.
|
* 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
|
* Furthermore, it does not need the numeric values encoded by {@link NumericField}. But
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.util.BitSet;
|
||||||
* be used by itself. Normally you subclass it to provide a Filter
|
* be used by itself. Normally you subclass it to provide a Filter
|
||||||
* counterpart for a {@link MultiTermQuery} subclass.
|
* counterpart for a {@link MultiTermQuery} subclass.
|
||||||
* <P>
|
* <P>
|
||||||
* For example, {@link RangeFilter} and {@link PrefixFilter} extend
|
* For example, {@link TermRangeFilter} and {@link PrefixFilter} extend
|
||||||
* <code>MultiTermQueryWrapperFilter</code>.
|
* <code>MultiTermQueryWrapperFilter</code>.
|
||||||
* This class also provides the functionality behind
|
* This class also provides the functionality behind
|
||||||
* {@link MultiTermQuery#getFilter}, this is why it is not abstract.
|
* {@link MultiTermQuery#getFilter}, this is why it is not abstract.
|
||||||
|
|
|
@ -36,7 +36,8 @@ import org.apache.lucene.index.IndexReader;
|
||||||
<li> {@link PrefixQuery}
|
<li> {@link PrefixQuery}
|
||||||
<li> {@link MultiPhraseQuery}
|
<li> {@link MultiPhraseQuery}
|
||||||
<li> {@link FuzzyQuery}
|
<li> {@link FuzzyQuery}
|
||||||
<li> {@link RangeQuery}
|
<li> {@link TermRangeQuery}
|
||||||
|
<li> {@link NumericRangeQuery}
|
||||||
<li> {@link org.apache.lucene.search.spans.SpanQuery}
|
<li> {@link org.apache.lucene.search.spans.SpanQuery}
|
||||||
</ul>
|
</ul>
|
||||||
<p>A parser for queries is contained in:
|
<p>A parser for queries is contained in:
|
||||||
|
@ -146,7 +147,7 @@ public abstract class Query implements java.io.Serializable, Cloneable {
|
||||||
* correspondence with queries). This is an optimization of the OR of
|
* correspondence with queries). This is an optimization of the OR of
|
||||||
* all queries. We handle the common optimization cases of equal
|
* all queries. We handle the common optimization cases of equal
|
||||||
* queries and overlapping clauses of boolean OR queries (as generated
|
* 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
|
* Be careful overriding this method as queries[0] determines which
|
||||||
* method will be called and is not necessarily of the same type as
|
* method will be called and is not necessarily of the same type as
|
||||||
* the other queries.
|
* the other queries.
|
||||||
|
|
|
@ -26,10 +26,10 @@ import org.apache.lucene.index.IndexReader;
|
||||||
* Constrains search results to only match those which also match a provided
|
* Constrains search results to only match those which also match a provided
|
||||||
* query.
|
* query.
|
||||||
*
|
*
|
||||||
* <p> This could be used, for example, with a {@link RangeQuery} on a suitably
|
* <p> 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
|
* formatted date field to implement date filtering. One could re-use a single
|
||||||
* QueryFilter that matches, e.g., only documents modified within the last
|
* 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.
|
* once per day.
|
||||||
*
|
*
|
||||||
* @version $Id:$
|
* @version $Id:$
|
||||||
|
|
|
@ -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.
|
|
||||||
*
|
|
||||||
* <p>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.
|
|
||||||
*
|
|
||||||
* <p>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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <strong>WARNING:</strong> Using this constructor and supplying a non-null
|
|
||||||
* value in the <code>collator</code> parameter will cause every single
|
|
||||||
* index Term in the Field referenced by lowerTerm and/or upperTerm to be
|
|
||||||
* examined. Depending on the number of index Terms in this Field, the
|
|
||||||
* operation could be very slow.
|
|
||||||
*
|
|
||||||
* @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 <code>fieldName</code> matching
|
|
||||||
* less than or equal to <code>upperTerm</code>.
|
|
||||||
*/
|
|
||||||
public static RangeFilter Less(String fieldName, String upperTerm) {
|
|
||||||
return new RangeFilter(fieldName, null, upperTerm, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a filter for field <code>fieldName</code> matching
|
|
||||||
* greater than or equal to <code>lowerTerm</code>.
|
|
||||||
*/
|
|
||||||
public static RangeFilter More(String fieldName, String lowerTerm) {
|
|
||||||
return new RangeFilter(fieldName, lowerTerm, null, true, false);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* <p>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.
|
||||||
|
*
|
||||||
|
* <p>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 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 TermRangeFilter(String fieldName, String lowerTerm, String upperTerm,
|
||||||
|
boolean includeLower, boolean includeUpper) {
|
||||||
|
super(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <strong>WARNING:</strong> Using this constructor and supplying a non-null
|
||||||
|
* value in the <code>collator</code> parameter will cause every single
|
||||||
|
* index Term in the Field referenced by lowerTerm and/or upperTerm to be
|
||||||
|
* examined. Depending on the number of index Terms in this Field, the
|
||||||
|
* operation could be very slow.
|
||||||
|
*
|
||||||
|
* @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 <code>fieldName</code> matching
|
||||||
|
* less than or equal to <code>upperTerm</code>.
|
||||||
|
*/
|
||||||
|
public static TermRangeFilter Less(String fieldName, String upperTerm) {
|
||||||
|
return new TermRangeFilter(fieldName, null, upperTerm, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a filter for field <code>fieldName</code> matching
|
||||||
|
* greater than or equal to <code>lowerTerm</code>.
|
||||||
|
*/
|
||||||
|
public static TermRangeFilter More(String fieldName, String lowerTerm) {
|
||||||
|
return new TermRangeFilter(fieldName, lowerTerm, null, true, false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,21 +22,23 @@ import java.text.Collator;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
|
import org.apache.lucene.util.ToStringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Query that matches documents within an exclusive range.
|
* A Query that matches documents within an exclusive range of terms.
|
||||||
*
|
*
|
||||||
* <p>This query matches the documents looking for terms that fall into the
|
* <p>This query matches the documents looking for terms that fall into the
|
||||||
* supplied range according to {@link String#compareTo(String)}. It is not intended
|
* supplied range according to {@link String#compareTo(String)}. It is not intended
|
||||||
* for numerical ranges, use {@link NumericRangeQuery} instead.
|
* for numerical ranges, use {@link NumericRangeQuery} instead.
|
||||||
*
|
*
|
||||||
* <p>See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between
|
* <p>This query is in constant score mode per default.
|
||||||
|
* See {@link MultiTermQuery#setConstantScoreRewrite} for the tradeoffs between
|
||||||
* enabling and disabling constantScoreRewrite mode.
|
* enabling and disabling constantScoreRewrite mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class RangeQuery extends MultiTermQuery {
|
public class TermRangeQuery extends MultiTermQuery {
|
||||||
private Term lowerTerm;
|
private String lowerTerm;
|
||||||
private Term upperTerm;
|
private String upperTerm;
|
||||||
private Collator collator;
|
private Collator collator;
|
||||||
private String field;
|
private String field;
|
||||||
private boolean includeLower;
|
private boolean includeLower;
|
||||||
|
@ -65,8 +67,8 @@ public class RangeQuery extends MultiTermQuery {
|
||||||
* If true, the <code>upperTerm</code> is
|
* If true, the <code>upperTerm</code> is
|
||||||
* included in the range.
|
* included in the range.
|
||||||
*/
|
*/
|
||||||
public RangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
public TermRangeQuery(String field, String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||||
init(new Term(field, lowerTerm), new Term(field, upperTerm), includeLower, includeUpper, null);
|
this(field, lowerTerm, upperTerm, includeLower, includeUpper, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constructs a query selecting all terms greater/equal than
|
/** Constructs a query selecting all terms greater/equal than
|
||||||
|
@ -99,39 +101,15 @@ public class RangeQuery extends MultiTermQuery {
|
||||||
* their membership in the range bounded by <code>lowerTerm</code> and
|
* their membership in the range bounded by <code>lowerTerm</code> and
|
||||||
* <code>upperTerm</code>.
|
* <code>upperTerm</code>.
|
||||||
*/
|
*/
|
||||||
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) {
|
Collator collator) {
|
||||||
init(new Term(field, lowerTerm), new Term(field,upperTerm), includeLower, includeUpper, collator);
|
this.field = field;
|
||||||
}
|
|
||||||
|
|
||||||
/** @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.lowerTerm = lowerTerm;
|
||||||
this.upperTerm = upperTerm;
|
this.upperTerm = upperTerm;
|
||||||
this.includeLower = includeLower;
|
this.includeLower = includeLower;
|
||||||
this.includeUpper = includeUpper;
|
this.includeUpper = includeUpper;
|
||||||
this.collator = collator;
|
this.collator = collator;
|
||||||
|
setConstantScoreRewrite(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the field name for this query */
|
/** Returns the field name for this query */
|
||||||
|
@ -139,19 +117,11 @@ public class RangeQuery extends MultiTermQuery {
|
||||||
return field;
|
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 */
|
/** Returns the lower value of this range query */
|
||||||
public String getLowerTermText() { return lowerTerm == null ? null : lowerTerm.text(); }
|
public String getLowerTerm() { return lowerTerm; }
|
||||||
|
|
||||||
/** Returns the upper value of this range query */
|
/** Returns the upper value of this range query */
|
||||||
public String getUpperTermText() { return upperTerm == null ? null : upperTerm.text(); }
|
public String getUpperTerm() { return upperTerm; }
|
||||||
|
|
||||||
/** Returns <code>true</code> if the lower endpoint is inclusive */
|
/** Returns <code>true</code> if the lower endpoint is inclusive */
|
||||||
public boolean includesLower() { return includeLower; }
|
public boolean includesLower() { return includeLower; }
|
||||||
|
@ -159,18 +129,12 @@ public class RangeQuery extends MultiTermQuery {
|
||||||
/** Returns <code>true</code> if the upper endpoint is inclusive */
|
/** Returns <code>true</code> if the upper endpoint is inclusive */
|
||||||
public boolean includesUpper() { return includeUpper; }
|
public boolean includesUpper() { return includeUpper; }
|
||||||
|
|
||||||
/** Returns <code>true</code> 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. */
|
/** Returns the collator used to determine range inclusion, if any. */
|
||||||
public Collator getCollator() { return collator; }
|
public Collator getCollator() { return collator; }
|
||||||
|
|
||||||
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
|
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
|
||||||
//TODO: when the deprecated 'Term' constructors are removed we can remove these null checks
|
return new TermRangeTermEnum(reader, collator, field, lowerTerm,
|
||||||
return new RangeTermEnum(reader, collator, getField(), lowerTerm == null ? null : lowerTerm.text(),
|
upperTerm, includeLower, includeUpper);
|
||||||
upperTerm == null ? null : upperTerm.text(), includeLower, includeUpper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints a user-readable version of this query. */
|
/** Prints a user-readable version of this query. */
|
||||||
|
@ -181,14 +145,11 @@ public class RangeQuery extends MultiTermQuery {
|
||||||
buffer.append(":");
|
buffer.append(":");
|
||||||
}
|
}
|
||||||
buffer.append(includeLower ? '[' : '{');
|
buffer.append(includeLower ? '[' : '{');
|
||||||
buffer.append(lowerTerm != null ? lowerTerm.text() : "*");
|
buffer.append(lowerTerm != null ? lowerTerm : "*");
|
||||||
buffer.append(" TO ");
|
buffer.append(" TO ");
|
||||||
buffer.append(upperTerm != null ? upperTerm.text() : "*");
|
buffer.append(upperTerm != null ? upperTerm : "*");
|
||||||
buffer.append(includeUpper ? ']' : '}');
|
buffer.append(includeUpper ? ']' : '}');
|
||||||
if (getBoost() != 1.0f) {
|
buffer.append(ToStringUtils.boost(getBoost()));
|
||||||
buffer.append("^");
|
|
||||||
buffer.append(Float.toString(getBoost()));
|
|
||||||
}
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +174,7 @@ public class RangeQuery extends MultiTermQuery {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
RangeQuery other = (RangeQuery) obj;
|
TermRangeQuery other = (TermRangeQuery) obj;
|
||||||
if (collator == null) {
|
if (collator == null) {
|
||||||
if (other.collator != null)
|
if (other.collator != null)
|
||||||
return false;
|
return false;
|
|
@ -30,7 +30,7 @@ import org.apache.lucene.index.Term;
|
||||||
* Term enumerations are always ordered by Term.compareTo(). Each term in
|
* Term enumerations are always ordered by Term.compareTo(). Each term in
|
||||||
* the enumeration is greater than all that precede it.
|
* the enumeration is greater than all that precede it.
|
||||||
*/
|
*/
|
||||||
public class RangeTermEnum extends FilteredTermEnum {
|
public class TermRangeTermEnum extends FilteredTermEnum {
|
||||||
|
|
||||||
private Collator collator = null;
|
private Collator collator = null;
|
||||||
private boolean endEnum = false;
|
private boolean endEnum = false;
|
||||||
|
@ -67,14 +67,14 @@ public class RangeTermEnum extends FilteredTermEnum {
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @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 {
|
String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper) throws IOException {
|
||||||
this.collator = collator;
|
this.collator = collator;
|
||||||
this.upperTermText = upperTermText;
|
this.upperTermText = upperTermText;
|
||||||
this.lowerTermText = lowerTermText;
|
this.lowerTermText = lowerTermText;
|
||||||
this.includeLower = includeLower;
|
this.includeLower = includeLower;
|
||||||
this.includeUpper = includeUpper;
|
this.includeUpper = includeUpper;
|
||||||
this.field = field;
|
this.field = field.intern();
|
||||||
|
|
||||||
// do a little bit of normalization...
|
// do a little bit of normalization...
|
||||||
// open ended range queries should always be inclusive.
|
// open ended range queries should always be inclusive.
|
|
@ -138,11 +138,11 @@ org.apache.lucene.search.Searcher#search(Query,Filter)}.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h4>
|
<h4>
|
||||||
<a href="RangeQuery.html">RangeQuery</a>
|
<a href="TermRangeQuery.html">TermRangeQuery</a>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<p>The
|
<p>The
|
||||||
<a href="RangeQuery.html">RangeQuery</a>
|
<a href="TermRangeQuery.html">TermRangeQuery</a>
|
||||||
matches all documents that occur in the
|
matches all documents that occur in the
|
||||||
exclusive range of a lower
|
exclusive range of a lower
|
||||||
<a href="../index/Term.html">Term</a>
|
<a href="../index/Term.html">Term</a>
|
||||||
|
|
|
@ -50,7 +50,7 @@ import org.apache.lucene.search.MatchAllDocsQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
import org.apache.lucene.search.Query;
|
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.ScoreDoc;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
|
@ -431,11 +431,11 @@ public class TestQueryParser extends LuceneTestCase {
|
||||||
|
|
||||||
public void testRange() throws Exception {
|
public void testRange() throws Exception {
|
||||||
assertQueryEquals("[ a TO z]", null, "[a TO z]");
|
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());
|
QueryParser qp = new QueryParser("field", new SimpleAnalyzer());
|
||||||
qp.setConstantScoreRewrite(false);
|
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]");
|
||||||
assertQueryEquals("{ a TO z}", null, "{a TO z}");
|
assertQueryEquals("{ a TO z}", null, "{a TO z}");
|
||||||
|
@ -481,7 +481,7 @@ public class TestQueryParser extends LuceneTestCase {
|
||||||
result = is.search(qp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs;
|
result = is.search(qp.parse("[ \u0633 TO \u0638 ]"), null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should be included.", 1, result.length);
|
assertEquals("The index Term should be included.", 1, result.length);
|
||||||
|
|
||||||
// Test RangeQuery
|
// Test TermRangeQuery
|
||||||
qp.setConstantScoreRewrite(false);
|
qp.setConstantScoreRewrite(false);
|
||||||
result = is.search(qp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;
|
result = is.search(qp.parse("[ \u062F TO \u0698 ]"), null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should not be included.", 0, result.length);
|
assertEquals("The index Term should not be included.", 0, result.length);
|
||||||
|
|
|
@ -66,11 +66,11 @@ public class TestDateFilter
|
||||||
|
|
||||||
// filter that should preserve matches
|
// filter that should preserve matches
|
||||||
//DateFilter df1 = DateFilter.Before("datefield", now);
|
//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);
|
DateTools.timeToString(now, DateTools.Resolution.MILLISECOND), false, true);
|
||||||
// filter that should discard matches
|
// filter that should discard matches
|
||||||
//DateFilter df2 = DateFilter.Before("datefield", now - 999999);
|
//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);
|
DateTools.timeToString(now - 2000, DateTools.Resolution.MILLISECOND), true, false);
|
||||||
|
|
||||||
// search something that doesn't exist with DateFilter
|
// search something that doesn't exist with DateFilter
|
||||||
|
@ -127,11 +127,11 @@ public class TestDateFilter
|
||||||
|
|
||||||
// filter that should preserve matches
|
// filter that should preserve matches
|
||||||
//DateFilter df1 = DateFilter.After("datefield", now);
|
//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);
|
DateTools.timeToString(now + 999999, DateTools.Resolution.MILLISECOND), true, false);
|
||||||
// filter that should discard matches
|
// filter that should discard matches
|
||||||
//DateFilter df2 = DateFilter.After("datefield", now + 999999);
|
//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);
|
DateTools.timeToString(now + 999999999, DateTools.Resolution.MILLISECOND), false, true);
|
||||||
|
|
||||||
// search something that doesn't exist with DateFilter
|
// search something that doesn't exist with DateFilter
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
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.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* NOTE: at the moment, this class only tests for 'positive' results,
|
* NOTE: at the moment, this class only tests for 'positive' results,
|
||||||
|
|
|
@ -177,8 +177,8 @@ extends LuceneTestCase {
|
||||||
* This tests FilteredQuery's rewrite correctness
|
* This tests FilteredQuery's rewrite correctness
|
||||||
*/
|
*/
|
||||||
public void testRangeQuery() throws Exception {
|
public void testRangeQuery() throws Exception {
|
||||||
RangeQuery rq = new RangeQuery(
|
TermRangeQuery rq = new TermRangeQuery(
|
||||||
new Term("sorter", "b"), new Term("sorter", "d"), true);
|
"sorter", "b", "d", true, true);
|
||||||
|
|
||||||
Query filteredquery = new FilteredQuery(rq, filter);
|
Query filteredquery = new FilteredQuery(rq, filter);
|
||||||
ScoreDoc[] hits = searcher.search(filteredquery, null, 1000).scoreDocs;
|
ScoreDoc[] hits = searcher.search(filteredquery, null, 1000).scoreDocs;
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {
|
||||||
|
|
||||||
/** macro for readability */
|
/** macro for readability */
|
||||||
public static Query csrq(String f, String l, String h, boolean il, boolean ih) {
|
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);
|
query.setConstantScoreRewrite(true);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {
|
||||||
/** macro for readability */
|
/** macro for readability */
|
||||||
public static Query csrq(String f, String l, String h, boolean il,
|
public static Query csrq(String f, String l, String h, boolean il,
|
||||||
boolean ih, Collator c) {
|
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);
|
query.setConstantScoreRewrite(true);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -220,10 +220,10 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {
|
||||||
IndexReader reader = IndexReader.open(small);
|
IndexReader reader = IndexReader.open(small);
|
||||||
IndexSearcher search = new IndexSearcher(reader);
|
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
|
// 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;
|
ScoreDoc[] expected = search.search(rq, null, 1000).scoreDocs;
|
||||||
int numHits = expected.length;
|
int numHits = expected.length;
|
||||||
|
|
|
@ -226,38 +226,38 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
// test inclusive range
|
// test inclusive range
|
||||||
NumericRangeQuery tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), true, true);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
TopDocs tTopDocs = searcher.search(tq, 1);
|
TopDocs tTopDocs = searcher.search(tq, 1);
|
||||||
TopDocs cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
// test exclusive range
|
// test exclusive range
|
||||||
tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), false, false);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
tTopDocs = searcher.search(tq, 1);
|
tTopDocs = searcher.search(tq, 1);
|
||||||
cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
// test left exclusive range
|
// test left exclusive range
|
||||||
tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), false, true);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
tTopDocs = searcher.search(tq, 1);
|
tTopDocs = searcher.search(tq, 1);
|
||||||
cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
// test right exclusive range
|
// test right exclusive range
|
||||||
tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper), true, false);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
tTopDocs = searcher.search(tq, 1);
|
tTopDocs = searcher.search(tq, 1);
|
||||||
cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,38 +226,38 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
// test inclusive range
|
// test inclusive range
|
||||||
NumericRangeQuery tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), true, true);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
TopDocs tTopDocs = searcher.search(tq, 1);
|
TopDocs tTopDocs = searcher.search(tq, 1);
|
||||||
TopDocs cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
// test exclusive range
|
// test exclusive range
|
||||||
tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), false, false);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
tTopDocs = searcher.search(tq, 1);
|
tTopDocs = searcher.search(tq, 1);
|
||||||
cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
// test left exclusive range
|
// test left exclusive range
|
||||||
tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), false, true);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
tTopDocs = searcher.search(tq, 1);
|
tTopDocs = searcher.search(tq, 1);
|
||||||
cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
// test right exclusive range
|
// test right exclusive range
|
||||||
tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper), true, false);
|
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);
|
cq.setConstantScoreRewrite(true);
|
||||||
tTopDocs = searcher.search(tq, 1);
|
tTopDocs = searcher.search(tq, 1);
|
||||||
cTopDocs = searcher.search(cq, 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();
|
termCountT += tq.getTotalNumberOfTerms();
|
||||||
termCountC += cq.getTotalNumberOfTerms();
|
termCountC += cq.getTotalNumberOfTerms();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
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.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* NOTE: at the moment, this class only tests for 'positive' results,
|
* NOTE: at the moment, this class only tests for 'positive' results,
|
||||||
|
@ -38,12 +38,12 @@ import org.apache.lucene.store.RAMDirectory;
|
||||||
* nor does it adequately test 'negative' results. It also does not test
|
* nor does it adequately test 'negative' results. It also does not test
|
||||||
* that garbage in results in an Exception.
|
* that garbage in results in an Exception.
|
||||||
*/
|
*/
|
||||||
public class TestRangeFilter extends BaseTestRangeFilter {
|
public class TestTermRangeFilter extends BaseTestRangeFilter {
|
||||||
|
|
||||||
public TestRangeFilter(String name) {
|
public TestTermRangeFilter(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
public TestRangeFilter() {
|
public TestTermRangeFilter() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,64 +67,64 @@ public class TestRangeFilter extends BaseTestRangeFilter {
|
||||||
|
|
||||||
// test id, bounded on both ends
|
// 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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
assertEquals("up to med", 1+ medId-minId, result.length);
|
||||||
|
|
||||||
// unbounded id
|
// 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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
assertEquals("not min, up to med", medId-minId, result.length);
|
||||||
|
|
||||||
// very small sets
|
// 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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
assertEquals("med,med,T,T", 1, result.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -151,64 +151,64 @@ public class TestRangeFilter extends BaseTestRangeFilter {
|
||||||
|
|
||||||
// test id, bounded on both ends
|
// 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());
|
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());
|
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());
|
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());
|
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());
|
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());
|
assertEquals("up to med", 1+ medId-minId, result.length());
|
||||||
|
|
||||||
// unbounded id
|
// 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());
|
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());
|
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());
|
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());
|
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());
|
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());
|
assertEquals("not min, up to med", medId-minId, result.length());
|
||||||
|
|
||||||
// very small sets
|
// 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());
|
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());
|
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());
|
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());
|
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());
|
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());
|
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());
|
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());
|
assertEquals("med,med,T,T", 1, result.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,47 +229,47 @@ public class TestRangeFilter extends BaseTestRangeFilter {
|
||||||
|
|
||||||
// test extremes, bounded on both ends
|
// 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);
|
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);
|
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);
|
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);
|
assertEquals("all but extremes", numDocs-2, result.length);
|
||||||
|
|
||||||
// unbounded
|
// 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);
|
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);
|
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);
|
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);
|
assertEquals("not biggest, but down", numDocs-1, result.length);
|
||||||
|
|
||||||
// very small sets
|
// 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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
assertEquals("max,nul,T,T", 1, result.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -294,47 +294,47 @@ public class TestRangeFilter extends BaseTestRangeFilter {
|
||||||
|
|
||||||
// test extremes, bounded on both ends
|
// 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());
|
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());
|
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());
|
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());
|
assertEquals("all but extremes", numDocs-2, result.length());
|
||||||
|
|
||||||
// unbounded
|
// 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());
|
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());
|
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());
|
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());
|
assertEquals("not biggest, but down", numDocs-1, result.length());
|
||||||
|
|
||||||
// very small sets
|
// 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());
|
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());
|
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());
|
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());
|
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());
|
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());
|
assertEquals("max,nul,T,T", 1, result.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,14 +365,14 @@ public class TestRangeFilter extends BaseTestRangeFilter {
|
||||||
|
|
||||||
// Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
|
// 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
|
// 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).
|
// Collator (or an Arabic one for the case when Farsi is not supported).
|
||||||
Hits result = search.search
|
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());
|
assertEquals("The index Term should not be included.", 0, result.length());
|
||||||
|
|
||||||
result = search.search
|
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());
|
assertEquals("The index Term should be included.", 1, result.length());
|
||||||
search.close();
|
search.close();
|
||||||
}
|
}
|
||||||
|
@ -403,17 +403,17 @@ public class TestRangeFilter extends BaseTestRangeFilter {
|
||||||
Query q = new TermQuery(new Term("body","body"));
|
Query q = new TermQuery(new Term("body","body"));
|
||||||
|
|
||||||
Collator collator = Collator.getInstance(new Locale("da", "dk"));
|
Collator collator = Collator.getInstance(new Locale("da", "dk"));
|
||||||
Query query = new RangeQuery
|
Query query = new TermRangeQuery
|
||||||
("content", "H\u00D8T", "MAND", false, false, collator);
|
("content", "H\u00D8T", "MAND", false, false, collator);
|
||||||
|
|
||||||
// Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ],
|
// Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ],
|
||||||
// but Danish collation does.
|
// but Danish collation does.
|
||||||
Hits result = search.search
|
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());
|
assertEquals("The index Term should be included.", 1, result.length());
|
||||||
|
|
||||||
result = search.search
|
result = search.search
|
||||||
(q, new RangeFilter("content", "H\u00C5T", "MAND", F, F, collator));
|
(q, new TermRangeFilter("content", "H\u00C5T", "MAND", F, F, collator));
|
||||||
assertEquals
|
assertEquals
|
||||||
("The index Term should not be included.", 0, result.length());
|
("The index Term should not be included.", 0, result.length());
|
||||||
search.close();
|
search.close();
|
|
@ -35,7 +35,7 @@ import java.util.Locale;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
|
|
||||||
|
|
||||||
public class TestRangeQuery extends LuceneTestCase {
|
public class TestTermRangeQuery extends LuceneTestCase {
|
||||||
|
|
||||||
private int docCount = 0;
|
private int docCount = 0;
|
||||||
private RAMDirectory dir;
|
private RAMDirectory dir;
|
||||||
|
@ -46,7 +46,7 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExclusive() throws Exception {
|
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"});
|
initializeIndex(new String[] {"A", "B", "C", "D"});
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
|
@ -84,7 +84,7 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInclusive() throws Exception {
|
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"});
|
initializeIndex(new String[]{"A", "B", "C", "D"});
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
|
@ -106,10 +106,10 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEqualsHashcode() {
|
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.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);
|
other.setBoost(1.0f);
|
||||||
|
|
||||||
assertEquals("query equals itself is true", query, query);
|
assertEquals("query equals itself is true", query, query);
|
||||||
|
@ -119,40 +119,40 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
other.setBoost(2.0f);
|
other.setBoost(2.0f);
|
||||||
assertFalse("Different boost queries are not equal", query.equals(other));
|
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));
|
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));
|
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));
|
assertFalse("Different upper terms are not equal", query.equals(other));
|
||||||
|
|
||||||
query = new RangeQuery("content", null, "C", true, true);
|
query = new TermRangeQuery("content", null, "C", true, true);
|
||||||
other = new RangeQuery("content", null, "C", true, true);
|
other = new TermRangeQuery("content", null, "C", true, true);
|
||||||
assertEquals("equivalent queries with null lowerterms are equal()", query, other);
|
assertEquals("equivalent queries with null lowerterms are equal()", query, other);
|
||||||
assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());
|
assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());
|
||||||
|
|
||||||
query = new RangeQuery("content", "C", null, true, true);
|
query = new TermRangeQuery("content", "C", null, true, true);
|
||||||
other = new RangeQuery("content", "C", null, true, true);
|
other = new TermRangeQuery("content", "C", null, true, true);
|
||||||
assertEquals("equivalent queries with null upperterms are equal()", query, other);
|
assertEquals("equivalent queries with null upperterms are equal()", query, other);
|
||||||
assertEquals("hashcode returns same value", query.hashCode(), other.hashCode());
|
assertEquals("hashcode returns same value", query.hashCode(), other.hashCode());
|
||||||
|
|
||||||
query = new RangeQuery("content", null, "C", true, true);
|
query = new TermRangeQuery("content", null, "C", true, true);
|
||||||
other = new RangeQuery("content", "C", null, true, true);
|
other = new TermRangeQuery("content", "C", null, true, true);
|
||||||
assertFalse("queries with different upper and lower terms are not equal", query.equals(other));
|
assertFalse("queries with different upper and lower terms are not equal", query.equals(other));
|
||||||
|
|
||||||
query = new RangeQuery("content", "A", "C", false, false);
|
query = new TermRangeQuery("content", "A", "C", false, false);
|
||||||
other = new RangeQuery("content", "A", "C", true, true);
|
other = new TermRangeQuery("content", "A", "C", true, true);
|
||||||
assertFalse("queries with different inclusive are not equal", query.equals(other));
|
assertFalse("queries with different inclusive are not equal", query.equals(other));
|
||||||
|
|
||||||
query = new RangeQuery("content", "A", "C", false, false);
|
query = new TermRangeQuery("content", "A", "C", false, false);
|
||||||
other = new RangeQuery("content", "A", "C", false, false, Collator.getInstance());
|
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));
|
assertFalse("a query with a collator is not equal to one without", query.equals(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExclusiveCollating() throws Exception {
|
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"});
|
initializeIndex(new String[] {"A", "B", "C", "D"});
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
|
@ -173,7 +173,7 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInclusiveCollating() throws Exception {
|
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"});
|
initializeIndex(new String[]{"A", "B", "C", "D"});
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
|
@ -199,17 +199,17 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
// RuleBasedCollator. However, the Arabic Locale seems to order the Farsi
|
// RuleBasedCollator. However, the Arabic Locale seems to order the Farsi
|
||||||
// characters properly.
|
// characters properly.
|
||||||
Collator collator = Collator.getInstance(new Locale("ar"));
|
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
|
// 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
|
// 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).
|
// Collator (or an Arabic one for the case when Farsi is not supported).
|
||||||
initializeIndex(new String[]{ "\u0633\u0627\u0628"});
|
initializeIndex(new String[]{ "\u0633\u0627\u0628"});
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should not be included.", 0, hits.length);
|
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;
|
hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should be included.", 1, hits.length);
|
assertEquals("The index Term should be included.", 1, hits.length);
|
||||||
searcher.close();
|
searcher.close();
|
||||||
|
@ -220,7 +220,7 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
// Danish collation orders the words below in the given order (example taken
|
// Danish collation orders the words below in the given order (example taken
|
||||||
// from TestSort.testInternationalSort() ).
|
// from TestSort.testInternationalSort() ).
|
||||||
String[] words = { "H\u00D8T", "H\u00C5T", "MAND" };
|
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" ],
|
// Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ],
|
||||||
// but Danish collation does.
|
// but Danish collation does.
|
||||||
|
@ -229,7 +229,7 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should be included.", 1, hits.length);
|
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;
|
hits = searcher.search(query, null, 1000).scoreDocs;
|
||||||
assertEquals("The index Term should not be included.", 0, hits.length);
|
assertEquals("The index Term should not be included.", 0, hits.length);
|
||||||
searcher.close();
|
searcher.close();
|
||||||
|
@ -315,9 +315,8 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
public void testExclusiveLowerNull() throws Exception {
|
public void testExclusiveLowerNull() throws Exception {
|
||||||
Analyzer analyzer = new SingleCharAnalyzer();
|
Analyzer analyzer = new SingleCharAnalyzer();
|
||||||
//http://issues.apache.org/jira/browse/LUCENE-38
|
//http://issues.apache.org/jira/browse/LUCENE-38
|
||||||
Query query = new RangeQuery(null,
|
Query query = new TermRangeQuery("content", null, "C",
|
||||||
new Term("content", "C"),
|
false, false);
|
||||||
false);
|
|
||||||
initializeIndex(new String[] {"A", "B", "", "C", "D"}, analyzer);
|
initializeIndex(new String[] {"A", "B", "", "C", "D"}, analyzer);
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
Hits hits = searcher.search(query);
|
Hits hits = searcher.search(query);
|
||||||
|
@ -349,9 +348,7 @@ public class TestRangeQuery extends LuceneTestCase {
|
||||||
public void testInclusiveLowerNull() throws Exception {
|
public void testInclusiveLowerNull() throws Exception {
|
||||||
//http://issues.apache.org/jira/browse/LUCENE-38
|
//http://issues.apache.org/jira/browse/LUCENE-38
|
||||||
Analyzer analyzer = new SingleCharAnalyzer();
|
Analyzer analyzer = new SingleCharAnalyzer();
|
||||||
Query query = new RangeQuery(null,
|
Query query = new TermRangeQuery("content", null, "C", true, true);
|
||||||
new Term("content", "C"),
|
|
||||||
true);
|
|
||||||
initializeIndex(new String[]{"A", "B", "","C", "D"}, analyzer);
|
initializeIndex(new String[]{"A", "B", "","C", "D"}, analyzer);
|
||||||
IndexSearcher searcher = new IndexSearcher(dir);
|
IndexSearcher searcher = new IndexSearcher(dir);
|
||||||
Hits hits = searcher.search(query);
|
Hits hits = searcher.search(query);
|
Loading…
Reference in New Issue