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

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

Introduction

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

Prototype

public SpanNotQuery(SpanQuery include, SpanQuery exclude, int pre, int post) 

Source Link

Document

Construct a SpanNotQuery matching spans from include which have no overlap with spans from exclude within pre tokens before or post tokens of include.

Usage

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

License:Apache License

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {

    Query includeQuery = this.include.toQuery(context);
    assert includeQuery instanceof SpanQuery;
    Query excludeQuery = this.exclude.toQuery(context);
    assert excludeQuery instanceof SpanQuery;

    return new SpanNotQuery((SpanQuery) includeQuery, (SpanQuery) excludeQuery, pre, post);
}

From source file:org.tallison.lucene.queryparser.spans.SpanQueryParserBase.java

License:Apache License

protected SpanQuery buildSpanNotNearQuery(List<SpanQuery> clauses, Integer pre, Integer post)
        throws ParseException {
    if (clauses.size() != 2) {
        throw new ParseException(
                String.format("SpanNotNear query must have two clauses. I count %d", clauses.size()));
    }//from ww w.  j  a va2 s . c o m
    // if include is an empty query, treat this as just an empty query
    if (isEmptyQuery(clauses.get(0))) {
        return clauses.get(0);
    }
    // if exclude is an empty query, return include alone
    if (isEmptyQuery(clauses.get(1))) {
        return clauses.get(0);
    }

    pre = (pre == null) ? 0 : pre;
    post = (post == null) ? pre : post;

    if (spanNotNearMaxDistance > -1 && pre > spanNotNearMaxDistance) {
        pre = spanNotNearMaxDistance;
    }
    if (spanNotNearMaxDistance > -1 && post > spanNotNearMaxDistance) {
        post = spanNotNearMaxDistance;
    }
    return new SpanNotQuery(clauses.get(0), clauses.get(1), pre, post);
}