本文整理汇总了Java中org.apache.lucene.search.NumericRangeQuery.newFloatRange方法的典型用法代码示例。如果您正苦于以下问题:Java NumericRangeQuery.newFloatRange方法的具体用法?Java NumericRangeQuery.newFloatRange怎么用?Java NumericRangeQuery.newFloatRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.NumericRangeQuery
的用法示例。
在下文中一共展示了NumericRangeQuery.newFloatRange方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testRangeParsing
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Test
public void testRangeParsing() throws Exception {
NumericConfig numericConfig = new NumericConfig(8, NumberFormat.getNumberInstance(Locale.ENGLISH), FieldType.NumericType.FLOAT);
HashMap<String, NumericConfig> numericConfigMap = new HashMap<String, NumericConfig>();
numericConfigMap.put("reflec_7", numericConfig);
numericConfigMap.put("reflec_8", numericConfig);
numericConfigMap.put("reflec_9", numericConfig);
StandardQueryParser parser = new StandardQueryParser();
parser.setNumericConfigMap(numericConfigMap);
Query query1 = parser.parse("reflec_8:[0.0 TO 1.0]", "x");
assertEquals(NumericRangeQuery.class, query1.getClass());
Query query2 = parser.parse("reflec_8:[0.0 TO 1.0] AND reflec_9:[0.2 TO 0.6]^3.1", "x");
assertEquals(BooleanQuery.class, query2.getClass());
BooleanClause clause1 = ((BooleanQuery) query2).getClauses()[0];
BooleanClause clause2 = ((BooleanQuery) query2).getClauses()[1];
NumericRangeQuery<Float> nrq1 = NumericRangeQuery.newFloatRange("reflec_8", 8, 0.0F, 1.0F, true, true);
NumericRangeQuery<Float> nrq2 = NumericRangeQuery.newFloatRange("reflec_9", 8, 0.2F, 0.6F, true, true);
nrq2.setBoost(3.1F);
assertEquals(nrq1, clause1.getQuery());
assertEquals(BooleanClause.Occur.MUST, clause1.getOccur());
assertEquals(nrq2, clause2.getQuery());
assertEquals(BooleanClause.Occur.MUST, clause2.getOccur());
}
示例3: 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);
}
}
示例4: rangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
return NumericRangeQuery.newFloatRange(names().indexName(), numericPrecisionStep(),
lowerTerm == null ? null : parseValue(lowerTerm),
upperTerm == null ? null : parseValue(upperTerm),
includeLower, includeUpper);
}
示例5: fuzzyQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
float iValue = parseValue(value);
final float iSim = fuzziness.asFloat();
return NumericRangeQuery.newFloatRange(names().indexName(), numericPrecisionStep(),
iValue - iSim,
iValue + iSim,
true, true);
}
示例6: toRangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query toRangeQuery(RangeFloat range) {
return NumericRangeQuery.newFloatRange(
range.getField(),
range.hasMin() ? range.getMin() : null,
range.hasMax() ? range.getMax() : null,
range.getMinInclusive(),
range.getMaxInclusive());
}
示例7: toTermFloatQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query toTermFloatQuery(SearchQuery.TermFloat term) {
return NumericRangeQuery.newFloatRange(
term.getField(),
term.getValue(),
term.getValue(),
true,
true);
}
示例8: _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;
}
示例9: 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 );
}
示例10: 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));
}
}
示例11: exactSearch
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
/**
* exact search
* @param fieldNum field num
* @param fieldValue field value
* @param n max results
* @return document list
* @throws IOException IOException
*/
public Document[] exactSearch(int fieldNum, String fieldValue, int n) throws IOException {
IndexSearcher searcher = manager.acquire();
if (n < 0) {
n = writer.maxDoc();
}
Query query = null;
TopDocs top = null;
String fieldName = fieldNames[fieldNum];
switch(fieldTypeEnums[fieldNum]) {
case DoubleField:
double doubleValue = Double.valueOf(fieldValue);
query = NumericRangeQuery.newDoubleRange(fieldName, doubleValue, doubleValue, true, true);
break;
case FloatField:
float floatValue = Float.valueOf(fieldValue);
query = NumericRangeQuery.newFloatRange(fieldName, floatValue, floatValue, true, true);
break;
case IntField:
int intValue = Integer.valueOf(fieldValue);
query = NumericRangeQuery.newIntRange(fieldName, intValue, intValue, true, true);
break;
case LongField:
long longValue = Long.valueOf(fieldValue);
query = NumericRangeQuery.newLongRange(fieldName, longValue, longValue, true, true);
break;
case StoredField:
break;
case StringField:
query = new TermQuery(new Term(fieldName, fieldValue));
break;
case TextField:
// parser is not MTSafe. create new instance
query = createQueryParser().createPhraseQuery(fieldName, fieldValue);
ExactCollector collector = new ExactCollector(searcher, fieldName, fieldValue, n);
searcher.search(query, collector);
top = collector.topDocs();
break;
}
// not TextField
if (top == null && query != null) {
top = searcher.search(query, n, Sort.INDEXORDER);
}
Document[] docs = createDocumentResult(searcher, top);
manager.release(searcher);
return docs;
}
示例12: parse
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
public static Query parse(String field, float value){
return NumericRangeQuery.newFloatRange(field, value, value, true, true);
}
示例13: getNewRangeQuery
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
@Override
public Query getNewRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) {
float p1 = parseFloat(part1);
float p2 = parseFloat(part2);
return NumericRangeQuery.newFloatRange(field, _precisionStep, p1, p2, startInclusive, endInclusive);
}
示例14: rq_i
import org.apache.lucene.search.NumericRangeQuery; //导入方法依赖的package包/类
private Query rq_i(String field, float min, float max) {
return NumericRangeQuery.newFloatRange(field, min, max, true, true);
}