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;
}
Aggregations