Search in sources :

Example 1 with FieldMaskingSpanQuery

use of org.apache.lucene.search.spans.FieldMaskingSpanQuery in project elasticsearch by elastic.

the class FieldMaskingSpanQueryBuilder method doToQuery.

@Override
protected SpanQuery doToQuery(QueryShardContext context) throws IOException {
    String fieldInQuery = fieldName;
    MappedFieldType fieldType = context.fieldMapper(fieldName);
    if (fieldType != null) {
        fieldInQuery = fieldType.name();
    }
    Query innerQuery = queryBuilder.toQuery(context);
    assert innerQuery instanceof SpanQuery;
    return new FieldMaskingSpanQuery((SpanQuery) innerQuery, fieldInQuery);
}
Also used : Query(org.apache.lucene.search.Query) FieldMaskingSpanQuery(org.apache.lucene.search.spans.FieldMaskingSpanQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) FieldMaskingSpanQuery(org.apache.lucene.search.spans.FieldMaskingSpanQuery) FieldMaskingSpanQuery(org.apache.lucene.search.spans.FieldMaskingSpanQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Example 2 with FieldMaskingSpanQuery

use of org.apache.lucene.search.spans.FieldMaskingSpanQuery in project elasticsearch by elastic.

the class FieldMaskingSpanQueryBuilderTests method doAssertLuceneQuery.

@Override
protected void doAssertLuceneQuery(FieldMaskingSpanQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
    String fieldInQuery = queryBuilder.fieldName();
    MappedFieldType fieldType = context.getQueryShardContext().fieldMapper(fieldInQuery);
    if (fieldType != null) {
        fieldInQuery = fieldType.name();
    }
    assertThat(query, instanceOf(FieldMaskingSpanQuery.class));
    FieldMaskingSpanQuery fieldMaskingSpanQuery = (FieldMaskingSpanQuery) query;
    assertThat(fieldMaskingSpanQuery.getField(), equalTo(fieldInQuery));
    assertThat(fieldMaskingSpanQuery.getMaskedQuery(), equalTo(queryBuilder.innerQuery().toQuery(context.getQueryShardContext())));
}
Also used : MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) FieldMaskingSpanQuery(org.apache.lucene.search.spans.FieldMaskingSpanQuery)

Aggregations

FieldMaskingSpanQuery (org.apache.lucene.search.spans.FieldMaskingSpanQuery)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 Query (org.apache.lucene.search.Query)1 SpanQuery (org.apache.lucene.search.spans.SpanQuery)1