Java Code Examples for org.apache.lucene.search.NumericRangeQuery#newLongRange()

The following examples show how to use org.apache.lucene.search.NumericRangeQuery#newLongRange() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/** {@inheritDoc} */
@Override
protected Query makeQuery(Token lower, Token upper, boolean includeLower, boolean includeUpper) {
    Long start = lower == null ? null : (Long) lower.getTokenValue();
    Long stop = upper == null ? null : (Long) upper.getTokenValue();
    if (lower != null && lower.isMinimum()) {
        start = null;
    }
    if (upper != null && upper.isMinimum()) {
        stop = null;
    }
    if (start == null && stop == null) {
        return null;
    }
    return NumericRangeQuery.newLongRange(FIELD_NAME, start, stop, includeLower, includeUpper);
}
 
Example 2
Source Project: Elasticsearch   File: IpFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseValue(lowerTerm),
        upperTerm == null ? null : parseValue(upperTerm),
        includeLower, includeUpper);
}
 
Example 3
Source Project: Elasticsearch   File: IpFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
    long iValue = parseValue(value);
    long iSim;
    try {
        iSim = ipToLong(fuzziness.asString());
    } catch (IllegalArgumentException e) {
        iSim = fuzziness.asLong();
    }
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
Example 4
Source Project: Elasticsearch   File: DateFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
    long iValue = parseValue(value);
    long iSim;
    try {
        iSim = fuzziness.asTimeValue().millis();
    } catch (Exception e) {
        // not a time format
        iSim =  fuzziness.asLong();
    }
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
Example 5
Source Project: Elasticsearch   File: LongFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseLongValue(lowerTerm),
        upperTerm == null ? null : parseLongValue(upperTerm),
        includeLower, includeUpper);
}
 
Example 6
Source Project: Elasticsearch   File: LongFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) {
    long iValue = parseLongValue(value);
    final long iSim = fuzziness.asLong();
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
Example 7
/**
 * Return a {@link Query} which is build based on the given {@link SearchQuery.SizeCriterion}
 */
private Query createSizeQuery(SearchQuery.SizeCriterion crit) throws UnsupportedSearchException {
    NumericOperator op = crit.getOperator();
    switch (op.getType()) {
    case EQUALS:
        return NumericRangeQuery.newLongRange(SIZE_FIELD, op.getValue(), op.getValue(), true, true);
    case GREATER_THAN:
        return NumericRangeQuery.newLongRange(SIZE_FIELD, op.getValue(), Long.MAX_VALUE, false, true);
    case LESS_THAN:
        return NumericRangeQuery.newLongRange(SIZE_FIELD, Long.MIN_VALUE, op.getValue(), true, false);
    default:
        throw new UnsupportedSearchException();
    }
}
 
Example 8
/**
 * Return a {@link Query} which is build based on the given {@link SearchQuery.UidCriterion}
 */
private Query createModSeqQuery(SearchQuery.ModSeqCriterion crit) throws UnsupportedSearchException {
    NumericOperator op = crit.getOperator();
    switch (op.getType()) {
    case EQUALS:
        return NumericRangeQuery.newLongRange(MODSEQ_FIELD, op.getValue(), op.getValue(), true, true);
    case GREATER_THAN:
        return NumericRangeQuery.newLongRange(MODSEQ_FIELD, op.getValue(), Long.MAX_VALUE, false, true);
    case LESS_THAN:
        return NumericRangeQuery.newLongRange(MODSEQ_FIELD, Long.MIN_VALUE, op.getValue(), true, false);
    default:
        throw new UnsupportedSearchException();
    }
}
 
Example 9
private Query createQuery(MessageRange range) {
    switch (range.getType()) {
    case ONE:
        return NumericRangeQuery.newLongRange(UID_FIELD, 
                range.getUidFrom().asLong(), 
                range.getUidTo().asLong(), true, true);
    case FROM:
        return NumericRangeQuery.newLongRange(UID_FIELD, 
                range.getUidFrom().asLong(), 
                MessageUid.MAX_VALUE.asLong(), true, true);
    default:
        return NumericRangeQuery.newLongRange(UID_FIELD, MessageUid.MIN_VALUE.asLong(), MessageUid.MAX_VALUE.asLong(), true, true);
    }
}
 
Example 10
Source Project: Elasticsearch   File: DateFieldMapper.java    License: Apache License 2.0 4 votes vote down vote up
private Query innerRangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, @Nullable DateTimeZone timeZone, @Nullable DateMathParser forcedDateParser) {
    return NumericRangeQuery.newLongRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseToMilliseconds(lowerTerm, !includeLower, timeZone, forcedDateParser == null ? dateMathParser : forcedDateParser),
        upperTerm == null ? null : parseToMilliseconds(upperTerm, includeUpper, timeZone, forcedDateParser == null ? dateMathParser : forcedDateParser),
        includeLower, includeUpper);
}
 
Example 11
Source Project: exhibitor   File: QueryBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public QueryBuilder     dateRange(Date startDate, Date endDate)
{
    NumericRangeQuery<Long> query = NumericRangeQuery.newLongRange(FieldNames.DATE, startDate.getTime(), endDate.getTime(), true, false);
    queries.add(query);
    return this;
}
 
Example 12
/** {@inheritDoc} */
@Override
public Query query(Token token) {
    Long value = (Long) token.getTokenValue();
    return NumericRangeQuery.newLongRange(FIELD_NAME, value, value, true, true);
}
 
Example 13
@Override
public Query getNewRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) {
  long p1 = parseDate(part1);
  long p2 = parseDate(part2);
  return NumericRangeQuery.newLongRange(field, _precisionStep, p1, p2, startInclusive, endInclusive);
}
 
Example 14
@Override
public Query getNewRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) {
  long p1 = parseLong(part1);
  long p2 = parseLong(part2);
  return NumericRangeQuery.newLongRange(field, _precisionStep, p1, p2, startInclusive, endInclusive);
}
 
Example 15
private Query rq_i(String field, long min, long max) {
  return NumericRangeQuery.newLongRange(field, min, max, true, true);
}
 
Example 16
private Query rq_e(String field, long min, long max) {
  return NumericRangeQuery.newLongRange(field, min, max, false, false);
}