本文整理汇总了Java中org.apache.lucene.search.NumericRangeQuery.newDoubleRange方法的典型用法代码示例。如果您正苦于以下问题:Java NumericRangeQuery.newDoubleRange方法的具体用法?Java NumericRangeQuery.newDoubleRange怎么用?Java NumericRangeQuery.newDoubleRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.NumericRangeQuery
的用法示例。
在下文中一共展示了NumericRangeQuery.newDoubleRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
* Will create a {@link Query} with a query for numeric ranges, that is
* values that have been indexed using {@link ValueContext#indexNumeric()}.
* It will match the type of numbers supplied to the type of values that
* are indexed in the index, f.ex. long, int, float and double.
* If both {@code from} and {@code to} is {@code null} then it will default
* to int.
*
* @param key the property key to query.
* @param from the low end of the range (inclusive)
* @param to the high end of the range (inclusive)
* @param includeFrom whether or not {@code from} (the lower bound) is inclusive
* or not.
* @param includeTo whether or not {@code to} (the higher bound) is inclusive
* or not.
* @return a {@link Query} to do numeric range queries with.
*/
public static Query rangeQuery( String key, Number from, Number to,
boolean includeFrom, boolean includeTo )
{
if ( from instanceof Long || to instanceof Long )
{
return NumericRangeQuery.newLongRange( key, from != null ? from.longValue() : 0,
to != null ? to.longValue() : Long.MAX_VALUE, includeFrom, includeTo );
}
else if ( from instanceof Double || to instanceof Double )
{
return NumericRangeQuery.newDoubleRange( key, from != null ? from.doubleValue() : 0,
to != null ? to.doubleValue() : Double.MAX_VALUE, includeFrom, includeTo );
}
else if ( from instanceof Float || to instanceof Float )
{
return NumericRangeQuery.newFloatRange( key, from != null ? from.floatValue() : 0,
to != null ? to.floatValue() : Float.MAX_VALUE, includeFrom, includeTo );
}
else
{
return NumericRangeQuery.newIntRange( key, from != null ? from.intValue() : 0,
to != null ? to.intValue() : Integer.MAX_VALUE, includeFrom, includeTo );
}
}
示例2: extractPromotionalProducts
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public List<Products> extractPromotionalProducts() {
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
em );
org.apache.lucene.search.Query query = NumericRangeQuery.newDoubleRange( "old_price" , 0.0d ,
1000d , false ,
true );
FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
Products.class );
Sort sort = new Sort( new SortField( "price" , SortField.DOUBLE ) );
fullTextQuery.setSort( sort );
//fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
List results = fullTextQuery.getResultList();
return results;
}
示例3: getRangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public Query getRangeQuery(String field,
String part1,
String part2,
boolean inclusive)
throws ParseException {
TermRangeQuery query = (TermRangeQuery)
super.getRangeQuery(field, part1, part2,
inclusive);
if ("price".equals(field)) {
return NumericRangeQuery.newDoubleRange(
"price",
Double.parseDouble(
query.getLowerTerm()),
Double.parseDouble(
query.getUpperTerm()),
query.includesLower(),
query.includesUpper());
} else {
return query;
}
}
示例4: getQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String lowerTerm = DOMUtils.getAttributeOrFail(e, "lowerTerm");
String upperTerm = DOMUtils.getAttributeOrFail(e, "upperTerm");
boolean lowerInclusive = DOMUtils.getAttribute(e, "includeLower", true);
boolean upperInclusive = DOMUtils.getAttribute(e, "includeUpper", true);
int precisionStep = DOMUtils.getAttribute(e, "precisionStep", NumericUtils.PRECISION_STEP_DEFAULT);
String type = DOMUtils.getAttribute(e, "type", "int");
try {
Query filter;
if (type.equalsIgnoreCase("int")) {
filter = NumericRangeQuery.newIntRange(field, precisionStep, Integer
.valueOf(lowerTerm), Integer.valueOf(upperTerm), lowerInclusive,
upperInclusive);
} else if (type.equalsIgnoreCase("long")) {
filter = NumericRangeQuery.newLongRange(field, precisionStep, Long
.valueOf(lowerTerm), Long.valueOf(upperTerm), lowerInclusive,
upperInclusive);
} else if (type.equalsIgnoreCase("double")) {
filter = NumericRangeQuery.newDoubleRange(field, precisionStep, Double
.valueOf(lowerTerm), Double.valueOf(upperTerm), lowerInclusive,
upperInclusive);
} else if (type.equalsIgnoreCase("float")) {
filter = NumericRangeQuery.newFloatRange(field, precisionStep, Float
.valueOf(lowerTerm), Float.valueOf(upperTerm), lowerInclusive,
upperInclusive);
} else {
throw new ParserException("type attribute must be one of: [long, int, double, float]");
}
return filter;
} catch (NumberFormatException nfe) {
throw new ParserException("Could not parse lowerTerm or upperTerm into a number", nfe);
}
}
示例5: rangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
return NumericRangeQuery.newDoubleRange(names().indexName(), numericPrecisionStep(),
lowerTerm == null ? null : parseDoubleValue(lowerTerm),
upperTerm == null ? null : parseDoubleValue(upperTerm),
includeLower, includeUpper);
}
示例6: fuzzyQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
double iValue = parseDoubleValue(value);
double iSim = fuzziness.asDouble();
return NumericRangeQuery.newDoubleRange(names().indexName(), numericPrecisionStep(),
iValue - iSim,
iValue + iSim,
true, true);
}
示例7: toRangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query toRangeQuery(RangeDouble range) {
return NumericRangeQuery.newDoubleRange(
range.getField(),
range.hasMin() ? range.getMin() : null,
range.hasMax() ? range.getMax() : null,
range.getMinInclusive(),
range.getMaxInclusive());
}
示例8: toTermDoubleQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query toTermDoubleQuery(SearchQuery.TermDouble term) {
return NumericRangeQuery.newDoubleRange(
term.getField(),
term.getValue(),
term.getValue(),
true,
true);
}
示例9: createNumericRangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public static Query createNumericRangeQuery(final String field, final double min, final double max, final boolean minInclusive, final boolean maxInclusive) {
return new Query() {
@Override
public org.apache.lucene.search.Query getLuceneQuery(Schema schema) {
validateType(field, schema, JsonNode.Type.NUMBER);
return NumericRangeQuery.newDoubleRange(field, min, max, minInclusive, maxInclusive);
}
};
}
示例10: rangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private NumericRangeQuery<Double> rangeQuery(String fieldName, Double min, Double max) {
return NumericRangeQuery.newDoubleRange(
fieldName,
precisionStep,
min,
max,
true,
true);//inclusive
}
示例11: _numberInRangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private static <N extends Number & Comparable> Query _numberInRangeQuery(final IndexDocumentFieldID fieldId,
final Range<N> range,
final Class<N> numberType) {
boolean lowerIncluded = range.hasLowerBound() && range.lowerBoundType() == BoundType.CLOSED;
boolean upperIncluded = range.hasUpperBound() && range.upperBoundType() == BoundType.CLOSED;
N lowerBound = range.hasLowerBound() ? range.lowerEndpoint() : null;
N upperBound = range.hasUpperBound() ? range.upperEndpoint() : null;
Query outNumberEqQry = null;
if (numberType.equals(Integer.class)) {
outNumberEqQry = NumericRangeQuery.newIntRange(fieldId.asString(),
(Integer)lowerBound,(Integer)upperBound,
lowerIncluded,upperIncluded);
} else if (numberType.equals(Long.class)) {
outNumberEqQry = NumericRangeQuery.newLongRange(fieldId.asString(),
(Long)lowerBound,(Long)upperBound,
lowerIncluded,upperIncluded);
} else if (numberType.equals(Double.class)) {
outNumberEqQry = NumericRangeQuery.newDoubleRange(fieldId.asString(),
(Double)lowerBound,(Double)upperBound,
lowerIncluded,upperIncluded);
} else if (numberType.equals(Float.class)) {
outNumberEqQry = NumericRangeQuery.newFloatRange(fieldId.asString(),
(Float)lowerBound,(Float)upperBound,
lowerIncluded,upperIncluded);
}
return outNumberEqQry;
}
示例12: newInclusiveNumericRangeSeekQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
* Range queries are always inclusive, in order to do exclusive range queries the result must be filtered after the
* fact. The reason we can't do inclusive range queries is that longs are coerced to doubles in the index.
*/
public NumericRangeQuery<Double> newInclusiveNumericRangeSeekQuery( Number lower, Number upper )
{
Double min = lower != null ? lower.doubleValue() : null;
Double max = upper != null ? upper.doubleValue() : null;
return NumericRangeQuery.newDoubleRange( ValueEncoding.Number.key(), min, max, true, true );
}
示例13: makeEquals
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
* Constructs a query to retrieve documents that equal the input envelope.
* @return the spatial query
*/
private Query makeEquals() {
// docMinX = qryMinX AND docMinY = qryMinY AND docMaxX = qryMaxX AND docMaxY = qryMaxY
Query qMinX = NumericRangeQuery.newDoubleRange(docMinX,qryMinX,qryMinX,true,true);
Query qMinY = NumericRangeQuery.newDoubleRange(docMinY,qryMinY,qryMinY,true,true);
Query qMaxX = NumericRangeQuery.newDoubleRange(docMaxX,qryMaxX,qryMaxX,true,true);
Query qMaxY = NumericRangeQuery.newDoubleRange(docMaxY,qryMaxY,qryMaxY,true,true);
BooleanQuery bq = new BooleanQuery();
bq.add(qMinX,BooleanClause.Occur.MUST);
bq.add(qMinY,BooleanClause.Occur.MUST);
bq.add(qMaxX,BooleanClause.Occur.MUST);
bq.add(qMaxY,BooleanClause.Occur.MUST);
return bq;
}
示例14: numericRange
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
* Will create a {@link QueryContext} with a query for numeric ranges, that is
* values that have been indexed using {@link ValueContext#indexNumeric()}.
* It will match the type of numbers supplied to the type of values that
* are indexed in the index, f.ex. long, int, float and double.
* If both {@code from} and {@code to} is {@code null} then it will default
* to int.
*
* @param key the property key to query.
* @param from the low end of the range (inclusive)
* @param to the high end of the range (inclusive)
* @param includeFrom whether or not {@code from} (the lower bound) is inclusive
* or not.
* @param includeTo whether or not {@code to} (the higher bound) is inclusive
* or not.
* @return a {@link QueryContext} to do numeric range queries with.
*/
public static QueryContext numericRange( String key, Number from, Number to,
boolean includeFrom, boolean includeTo )
{
Query query = null;
if ( from instanceof Long )
{
query = NumericRangeQuery.newLongRange( key, from != null ? from.longValue() : 0,
to != null ? to.longValue() : Long.MAX_VALUE, includeFrom, includeTo );
}
else if ( from instanceof Double )
{
query = NumericRangeQuery.newDoubleRange( key, from != null ? from.doubleValue() : 0,
to != null ? to.doubleValue() : Double.MAX_VALUE, includeFrom, includeTo );
}
else if ( from instanceof Float )
{
query = NumericRangeQuery.newFloatRange( key, from != null ? from.floatValue() : 0,
to != null ? to.floatValue() : Float.MAX_VALUE, includeFrom, includeTo );
}
else
{
query = NumericRangeQuery.newIntRange( key, from != null ? from.intValue() : 0,
to != null ? to.intValue() : Integer.MAX_VALUE, includeFrom, includeTo );
}
return new QueryContext( query );
}
示例15: build
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public NumericRangeQuery<? extends Number> build(QueryNode queryNode)
throws QueryNodeException {
NumericRangeQueryNode numericRangeNode = (NumericRangeQueryNode) queryNode;
NumericQueryNode lowerNumericNode = numericRangeNode.getLowerBound();
NumericQueryNode upperNumericNode = numericRangeNode.getUpperBound();
Number lowerNumber = lowerNumericNode.getValue();
Number upperNumber = upperNumericNode.getValue();
NumericConfig numericConfig = numericRangeNode.getNumericConfig();
NumericType numberType = numericConfig.getType();
String field = StringUtils.toString(numericRangeNode.getField());
boolean minInclusive = numericRangeNode.isLowerInclusive();
boolean maxInclusive = numericRangeNode.isUpperInclusive();
int precisionStep = numericConfig.getPrecisionStep();
switch (numberType) {
case LONG:
return NumericRangeQuery.newLongRange(field, precisionStep,
(Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive);
case INT:
return NumericRangeQuery.newIntRange(field, precisionStep,
(Integer) lowerNumber, (Integer) upperNumber, minInclusive,
maxInclusive);
case FLOAT:
return NumericRangeQuery.newFloatRange(field, precisionStep,
(Float) lowerNumber, (Float) upperNumber, minInclusive,
maxInclusive);
case DOUBLE:
return NumericRangeQuery.newDoubleRange(field, precisionStep,
(Double) lowerNumber, (Double) upperNumber, minInclusive,
maxInclusive);
default :
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
}
}