Search in sources :

Example 11 with IndexOrDocValuesQuery

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);
}
Also used : Query(org.apache.lucene.search.Query) QueryBuilders.rangeQuery(org.elasticsearch.index.query.QueryBuilders.rangeQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery)

Example 12 with IndexOrDocValuesQuery

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);
}
Also used : Query(org.apache.lucene.search.Query) QueryBuilders.rangeQuery(org.elasticsearch.index.query.QueryBuilders.rangeQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery)

Example 13 with IndexOrDocValuesQuery

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);
    }
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery)

Example 14 with IndexOrDocValuesQuery

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);
    }
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery)

Example 15 with IndexOrDocValuesQuery

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));
}
Also used : Query(org.apache.lucene.search.Query) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) IndexOrDocValuesQuery(org.apache.lucene.search.IndexOrDocValuesQuery) IntPoint(org.apache.lucene.document.IntPoint)

Aggregations

IndexOrDocValuesQuery (org.apache.lucene.search.IndexOrDocValuesQuery)16 Query (org.apache.lucene.search.Query)14 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)6 PointRangeQuery (org.apache.lucene.search.PointRangeQuery)6 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)5 IntPoint (org.apache.lucene.document.IntPoint)4 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)4 QueryBuilders.rangeQuery (org.elasticsearch.index.query.QueryBuilders.rangeQuery)4 LongPoint (org.apache.lucene.document.LongPoint)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 FloatPoint (org.apache.lucene.document.FloatPoint)2 Version (org.elasticsearch.Version)2 Settings (org.elasticsearch.common.settings.Settings)2 IndexSettings (org.elasticsearch.index.IndexSettings)2 GeoPointFieldType (org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType)2 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)2 DoublePoint (org.apache.lucene.document.DoublePoint)1 HalfFloatPoint (org.apache.lucene.document.HalfFloatPoint)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1