org.apache.lucene.search.NumericRangeQuery Java Examples

The following examples show how to use org.apache.lucene.search.NumericRangeQuery. 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: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloatClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 43.42F, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43.42f, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #2
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInteger() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #3
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testLong() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42L);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #4
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloat() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42.42F);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42.42F, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #5
Source File: MatchConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDouble() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    MatchCondition matchCondition = new MatchCondition(0.5f, "name", 42.42D);
    Query query = matchCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #6
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntegerClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42, 43, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #7
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntegerOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInteger(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #8
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testLongClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42L, 43, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43L, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #9
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testLongOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperLong(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42f, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42L, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #10
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloatOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperFloat(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42f, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42f, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #11
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoubleClose() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, 43.42D, false, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(43.42D, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #12
Source File: RangeConditionTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoubleOpen() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperDouble(1f));
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    RangeCondition rangeCondition = new RangeCondition(0.5f, "name", 42.42D, null, true, false);
    Query query = rangeCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(NumericRangeQuery.class, query.getClass());
    Assert.assertEquals("name", ((NumericRangeQuery<?>) query).getField());
    Assert.assertEquals(42.42D, ((NumericRangeQuery<?>) query).getMin());
    Assert.assertEquals(null, ((NumericRangeQuery<?>) query).getMax());
    Assert.assertEquals(true, ((NumericRangeQuery<?>) query).includesMin());
    Assert.assertEquals(false, ((NumericRangeQuery<?>) query).includesMax());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
Example #13
Source File: ZipscriptQueryExtension.java    From drftpd with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) {
    try {
        ZipscriptQueryParams queryParams = params.getExtensionData(ZipscriptQueryParams.ZIPSCRIPTQUERYPARAMS);
        if (queryParams.getMinPresent() != null || queryParams.getMaxPresent() != null) {
            Query presentQuery = NumericRangeQuery.newIntRange("present",
                    queryParams.getMinPresent(), queryParams.getMaxPresent(), true, true);
            query.add(presentQuery, Occur.MUST);
        }
        if (queryParams.getMinMissing() != null || queryParams.getMaxMissing() != null) {
            Query missingQuery = NumericRangeQuery.newIntRange("missing",
                    queryParams.getMinMissing(), queryParams.getMaxMissing(), true, true);
            query.add(missingQuery, Occur.MUST);
        }
        if (queryParams.getMinPercent() != null || queryParams.getMaxPercent() != null) {
            Query percentQuery = NumericRangeQuery.newIntRange("percent",
                    queryParams.getMinPercent(), queryParams.getMaxPercent(), true, true);
            query.add(percentQuery, Occur.MUST);
        }
    } catch (KeyNotFoundException e) {
        // No MP3 terms to include, return without amending query
    }
}
 
Example #14
Source File: ZipscriptQueryExtension.java    From drftpd with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) {
    try {
        ZipscriptQueryParams queryParams = params.getExtensionData(ZipscriptQueryParams.ZIPSCRIPTQUERYPARAMS);
        if (queryParams.getMinPresent() != null || queryParams.getMaxPresent() != null) {
            Query presentQuery = NumericRangeQuery.newIntRange("present",
                    queryParams.getMinPresent(), queryParams.getMaxPresent(), true, true);
            query.add(presentQuery, Occur.MUST);
        }
        if (queryParams.getMinMissing() != null || queryParams.getMaxMissing() != null) {
            Query missingQuery = NumericRangeQuery.newIntRange("missing",
                    queryParams.getMinMissing(), queryParams.getMaxMissing(), true, true);
            query.add(missingQuery, Occur.MUST);
        }
        if (queryParams.getMinPercent() != null || queryParams.getMaxPercent() != null) {
            Query percentQuery = NumericRangeQuery.newIntRange("percent",
                    queryParams.getMinPercent(), queryParams.getMaxPercent(), true, true);
            query.add(percentQuery, Occur.MUST);
        }
    } catch (KeyNotFoundException e) {
        // No MP3 terms to include, return without amending query
    }
}
 
Example #15
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 #16
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 #17
Source File: FlacQueryExtension.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) {
    try {
        FlacQueryParams queryParams = params.getExtensionData(FlacQueryParams.FLACQUERYPARAMS);
        if (queryParams.getGenre() != null) {
            Query genreQuery = LuceneUtils.analyze("flacGenre", TERM_GENRE, queryParams.getGenre());
            query.add(genreQuery, Occur.MUST);
        }
        if (queryParams.getTitle() != null) {
            Query titleQuery = LuceneUtils.analyze("flacTitle", TERM_TITLE, queryParams.getTitle());
            query.add(titleQuery, Occur.MUST);
        }
        if (queryParams.getArtist() != null) {
            Query artistQuery = LuceneUtils.analyze("flacArtist", TERM_ARTIST, queryParams.getArtist());
            query.add(artistQuery, Occur.MUST);
        }
        if (queryParams.getAlbum() != null) {
            Query albumQuery = LuceneUtils.analyze("flacAlbum", TERM_ALBUM, queryParams.getAlbum());
            query.add(albumQuery, Occur.MUST);
        }
        if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) {
            Query yearQuery = NumericRangeQuery.newIntRange("flacYear",
                    queryParams.getMinYear(), queryParams.getMaxYear(), true, true);
            query.add(yearQuery, Occur.MUST);
        }
    } catch (KeyNotFoundException e) {
        // No FLAC terms to include, return without amending query
    }
}
 
