Search in sources :

Example 1 with AnyQueryNode

use of org.apache.lucene.queryparser.flexible.core.nodes.AnyQueryNode in project lucene-solr by apache.

the class AnyQueryNodeBuilder method build.

@Override
public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
    AnyQueryNode andNode = (AnyQueryNode) queryNode;
    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
    List<QueryNode> children = andNode.getChildren();
    if (children != null) {
        for (QueryNode child : children) {
            Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            if (obj != null) {
                Query query = (Query) obj;
                try {
                    bQuery.add(query, BooleanClause.Occur.SHOULD);
                } catch (TooManyClauses ex) {
                    throw new QueryNodeException(new MessageImpl(/*
             * IQQQ.Q0028E_TOO_MANY_BOOLEAN_CLAUSES,
             * BooleanQuery.getMaxClauseCount()
             */
                    QueryParserMessages.EMPTY_MESSAGE), ex);
                }
            }
        }
    }
    bQuery.setMinimumNumberShouldMatch(andNode.getMinimumMatchingElements());
    return bQuery.build();
}
Also used : QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) AnyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AnyQueryNode) QueryTreeBuilder(org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder) TooManyClauses(org.apache.lucene.search.BooleanQuery.TooManyClauses) AnyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AnyQueryNode) MessageImpl(org.apache.lucene.queryparser.flexible.messages.MessageImpl)

Aggregations

QueryNodeException (org.apache.lucene.queryparser.flexible.core.QueryNodeException)1 QueryTreeBuilder (org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder)1 AnyQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.AnyQueryNode)1 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)1 MessageImpl (org.apache.lucene.queryparser.flexible.messages.MessageImpl)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 TooManyClauses (org.apache.lucene.search.BooleanQuery.TooManyClauses)1 Query (org.apache.lucene.search.Query)1