Search in sources :

Example 6 with QueryNode

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

the class MultiPhraseQueryNode method toString.

@Override
public String toString() {
    if (getChildren() == null || getChildren().size() == 0)
        return "<multiPhrase/>";
    StringBuilder sb = new StringBuilder();
    sb.append("<multiPhrase>");
    for (QueryNode child : getChildren()) {
        sb.append("\n");
        sb.append(child.toString());
    }
    sb.append("\n</multiPhrase>");
    return sb.toString();
}
Also used : QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)

Example 7 with QueryNode

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

the class MultiPhraseQueryNode method toQueryString.

@Override
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
    if (getChildren() == null || getChildren().size() == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    String filler = "";
    for (QueryNode child : getChildren()) {
        sb.append(filler).append(child.toQueryString(escapeSyntaxParser));
        filler = ",";
    }
    return "[MTP[" + sb.toString() + "]]";
}
Also used : QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)

Example 8 with QueryNode

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

the class StandardSyntaxParser method ConjQuery.

public final QueryNode ConjQuery(CharSequence field) throws ParseException {
    QueryNode first, c;
    Vector<QueryNode> clauses = null;
    first = ModClause(field);
    label_3: while (true) {
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case AND:
                ;
                break;
            default:
                jj_la1[4] = jj_gen;
                break label_3;
        }
        jj_consume_token(AND);
        c = ModClause(field);
        if (clauses == null) {
            clauses = new Vector<QueryNode>();
            clauses.addElement(first);
        }
        clauses.addElement(c);
    }
    if (clauses != null) {
        {
            if (true)
                return new AndQueryNode(clauses);
        }
    } else {
        {
            if (true)
                return first;
        }
    }
    throw new Error("Missing return statement in function");
}
Also used : RegexpQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode) GroupQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode) AndQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode) FieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode) TermRangeQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) BoostQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode) FuzzyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode) ModifierQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode) QuotedFieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode) SlopQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode) OrQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) Vector(java.util.Vector) AndQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode)

Example 9 with QueryNode

use of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode 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)

Example 10 with QueryNode

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

the class BooleanQueryNodeBuilder method build.

@Override
public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
    BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
    List<QueryNode> children = booleanNode.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, getModifierValue(child));
                } catch (TooManyClauses ex) {
                    throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), queryNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
                }
            }
        }
    }
    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) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) ModifierQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) QueryTreeBuilder(org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) TooManyClauses(org.apache.lucene.search.BooleanQuery.TooManyClauses) MessageImpl(org.apache.lucene.queryparser.flexible.messages.MessageImpl) EscapeQuerySyntaxImpl(org.apache.lucene.queryparser.flexible.standard.parser.EscapeQuerySyntaxImpl)

Aggregations

QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)26 BooleanQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode)12 FieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode)11 GroupQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode)11 ModifierQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode)11 OrQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode)10 BoostQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode)9 FuzzyQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode)9 QuotedFieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode)9 RegexpQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode)9 AndQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode)8 SlopQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode)7 TermRangeQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode)7 QueryTreeBuilder (org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder)5 ArrayList (java.util.ArrayList)4 Query (org.apache.lucene.search.Query)4 LinkedList (java.util.LinkedList)3 Vector (java.util.Vector)3 TokenizedPhraseQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.TokenizedPhraseQueryNode)3 MessageImpl (org.apache.lucene.queryparser.flexible.messages.MessageImpl)3