Example #18
Source File: FloatFieldMapper.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) {
    float iValue = parseValue(value);
    final float iSim = fuzziness.asFloat();
    return NumericRangeQuery.newFloatRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
Example #19
Source File: DoubleFieldMapper.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.newDoubleRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseDoubleValue(lowerTerm),
        upperTerm == null ? null : parseDoubleValue(upperTerm),
        includeLower, includeUpper);
}
 
Example #20
Source File: DoubleFieldMapper.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) {
    double iValue = parseDoubleValue(value);
    double iSim = fuzziness.asDouble();
    return NumericRangeQuery.newDoubleRange(names().indexName(), numericPrecisionStep(),
        iValue - iSim,
        iValue + iSim,
        true, true);
}
 
Example #21
Source File: IntegerFieldMapper.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.newIntRange(names().indexName(), numericPrecisionStep(),
        lowerTerm == null ? null : parseValue(lowerTerm),
        upperTerm == null ? null : parseValue(upperTerm),
        includeLower, includeUpper);
}
 
Example #22
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 #23
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 #24
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 #25
Source File: SuperParserTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public static void assertEqualsQuery(Query expected, Query actual) {
  assertEquals(expected.getClass(), actual.getClass());
  if (expected instanceof BooleanQuery) {
    assertEqualsBooleanQuery((BooleanQuery) expected, (BooleanQuery) actual);
  } else if (expected instanceof SuperQuery) {
    assertEqualsSuperQuery((SuperQuery) expected, (SuperQuery) actual);
  } else if (expected instanceof TermQuery) {
    assertEqualsTermQuery((TermQuery) expected, (TermQuery) actual);
  } else if (expected instanceof PrefixQuery) {
    assertEqualsPrefixQuery((PrefixQuery) expected, (PrefixQuery) actual);
  } else if (expected instanceof WildcardQuery) {
    assertEqualsWildcardQuery((WildcardQuery) expected, (WildcardQuery) actual);
  } else if (expected instanceof FuzzyQuery) {
    assertEqualsFuzzyQuery((FuzzyQuery) expected, (FuzzyQuery) actual);
  } else if (expected instanceof RegexpQuery) {
    assertEqualsRegexpQuery((RegexpQuery) expected, (RegexpQuery) actual);
  } else if (expected instanceof TermRangeQuery) {
    assertEqualsTermRangeQuery((TermRangeQuery) expected, (TermRangeQuery) actual);
  } else if (expected instanceof MatchAllDocsQuery) {
    assertEqualsMatchAllDocsQuery((MatchAllDocsQuery) expected, (MatchAllDocsQuery) actual);
  } else if (expected instanceof MultiPhraseQuery) {
    assertEqualsMultiPhraseQuery((MultiPhraseQuery) expected, (MultiPhraseQuery) actual);
  } else if (expected instanceof PhraseQuery) {
    assertEqualsPhraseQuery((PhraseQuery) expected, (PhraseQuery) actual);
  } else if (expected instanceof NumericRangeQuery<?>) {
    assertEqualsNumericRangeQuery((NumericRangeQuery<?>) expected, (NumericRangeQuery<?>) actual);
  } else {
    fail("Type [" + expected.getClass() + "] not supported");
  }
}
 
