Example usage for org.apache.lucene.queryparser.flexible.core QueryNodeException QueryNodeException

List of usage examples for org.apache.lucene.queryparser.flexible.core QueryNodeException QueryNodeException

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.core QueryNodeException QueryNodeException.

Prototype

public QueryNodeException(Message message, Throwable throwable) 

Source Link

Usage

From source file:com.sindicetech.siren.qparser.keyword.builders.AnyQueryNodeBuilder.java

License:Open Source License

public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
    AnyQueryNode andNode = (AnyQueryNode) queryNode;

    BooleanQuery bQuery = new BooleanQuery();
    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()
                             *///from w  ww  .j  av  a 2  s. c o  m
                            QueryParserMessages.EMPTY_MESSAGE), ex);

                }

            }

        }

    }

    bQuery.setMinimumNumberShouldMatch(andNode.getMinimumMatchingElements());

    return bQuery;

}

From source file:com.sindicetech.siren.qparser.keyword.builders.BooleanQueryNodeBuilder.java

License:Open Source License

public Query build(final QueryNode queryNode) throws QueryNodeException {
    final BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;

    final BooleanQuery bQuery = new BooleanQuery();
    final List<QueryNode> children = booleanNode.getChildren();

    if (children != null) {

        for (final QueryNode child : children) {
            final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

            if (obj != null) {
                final Query query = (Query) obj;

                try {
                    final QueryNode mod;
                    if (child instanceof DatatypeQueryNode) {
                        mod = ((DatatypeQueryNode) child).getChild();
                    } else {
                        mod = child;//from  w  w w . ja  va  2  s.  com
                    }
                    bQuery.add(query, getModifierValue(mod));

                } catch (final TooManyClauses ex) {

                    throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                            BooleanQuery.getMaxClauseCount(),
                            queryNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);

                }

            }

        }

    }

    return bQuery;

}

From source file:com.sindicetech.siren.qparser.tree.builders.BooleanQueryNodeBuilder.java

License:Open Source License

private final BooleanSpanQuery buildBooleanSpanQuery(BooleanQueryNode booleanNode) throws QueryNodeException {
    // check if the node has a slop
    int slop = this.DEFAULT_SLOP;
    if (booleanNode.getTag(SlopPropertyParser.SLOP_PROPERTY) != null) {
        slop = (Integer) booleanNode.getTag(SlopPropertyParser.SLOP_PROPERTY);
    }//from  w ww  .  j  av  a2  s . c om

    // check if the node has a inOrder flag
    boolean inOrder = this.DEFAULT_INORDER;
    if (booleanNode.getTag(InOrderPropertyParser.IN_ORDER_PROPERTY) != null) {
        int tag = (Integer) booleanNode.getTag(InOrderPropertyParser.IN_ORDER_PROPERTY);
        inOrder = tag == 0 ? false : true;
    }

    // build the query and add clauses
    final BooleanSpanQuery bsq = new BooleanSpanQuery(slop, inOrder);
    for (final QueryNode child : booleanNode.getChildren()) {
        final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        try {
            bsq.add(new NodeSpanQuery((NodeQuery) obj), this.getNodeModifierValue(child));
        } catch (final BooleanQuery.TooManyClauses ex) {
            throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                    BooleanQuery.getMaxClauseCount(), booleanNode.toQueryString(new EscapeQuerySyntaxImpl())),
                    ex);
        }
    }

    // check if the node has a node range constraint
    if (booleanNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) {
        final int[] range = (int[]) booleanNode.getTag(RangePropertyParser.RANGE_PROPERTY);
        bsq.setNodeConstraint(range[0], range[1]);
    }

    return bsq;
}

From source file:com.sindicetech.siren.qparser.tree.builders.BooleanQueryNodeBuilder.java

License:Open Source License

