use of org.apache.lucene.search.IndexOrDocValuesQuery in project elasticsearch by elastic.
the class RangeQueryBuilderTests method testDateRangeBoundaries.
public void testDateRangeBoundaries() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
String query = "{\n" + " \"range\" : {\n" + " \"" + DATE_FIELD_NAME + "\" : {\n" + " \"gte\": \"2014-11-05||/M\",\n" + " \"lte\": \"2014-12-08||/d\"\n" + " }\n" + " }\n" + "}\n";
Query parsedQuery = parseQuery(query).toQuery(createShardContext());
assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class));
parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery();
assertThat(parsedQuery, instanceOf(PointRangeQuery.class));
assertEquals(LongPoint.newRangeQuery(DATE_FIELD_NAME, DateTime.parse("2014-11-01T00:00:00.000+00").getMillis(), DateTime.parse("2014-12-08T23:59:59.999+00").getMillis()), parsedQuery);
query = "{\n" + " \"range\" : {\n" + " \"" + DATE_FIELD_NAME + "\" : {\n" + " \"gt\": \"2014-11-05||/M\",\n" + " \"lt\": \"2014-12-08||/d\"\n" + " }\n" + " }\n" + "}";
parsedQuery = parseQuery(query).toQuery(createShardContext());
assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class));
parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery();
assertThat(parsedQuery, instanceOf(PointRangeQuery.class));
assertEquals(LongPoint.newRangeQuery(DATE_FIELD_NAME, DateTime.parse("2014-11-30T23:59:59.999+00").getMillis() + 1, DateTime.parse("2014-12-08T00:00:00.000+00").getMillis() - 1), parsedQuery);
}
use of org.apache.lucene.search.IndexOrDocValuesQuery in project elasticsearch by elastic.
the class RangeQueryBuilderTests method testToQueryNumericField.
public void testToQueryNumericField() throws IOException {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
Query parsedQuery = rangeQuery(INT_FIELD_NAME).from(23).to(54).includeLower(true).includeUpper(false).toQuery(createShardContext());
// since age is automatically registered in data, we encode it as numeric
assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class));
parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery();
assertThat(parsedQuery, instanceOf(PointRangeQuery.class));
assertEquals(IntPoint.newRangeQuery(INT_FIELD_NAME, 23, 53), parsedQuery);
}
use of org.apache.lucene.search.IndexOrDocValuesQuery in project elasticsearch by elastic.
the class GeoBoundingBoxQueryBuilderTests method doAssertLuceneQuery.
@Override
protected void doAssertLuceneQuery(GeoBoundingBoxQueryBuilder queryBuilder, Query query, SearchContext searchContext) throws IOException {
QueryShardContext context = searchContext.getQueryShardContext();
MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName());
if (fieldType == null) {
assertTrue("Found no indexed geo query.", query instanceof MatchNoDocsQuery);
} else if (query instanceof IndexOrDocValuesQuery) {
// TODO: remove the if statement once we always use LatLonPoint
Query indexQuery = ((IndexOrDocValuesQuery) query).getIndexQuery();
assertEquals(LatLonPoint.newBoxQuery(queryBuilder.fieldName(), queryBuilder.bottomRight().lat(), queryBuilder.topLeft().lat(), queryBuilder.topLeft().lon(), queryBuilder.bottomRight().lon()), indexQuery);
Query dvQuery = ((IndexOrDocValuesQuery) query).getRandomAccessQuery();
assertEquals(LatLonDocValuesField.newBoxQuery(queryBuilder.fieldName(), queryBuilder.bottomRight().lat(), queryBuilder.topLeft().lat(), queryBuilder.topLeft().lon(), queryBuilder.bottomRight().lon()), dvQuery);
}
}
use of org.apache.lucene.search.IndexOrDocValuesQuery in project elasticsearch by elastic.
the class GeoDistanceQueryBuilderTests method doAssertLuceneQuery.
@Override
protected void doAssertLuceneQuery(GeoDistanceQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
// TODO: remove the if statement once we always use LatLonPoint
if (query instanceof IndexOrDocValuesQuery) {
Query indexQuery = ((IndexOrDocValuesQuery) query).getIndexQuery();
assertEquals(LatLonPoint.newDistanceQuery(queryBuilder.fieldName(), queryBuilder.point().lat(), queryBuilder.point().lon(), queryBuilder.distance()), indexQuery);
Query dvQuery = ((IndexOrDocValuesQuery) query).getRandomAccessQuery();
assertEquals(LatLonDocValuesField.newDistanceQuery(queryBuilder.fieldName(), queryBuilder.point().lat(), queryBuilder.point().lon(), queryBuilder.distance()), dvQuery);
}
}
use of org.apache.lucene.search.IndexOrDocValuesQuery in project crate by crate.
the class IntEqQuery method rangeQuery.
@Override
public Query rangeQuery(String field, Number lowerTerm, Number upperTerm, boolean includeLower, boolean includeUpper) {
int lower = Integer.MIN_VALUE;
if (lowerTerm != null) {
lower = includeLower ? lowerTerm.intValue() : lowerTerm.intValue() + 1;
}
int upper = Integer.MAX_VALUE;
if (upperTerm != null) {
upper = includeUpper ? upperTerm.intValue() : upperTerm.intValue() - 1;
}
Query indexquery = IntPoint.newRangeQuery(field, lower, upper);
return new IndexOrDocValuesQuery(indexquery, SortedNumericDocValuesField.newSlowRangeQuery(field, lower, upper));
}
Aggregations