Example usage for org.apache.lucene.search.spans SpanContainingQuery SpanContainingQuery

List of usage examples for org.apache.lucene.search.spans SpanContainingQuery SpanContainingQuery

Introduction

In this page you can find the example usage for org.apache.lucene.search.spans SpanContainingQuery SpanContainingQuery.

Prototype

public SpanContainingQuery(SpanQuery big, SpanQuery little) 

Source Link

Document

Construct a SpanContainingQuery matching spans from big that contain at least one spans from little.

Usage

From source file:org.codelibs.elasticsearch.index.query.SpanContainingQueryBuilder.java

License:Apache License

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    Query innerBig = big.toQuery(context);
    assert innerBig instanceof SpanQuery;
    Query innerLittle = little.toQuery(context);
    assert innerLittle instanceof SpanQuery;
    return new SpanContainingQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
}

From source file:org.elasticsearch.index.query.SpanContainingQueryParser.java

License:Apache License

@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();

    float boost = 1.0f;
    String queryName = null;//  w  w w.ja v  a 2 s  .c o  m
    SpanQuery big = null;
    SpanQuery little = null;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            if ("big".equals(currentFieldName)) {
                Query query = parseContext.parseInnerQuery();
                if (!(query instanceof SpanQuery)) {
                    throw new QueryParsingException(parseContext,
                            "span_containing [big] must be of type span query");
                }
                big = (SpanQuery) query;
            } else if ("little".equals(currentFieldName)) {
                Query query = parseContext.parseInnerQuery();
                if (!(query instanceof SpanQuery)) {
                    throw new QueryParsingException(parseContext,
                            "span_containing [little] must be of type span query");
                }
                little = (SpanQuery) query;
            } else {
                throw new QueryParsingException(parseContext,
                        "[span_containing] query does not support [" + currentFieldName + "]");
            }
        } else if ("boost".equals(currentFieldName)) {
            boost = parser.floatValue();
        } else if ("_name".equals(currentFieldName)) {
            queryName = parser.text();
        } else {
            throw new QueryParsingException(parseContext,
                    "[span_containing] query does not support [" + currentFieldName + "]");
        }
    }

    if (big == null) {
        throw new QueryParsingException(parseContext, "span_containing must include [big]");
    }
    if (little == null) {
        throw new QueryParsingException(parseContext, "span_containing must include [little]");
    }

    Query query = new SpanContainingQuery(big, little);
    if (boost != 1.0F) {
        query.setBoost(boost);
    }
    if (queryName != null) {
        parseContext.addNamedQuery(queryName, query);
    }
    return query;
}