private final BooleanQuery buildBooleanQuery(BooleanQueryNode booleanNode) throws QueryNodeException {
    // build the query and add clauses
    final BooleanQuery bq = new BooleanQuery(true);

    for (final QueryNode child : booleanNode.getChildren()) {
        final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        try {/*  w w  w  . j  a v  a2  s . c  om*/
            Query q = (Query) obj;
            if (obj instanceof NodeQuery) {
                // wrap the query into a LuceneProxyNodeQuery
                q = new LuceneProxyNodeQuery((NodeQuery) q);
            }
            bq.add(q, this.getLuceneModifierValue(child));
        } catch (final BooleanQuery.TooManyClauses ex) {
            throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                    BooleanQuery.getMaxClauseCount(), booleanNode.toQueryString(new EscapeQuerySyntaxImpl())),
                    ex);
        }
    }

    return bq;
}

From source file:com.sindicetech.siren.qparser.tree.builders.TwigQueryNodeBuilder.java

License:Open Source License

@Override
public TwigQuery build(final QueryNode queryNode) throws QueryNodeException {
    final TwigQueryNode twigNode = (TwigQueryNode) queryNode;
    final List<QueryNode> children = twigNode.getChildren();
    final TwigQuery query = new TwigQuery();

    // check if the node has a level constraint
    if (twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) {
        query.setLevelConstraint((Integer) twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY));
    }/*w  ww  .j  av a  2s.  c om*/

    // check if the node has a node range constraint
    if (twigNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) {
        final int[] range = (int[]) twigNode.getTag(RangePropertyParser.RANGE_PROPERTY);
        query.setNodeConstraint(range[0], range[1]);
    }

    // process root query
    this.processRoot(twigNode, query);

    // process child and descendant queries
    try {
        this.processChildren(children, query);
    } catch (final TooManyClauses ex) {
        throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                BooleanQuery.getMaxClauseCount(), twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
    }

    return query;
}

From source file:org.sindice.siren.qparser.json.builders.BooleanQueryNodeBuilder.java

License:Apache License

public BooleanQuery build(final QueryNode queryNode) throws QueryNodeException {
    final BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
    final BooleanQuery bQuery = new BooleanQuery(true);
    final List<QueryNode> children = booleanNode.getChildren();

    for (final QueryNode child : children) {
        final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        // wrap the query into a LuceneProxyNodeQuery
        final Query query = new LuceneProxyNodeQuery((NodeQuery) obj);
        try {/*w w  w .  j a  v  a 2 s  .  c  o  m*/
            bQuery.add(query, getModifierValue(child));
        } catch (final TooManyClauses ex) {
            throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                    BooleanQuery.getMaxClauseCount(), queryNode.toQueryString(new EscapeQuerySyntaxImpl())),
                    ex);
        }
    }
    return bQuery;
}

From source file:org.sindice.siren.qparser.json.builders.TwigQueryNodeBuilder.java

License:Apache License

@Override
public TwigQuery build(final QueryNode queryNode) throws QueryNodeException {
    final TwigQueryNode twigNode = (TwigQueryNode) queryNode;
    final List<QueryNode> children = twigNode.getChildren();
    final TwigQuery query = new TwigQuery();

    // check if the node has a level constraint
    if (twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) {
        query.setLevelConstraint((Integer) twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY));
    }//from w  ww .  j a  v a  2  s. c  om

    // check if the node has a node range constraint
    if (twigNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) {
        final int[] range = (int[]) twigNode.getTag(RangePropertyParser.RANGE_PROPERTY);
        query.setNodeConstraint(range[0], range[1]);
    }

    // process root query
    if (twigNode.hasRoot()) {
        final String rootExpr = twigNode.getRoot().toString();
        final String field = twigNode.getField().toString();
        query.addRoot((NodeQuery) keywordParser.parse(rootExpr, field));
    }

    // process child and descendant queries
    try {
        processChildren(children, query);
    } catch (final TooManyClauses ex) {
        throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                BooleanQuery.getMaxClauseCount(), twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
    }

    return query;
}