You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2024/01/31 09:49:53 UTC
(lucene) branch branch_9x updated: Clean up AnyQueryNode code (#13053)
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 6f6fdbdf2e8 Clean up AnyQueryNode code (#13053)
6f6fdbdf2e8 is described below
commit 6f6fdbdf2e82208079c9cf98404642ae75398a3c
Author: Dmitry Cherniachenko <2s...@gmail.com>
AuthorDate: Wed Jan 31 10:49:23 2024 +0100
Clean up AnyQueryNode code (#13053)
---
lucene/CHANGES.txt | 2 ++
.../flexible/core/nodes/AnyQueryNode.java | 38 +++++++++-------------
2 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 350da742a8d..2f6065a9c04 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -104,6 +104,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 Fixes
diff --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.java
index 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;
}
@Override
public 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 {
@Override
public 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 + ")";
}
}
}