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

The following examples show how to use org.apache.lucene.search.NumericRangeQuery#newLongRange() . 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
Source File: TokenMapperMurmur.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/** {@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 File: IpFieldMapper.java    From Elasticsearch with 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 File: IpFieldMapper.java    From Elasticsearch with 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 File: DateFieldMapper.java    From Elasticsearch with 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 File: LongFieldMapper.java    From Elasticsearch with 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 File: LongFieldMapper.java    From Elasticsearch with 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
Source File: LuceneMessageSearchIndex.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: LuceneMessageSearchIndex.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: LuceneMessageSearchIndex.java    From james-project with Apache License 2.0 5 votes vote down vote up
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 File: DateFieldMapper.java    From Elasticsearch with 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 File: QueryBuilder.java    From exhibitor with 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
Source File: TokenMapperMurmur.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public Query query(Token token) {
    Long value = (Long) token.getTokenValue();
    return NumericRangeQuery.newLongRange(FIELD_NAME, value, value, true, true);
}
 
Example 13
Source File: DateFieldTypeDefinition.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
@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
Source File: LongFieldTypeDefinition.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
@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
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
private Query rq_i(String field, long min, long max) {
  return NumericRangeQuery.newLongRange(field, min, max, true, true);
}
 
Example 16
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
private Query rq_e(String field, long min, long max) {
  return NumericRangeQuery.newLongRange(field, min, max, false, false);
}