Search in sources :

Example 26 with QueryNode

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

the class MultiFieldQueryNodeProcessor method preProcessNode.

@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    if (node instanceof FieldableNode) {
        this.processChildren = false;
        FieldableNode fieldNode = (FieldableNode) node;
        if (fieldNode.getField() == null) {
            CharSequence[] fields = getQueryConfigHandler().get(ConfigurationKeys.MULTI_FIELDS);
            if (fields == null) {
                throw new IllegalArgumentException("StandardQueryConfigHandler.ConfigurationKeys.MULTI_FIELDS should be set on the QueryConfigHandler");
            }
            if (fields != null && fields.length > 0) {
                fieldNode.setField(fields[0]);
                if (fields.length == 1) {
                    return fieldNode;
                } else {
                    List<QueryNode> children = new ArrayList<>(fields.length);
                    children.add(fieldNode);
                    for (int i = 1; i < fields.length; i++) {
                        try {
                            fieldNode = (FieldableNode) fieldNode.cloneTree();
                            fieldNode.setField(fields[i]);
                            children.add(fieldNode);
                        } catch (CloneNotSupportedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    return new GroupQueryNode(new OrQueryNode(children));
                }
            }
        }
    }
    return node;
}
Also used : FieldableNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldableNode) OrQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) OrQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) GroupQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode) ArrayList(java.util.ArrayList) GroupQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode)

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