You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by vo...@apache.org on 2025/06/04 08:38:55 UTC
(lucene) branch branch_10x updated: Clean up query node classes (#14737)
This is an automated email from the ASF dual-hosted git repository.
voditas pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 7c7a1a29275 Clean up query node classes (#14737)
7c7a1a29275 is described below
commit 7c7a1a2927569844b816960af9eea82aed29ab05
Author: Stefan Vodita <41...@users.noreply.github.com>
AuthorDate: Wed Jun 4 09:05:36 2025 +0100
Clean up query node classes (#14737)
---
lucene/CHANGES.txt | 2 +
.../flexible/core/nodes/AndQueryNode.java | 2 +-
.../flexible/core/nodes/AnyQueryNode.java | 8 +---
.../flexible/core/nodes/BooleanQueryNode.java | 12 ++----
.../flexible/core/nodes/BoostQueryNode.java | 4 +-
.../flexible/core/nodes/DeletedQueryNode.java | 4 +-
.../flexible/core/nodes/FieldQueryNode.java | 2 -
.../core/nodes/FieldValuePairQueryNode.java | 3 +-
.../flexible/core/nodes/FieldableNode.java | 4 +-
.../flexible/core/nodes/FuzzyQueryNode.java | 4 --
.../flexible/core/nodes/GroupQueryNode.java | 4 +-
.../queryparser/flexible/core/nodes/QueryNode.java | 43 ++++++++++------------
.../flexible/core/nodes/ValueQueryNode.java | 4 +-
.../standard/nodes/AbstractRangeQueryNode.java | 6 ---
.../core/builders/TestQueryTreeBuilder.java | 2 +-
15 files changed, 37 insertions(+), 67 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4827dd69f74..5940abbdaa7 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -33,6 +33,8 @@ Improvements
* GITHUB#14443: Support adaptive refresh in Searcher Managers (Vigya Sharma)
+* GITHUB#14737: Clean up redundant code and comments in query node classes. (Stefan Vodita)
+
Optimizations
---------------------
* GITHUB#14418: Quick exit on filter query matching no docs when rewriting knn query. (Pan Guixin)
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AndQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AndQueryNode.java
index 30a2a7c6aeb..48a1d8d8d9e 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AndQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AndQueryNode.java
@@ -59,6 +59,6 @@ public class AndQueryNode extends BooleanQueryNode {
// in case is root or the parent is a group node avoid parenthesis
if ((getParent() != null && getParent() instanceof GroupQueryNode) || isRoot())
return sb.toString();
- else return "( " + sb.toString() + " )";
+ else return "( " + sb + " )";
}
}
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 8becad6a9c3..c1d1211144e 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
@@ -47,18 +47,14 @@ public class AnyQueryNode extends AndQueryNode {
}
/**
- * returns null if the field was not specified
- *
- * @return the field
+ * @return the field or null if the field is unspecified
*/
public CharSequence getField() {
return this.field;
}
/**
- * returns - null if the field was not specified
- *
- * @return the field as a String
+ * @return the field as a String or null if the field is unspecified
*/
public String getFieldAsString() {
if (this.field == null) return null;
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BooleanQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BooleanQueryNode.java
index 9f650178f34..d441758d5b4 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BooleanQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BooleanQueryNode.java
@@ -37,7 +37,7 @@ public class BooleanQueryNode extends QueryNodeImpl {
@Override
public String toString() {
- if (getChildren() == null || getChildren().size() == 0) return "<boolean operation='default'/>";
+ if (getChildren() == null || getChildren().isEmpty()) return "<boolean operation='default'/>";
StringBuilder sb = new StringBuilder();
sb.append("<boolean operation='default'>");
for (QueryNode child : getChildren()) {
@@ -50,7 +50,7 @@ public class BooleanQueryNode extends QueryNodeImpl {
@Override
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
- if (getChildren() == null || getChildren().size() == 0) return "";
+ if (getChildren() == null || getChildren().isEmpty()) return "";
StringBuilder sb = new StringBuilder();
String filler = "";
@@ -62,15 +62,11 @@ public class BooleanQueryNode extends QueryNodeImpl {
// in case is root or the parent is a group node avoid parenthesis
if ((getParent() != null && getParent() instanceof GroupQueryNode) || isRoot())
return sb.toString();
- else return "( " + sb.toString() + " )";
+ else return "( " + sb + " )";
}
@Override
public QueryNode cloneTree() throws CloneNotSupportedException {
- BooleanQueryNode clone = (BooleanQueryNode) super.cloneTree();
-
- // nothing to do here
-
- return clone;
+ return super.cloneTree();
}
}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BoostQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BoostQueryNode.java
index a8c39a41110..c86ddb06e9e 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BoostQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BoostQueryNode.java
@@ -51,14 +51,12 @@ public class BoostQueryNode extends QueryNodeImpl {
}
/**
- * Returns the single child which this node boosts.
- *
* @return the single child which this node boosts
*/
public QueryNode getChild() {
List<QueryNode> children = getChildren();
- if (children == null || children.size() == 0) {
+ if (children == null || children.isEmpty()) {
return null;
}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/DeletedQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/DeletedQueryNode.java
index 483737a2ff4..32dadcde95b 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/DeletedQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/DeletedQueryNode.java
@@ -41,8 +41,6 @@ public class DeletedQueryNode extends QueryNodeImpl {
@Override
public QueryNode cloneTree() throws CloneNotSupportedException {
- DeletedQueryNode clone = (DeletedQueryNode) super.cloneTree();
-
- return clone;
+ return super.cloneTree();
}
}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldQueryNode.java
index db9c17eb2a9..20b6af3eec4 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldQueryNode.java
@@ -135,8 +135,6 @@ public class FieldQueryNode extends QueryNodeImpl
}
/**
- * Returns the term.
- *
* @return The "original" form of the term.
*/
@Override
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java
index b334a30254d..4fc1e189291 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java
@@ -23,5 +23,4 @@ package org.apache.lucene.queryparser.flexible.core.nodes;
* @see FieldableNode
* @see ValueQueryNode
*/
-public interface FieldValuePairQueryNode<T extends Object>
- extends FieldableNode, ValueQueryNode<T> {}
+public interface FieldValuePairQueryNode<T> extends FieldableNode, ValueQueryNode<T> {}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldableNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldableNode.java
index 203c47f3396..1c59a61ac16 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldableNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldableNode.java
@@ -26,9 +26,7 @@ package org.apache.lucene.queryparser.flexible.core.nodes;
public interface FieldableNode extends QueryNode {
/**
- * Returns the field associated to the node and every node under it.
- *
- * @return the field name
+ * @return name of the filed associated to the node and every node under it
*/
CharSequence getField();
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FuzzyQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FuzzyQueryNode.java
index 72f803c4615..7b07cd711f3 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FuzzyQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FuzzyQueryNode.java
@@ -25,10 +25,6 @@ public class FuzzyQueryNode extends FieldQueryNode {
private int prefixLength;
- /**
- * @param field Name of the field query will use.
- * @param termStr Term token to use for building term for the query
- */
/**
* @param field - Field name
* @param term - Value
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/GroupQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/GroupQueryNode.java
index 22449e74cdb..8721ef56bb1 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/GroupQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/GroupQueryNode.java
@@ -61,9 +61,7 @@ public class GroupQueryNode extends QueryNodeImpl {
@Override
public QueryNode cloneTree() throws CloneNotSupportedException {
- GroupQueryNode clone = (GroupQueryNode) super.cloneTree();
-
- return clone;
+ return super.cloneTree();
}
public void setChild(QueryNode child) {
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/QueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/QueryNode.java
index 859503bedb4..7c2d23a400d 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/QueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/QueryNode.java
@@ -24,70 +24,67 @@ import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax;
public interface QueryNode {
/** convert to a query string understood by the query parser */
- // TODO: this interface might be changed in the future
- public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser);
+ CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser);
/** for printing */
@Override
- public String toString();
+ String toString();
/** get Children nodes */
- public List<QueryNode> getChildren();
+ List<QueryNode> getChildren();
/** verify if a node is a Leaf node */
- public boolean isLeaf();
+ boolean isLeaf();
/** verify if a node contains a tag */
- public boolean containsTag(String tagName);
+ boolean containsTag(String tagName);
/** Returns object stored under that tag name */
- public Object getTag(String tagName);
+ Object getTag(String tagName);
- public QueryNode getParent();
+ QueryNode getParent();
/**
- * Recursive clone the QueryNode tree The tags are not copied to the new tree when you call the
- * cloneTree() method
+ * Recursive clone the QueryNode tree. The tags are not copied to the new tree when you call the
+ * cloneTree() method.
*
* @return the cloned tree
*/
- public QueryNode cloneTree() throws CloneNotSupportedException;
+ QueryNode cloneTree() throws CloneNotSupportedException;
// Below are the methods that can change state of a QueryNode
// Write Operations (not Thread Safe)
- // add a new child to a non Leaf node
- public void add(QueryNode child);
+ /** add a new child to a non Leaf node */
+ void add(QueryNode child);
- public void add(List<QueryNode> children);
+ void add(List<QueryNode> children);
- // reset the children of a node
- public void set(List<QueryNode> children);
+ /** reset the children of a node */
+ void set(List<QueryNode> children);
/**
* Associate the specified value with the specified tagName. If the tagName already exists, the
* old value is replaced. The tagName and value cannot be null. tagName will be converted to
* lowercase.
*/
- public void setTag(String tagName, Object value);
+ void setTag(String tagName, Object value);
/** Unset a tag. tagName will be converted to lowercase. */
- public void unsetTag(String tagName);
+ void unsetTag(String tagName);
/**
- * Returns a map containing all tags attached to this query node.
- *
* @return a map containing all tags attached to this query node
*/
- public Map<String, Object> getTagMap();
+ Map<String, Object> getTagMap();
/** Removes this query node from its parent. */
- public void removeFromParent();
+ void removeFromParent();
/**
* Remove a child node
*
* @param childNode Which child to remove
*/
- public void removeChildren(QueryNode childNode);
+ void removeChildren(QueryNode childNode);
}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ValueQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ValueQueryNode.java
index b9eda590c0f..ebf53dc7ba4 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ValueQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ValueQueryNode.java
@@ -19,7 +19,7 @@ package org.apache.lucene.queryparser.flexible.core.nodes;
/** This interface should be implemented by {@link QueryNode} that holds an arbitrary value. */
public interface ValueQueryNode<T extends Object> extends QueryNode {
- public void setValue(T value);
+ void setValue(T value);
- public T getValue();
+ T getValue();
}
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java
index 4de8fe0d575..aad298a5bb6 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/AbstractRangeQueryNode.java
@@ -42,8 +42,6 @@ public class AbstractRangeQueryNode<T extends FieldValuePairQueryNode<?>> extend
}
/**
- * Returns the field associated with this node.
- *
* @return the field associated with this node
* @see FieldableNode
*/
@@ -83,8 +81,6 @@ public class AbstractRangeQueryNode<T extends FieldValuePairQueryNode<?>> extend
}
/**
- * Returns the lower bound node.
- *
* @return the lower bound node.
*/
@Override
@@ -94,8 +90,6 @@ public class AbstractRangeQueryNode<T extends FieldValuePairQueryNode<?>> extend
}
/**
- * Returns the upper bound node.
- *
* @return the upper bound node.
*/
@Override
diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java
index fbbb569037a..e8e5fc5998d 100644
--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java
+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java
@@ -57,7 +57,7 @@ public class TestQueryTreeBuilder extends LuceneTestCase {
private static class DummyBuilder implements QueryBuilder {
@Override
- public Object build(QueryNode queryNode) throws QueryNodeException {
+ public Object build(QueryNode queryNode) {
return "OK";
}
}