Search in sources :

Example 1 with FieldableNode

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

the class UniqueFieldQueryNodeProcessor method preProcessNode.

@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    if (node instanceof FieldableNode) {
        FieldableNode fieldNode = (FieldableNode) node;
        QueryConfigHandler queryConfig = getQueryConfigHandler();
        if (queryConfig == null) {
            throw new IllegalArgumentException("A config handler is expected by the processor UniqueFieldQueryNodeProcessor!");
        }
        if (!queryConfig.has(SpansQueryConfigHandler.UNIQUE_FIELD)) {
            throw new IllegalArgumentException("UniqueFieldAttribute should be defined in the config handler!");
        }
        String uniqueField = queryConfig.get(SpansQueryConfigHandler.UNIQUE_FIELD);
        fieldNode.setField(uniqueField);
    }
    return node;
}
Also used : FieldableNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldableNode) QueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler)

Example 2 with FieldableNode

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

the class BoostQueryNodeProcessor method postProcessNode.

@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
    if (node instanceof FieldableNode && (node.getParent() == null || !(node.getParent() instanceof FieldableNode))) {
        FieldableNode fieldNode = (FieldableNode) node;
        QueryConfigHandler config = getQueryConfigHandler();
        if (config != null) {
            CharSequence field = fieldNode.getField();
            FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field));
            if (fieldConfig != null) {
                Float boost = fieldConfig.get(ConfigurationKeys.BOOST);
                if (boost != null) {
                    return new BoostQueryNode(node, boost);
                }
            }
        }
    }
    return node;
}
Also used : FieldableNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldableNode) BoostQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode) FieldConfig(org.apache.lucene.queryparser.flexible.core.config.FieldConfig) QueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler)

Example 3 with FieldableNode

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

FieldableNode (org.apache.lucene.queryparser.flexible.core.nodes.FieldableNode)3 QueryConfigHandler (org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler)2 ArrayList (java.util.ArrayList)1 FieldConfig (org.apache.lucene.queryparser.flexible.core.config.FieldConfig)1 BooleanQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode)1 BoostQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode)1 GroupQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode)1 OrQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode)1 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)1