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

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

Introduction

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

Prototype

public SpanWithinQuery(SpanQuery big, SpanQuery little) 

Source Link

Document

Construct a SpanWithinQuery matching spans from little that are inside of big.

Usage

From source file:org.codelibs.elasticsearch.index.query.SpanWithinQueryBuilder.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 SpanWithinQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
}

From source file:org.elasticsearch.index.query.SpanWithinQueryParser.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 ww .  j  av  a  2s  .  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 == false) {
                    throw new QueryParsingException(parseContext,
                            "span_within [big] must be of type span query");
                }
                big = (SpanQuery) query;
            } else if ("little".equals(currentFieldName)) {
                Query query = parseContext.parseInnerQuery();
                if (query instanceof SpanQuery == false) {
                    throw new QueryParsingException(parseContext,
                            "span_within [little] must be of type span query");
                }
                little = (SpanQuery) query;
            } else {
                throw new QueryParsingException(parseContext,
                        "[span_within] 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_within] query does not support [" + currentFieldName + "]");
        }
    }

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

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