mirror of https://github.com/apache/lucene.git
SOLR-940 followup -- Changing API, implementation and javadocs per Hoss's suggestions
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@752785 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
60060d89f4
commit
e53a1f29c1
|
@ -427,20 +427,30 @@ public abstract class FieldType extends FieldProperties {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a Query instance for doing range searches on this field type
|
||||
* Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
|
||||
* currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
|
||||
* currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
|
||||
* different semantics.
|
||||
* <p/>
|
||||
* Sub-classes should override this method to provide their own range query implementation. They should strive to
|
||||
* handle nulls in part1 and/or part2 as well as unequal minInclusive and maxInclusive parameters gracefully.
|
||||
*
|
||||
* @param field the name of the field
|
||||
* @param part1 the lower boundary of the range, nulls are allowed.
|
||||
* @param part2 the upper boundary of the range, nulls are allowed
|
||||
* @param minInclusive whether the minimum of the range is inclusive or not
|
||||
* @param maxInclusive whether the maximum of the range is inclusive or not
|
||||
*
|
||||
* @param field the name of the field
|
||||
* @param part1 the lower boundary of the range
|
||||
* @param part2 the upper boundary of the range
|
||||
* @param inclusive whether the range is inclusive or not
|
||||
* @return a Query instance to perform range search according to given parameters
|
||||
*
|
||||
* @see org.apache.solr.search.SolrQueryParser#getRangeQuery(String, String, String, boolean)
|
||||
*/
|
||||
public Query getRangeQuery(String field, String part1, String part2, boolean inclusive) {
|
||||
public Query getRangeQuery(String field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
|
||||
RangeQuery rangeQuery = new RangeQuery(
|
||||
field,
|
||||
"*".equals(part1) ? null : toInternal(part1),
|
||||
"*".equals(part2) ? null : toInternal(part2),
|
||||
inclusive, inclusive);
|
||||
part1 == null ? null : toInternal(part1),
|
||||
part2 == null ? null : toInternal(part2),
|
||||
minInclusive, maxInclusive);
|
||||
rangeQuery.setConstantScoreRewrite(true);
|
||||
return rangeQuery;
|
||||
}
|
||||
|
|
|
@ -148,38 +148,38 @@ public class TrieField extends FieldType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Query getRangeQuery(String field, String min, String max, boolean inclusive) {
|
||||
public Query getRangeQuery(String field, String min, String max, boolean minInclusive, boolean maxInclusive) {
|
||||
Filter filter = null;
|
||||
switch (type) {
|
||||
case INTEGER:
|
||||
filter = new IntTrieRangeFilter(field, field, precisionStep,
|
||||
"*".equals(min) ? null : Integer.parseInt(min),
|
||||
"*".equals(max) ? null : Integer.parseInt(max),
|
||||
inclusive, inclusive);
|
||||
min == null ? null : Integer.parseInt(min),
|
||||
max == null ? null : Integer.parseInt(max),
|
||||
minInclusive, maxInclusive);
|
||||
break;
|
||||
case FLOAT:
|
||||
filter = new IntTrieRangeFilter(field, field, precisionStep,
|
||||
"*".equals(min) ? null : TrieUtils.floatToSortableInt(Float.parseFloat(min)),
|
||||
"*".equals(max) ? null : TrieUtils.floatToSortableInt(Float.parseFloat(max)),
|
||||
inclusive, inclusive);
|
||||
min == null ? null : TrieUtils.floatToSortableInt(Float.parseFloat(min)),
|
||||
max == null ? null : TrieUtils.floatToSortableInt(Float.parseFloat(max)),
|
||||
minInclusive, maxInclusive);
|
||||
break;
|
||||
case LONG:
|
||||
filter = new LongTrieRangeFilter(field, field, precisionStep,
|
||||
"*".equals(min) ? null : Long.parseLong(min),
|
||||
"*".equals(max) ? null : Long.parseLong(max),
|
||||
inclusive, inclusive);
|
||||
min == null ? null : Long.parseLong(min),
|
||||
max == null ? null : Long.parseLong(max),
|
||||
minInclusive, maxInclusive);
|
||||
break;
|
||||
case DOUBLE:
|
||||
filter = new LongTrieRangeFilter(field, field, precisionStep,
|
||||
"*".equals(min) ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(min)),
|
||||
"*".equals(max) ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(max)),
|
||||
inclusive, inclusive);
|
||||
min == null ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(min)),
|
||||
max == null ? null : TrieUtils.doubleToSortableLong(Double.parseDouble(max)),
|
||||
minInclusive, maxInclusive);
|
||||
break;
|
||||
case DATE:
|
||||
filter = new LongTrieRangeFilter(field, field, precisionStep,
|
||||
"*".equals(min) ? null : dateField.parseMath(null, min).getTime(),
|
||||
"*".equals(max) ? null : dateField.parseMath(null, max).getTime(),
|
||||
inclusive, inclusive);
|
||||
min == null ? null : dateField.parseMath(null, min).getTime(),
|
||||
max == null ? null : dateField.parseMath(null, max).getTime(),
|
||||
minInclusive, maxInclusive);
|
||||
break;
|
||||
default:
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field");
|
||||
|
|
|
@ -119,7 +119,10 @@ public class SolrQueryParser extends QueryParser {
|
|||
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException {
|
||||
checkNullField(field);
|
||||
FieldType ft = schema.getFieldType(field);
|
||||
return ft.getRangeQuery(field, part1, part2, inclusive);
|
||||
return ft.getRangeQuery(field,
|
||||
"*".equals(part1) ? null : part1,
|
||||
"*".equals(part2) ? null : part2,
|
||||
inclusive, inclusive);
|
||||
}
|
||||
|
||||
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
|
||||
|
|
Loading…
Reference in New Issue