Example #26
Source File: HighlightHelper.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public static boolean shouldNumberBeHighlighted(String name, Number numericValue, Query query) {
  if (query instanceof BooleanQuery) {
    BooleanQuery booleanQuery = (BooleanQuery) query;
    for (BooleanClause booleanClause : booleanQuery) {
      if (booleanClause.isProhibited()) {
        continue;
      } else {
        if (shouldNumberBeHighlighted(name, numericValue, booleanClause.getQuery())) {
          return true;
        }
      }
    }
  } else {
    if (query instanceof NumericRangeQuery) {
      if (numericValue instanceof Integer) {
        return checkInteger(name, numericValue, query);
      } else if (numericValue instanceof Double) {
        return checkDouble(name, numericValue, query);
      } else if (numericValue instanceof Float) {
        return checkFloat(name, numericValue, query);
      } else if (numericValue instanceof Long) {
        return checkLong(name, numericValue, query);
      }
    }
  }
  return false;
}
 
Example #27
Source File: HighlightHelper.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static boolean checkLong(String name, Number numericValue, Query query) {
  long value = (Long) numericValue;
  NumericRangeQuery<Long> nrq = (NumericRangeQuery<Long>) query;
  if (!name.equals(nrq.getField())) {
    return false;
  }
  if (nrq.includesMin()) {
    if (nrq.includesMax()) {
      if (value >= nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value >= nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  } else {
    if (nrq.includesMax()) {
      if (value > nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value > nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #28
Source File: HighlightHelper.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static boolean checkFloat(String name, Number numericValue, Query query) {
  float value = (Float) numericValue;
  NumericRangeQuery<Float> nrq = (NumericRangeQuery<Float>) query;
  if (!name.equals(nrq.getField())) {
    return false;
  }
  if (nrq.includesMin()) {
    if (nrq.includesMax()) {
      if (value >= nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value >= nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  } else {
    if (nrq.includesMax()) {
      if (value > nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value > nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #29
Source File: HighlightHelper.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static boolean checkDouble(String name, Number numericValue, Query query) {
  double value = (Double) numericValue;
  NumericRangeQuery<Double> nrq = (NumericRangeQuery<Double>) query;
  if (!name.equals(nrq.getField())) {
    return false;
  }
  if (nrq.includesMin()) {
    if (nrq.includesMax()) {
      if (value >= nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value >= nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  } else {
    if (nrq.includesMax()) {
      if (value > nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value > nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #30
Source File: HighlightHelper.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static boolean checkInteger(String name, Number numericValue, Query query) {
  int value = (Integer) numericValue;
  NumericRangeQuery<Integer> nrq = (NumericRangeQuery<Integer>) query;
  if (!name.equals(nrq.getField())) {
    return false;
  }
  if (nrq.includesMin()) {
    if (nrq.includesMax()) {
      if (value >= nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value >= nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  } else {
    if (nrq.includesMax()) {
      if (value > nrq.getMin() && value <= nrq.getMax()) {
        return true;
      }
    } else {
      if (value > nrq.getMin() && value < nrq.getMax()) {
        return true;
      }
    }
  }
  return false;
}