Apache Lucene open-source search software
Clean up AnyQueryNode code (#13053)
Dmitry Cherniachenko08e0f41fea5d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 2f391e4f5e0..db296497ce5 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -266,6 +266,8 @@ Other* GITHUB#12967, GITHUB#13038, GITHUB#13040, GITHUB#13042, GITHUB#13047, GITHUB#13048, GITHUB#13049, GITHUB#13050, GITHUB#13051, GITHUB#13039:Code cleanups and optimizations. (Dmitry Cherniachenko)+* GITHUB#13053: Minor AnyQueryNode code cleanup (Dmitry Cherniachenko)+======================== Lucene 9.9.2 =======================Bug Fixesdiff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AnyQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AnyQueryNode.javaindex 65b6d6f3d4d..8becad6a9c3 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AnyQueryNode.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AnyQueryNode.java@@ -21,8 +21,8 @@ import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax;/** A {@link AnyQueryNode} represents an ANY operator performed on a list of nodes. */public class AnyQueryNode extends AndQueryNode {- private CharSequence field = null;- private int minimumMatchingmElements = 0;+ private CharSequence field;+ private int minimumMatchingElements;/*** @param clauses - the query nodes to be or'ed@@ -30,28 +30,20 @@ public class AnyQueryNode extends AndQueryNode {public AnyQueryNode(List<QueryNode> clauses, CharSequence field, int minimumMatchingElements) {super(clauses);this.field = field;- this.minimumMatchingmElements = minimumMatchingElements;+ this.minimumMatchingElements = minimumMatchingElements;if (clauses != null) {-for (QueryNode clause : clauses) {-if (clause instanceof FieldQueryNode) {-- if (clause instanceof QueryNodeImpl) {- ((QueryNodeImpl) clause).toQueryStringIgnoreFields = true;- }-- if (clause instanceof FieldableNode) {- ((FieldableNode) clause).setField(field);- }+ ((FieldQueryNode) clause).toQueryStringIgnoreFields = true;+ ((FieldQueryNode) clause).setField(field);}}}}public int getMinimumMatchingElements() {- return this.minimumMatchingmElements;+ return this.minimumMatchingElements;}/**@@ -85,24 +77,24 @@ public class AnyQueryNode extends AndQueryNode {AnyQueryNode clone = (AnyQueryNode) super.cloneTree();clone.field = this.field;- clone.minimumMatchingmElements = this.minimumMatchingmElements;+ clone.minimumMatchingElements = this.minimumMatchingElements;return clone;}@Overridepublic String toString() {- if (getChildren() == null || getChildren().size() == 0)+ if (getChildren() == null || getChildren().isEmpty())return "<any field='"+ this.field+ "' matchelements="- + this.minimumMatchingmElements+ + this.minimumMatchingElements+ "/>";StringBuilder sb = new StringBuilder();sb.append("<any field='").append(this.field).append("' matchelements=")- .append(this.minimumMatchingmElements)+ .append(this.minimumMatchingElements).append('>');for (QueryNode clause : getChildren()) {sb.append("\n");@@ -114,11 +106,11 @@ public class AnyQueryNode extends AndQueryNode {@Overridepublic CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {- String anySTR = "ANY " + this.minimumMatchingmElements;+ String anySTR = "ANY " + this.minimumMatchingElements;StringBuilder sb = new StringBuilder();- if (getChildren() == null || getChildren().size() == 0) {- // no childs case+ if (getChildren() == null || getChildren().isEmpty()) {+ // no children case} else {String filler = "";for (QueryNode clause : getChildren()) {@@ -128,9 +120,9 @@ public class AnyQueryNode extends AndQueryNode {}if (isDefaultField(this.field)) {- return "( " + sb.toString() + " ) " + anySTR;+ return "( " + sb + " ) " + anySTR;} else {- return this.field + ":(( " + sb.toString() + " ) " + anySTR + ")";+ return this.field + ":(( " + sb + " ) " + anySTR + ")";}}}