Apache Lucene open-source search software
Clean up query node classes (#14737)
Stefan Voditaf2493e586b11
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 29913a822fe..ed346e4b508 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -100,6 +100,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.javaindex 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 parenthesisif ((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.javaindex 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.javaindex 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 {@Overridepublic 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 {@Overridepublic 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 parenthesisif ((getParent() != null && getParent() instanceof GroupQueryNode) || isRoot())return sb.toString();- else return "( " + sb.toString() + " )";+ else return "( " + sb + " )";}@Overridepublic 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.javaindex 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.javaindex 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 {@Overridepublic 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.javaindex 1bdaa739e9d..31adb7f08b9 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@@ -136,8 +136,6 @@ public class FieldQueryNode extends QueryNodeImpl}/**- * Returns the term.- ** @return The "original" form of the term.*/@Overridediff --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.javaindex 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.javaindex 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.javaindex 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 - Valuediff --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.javaindex 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 {@Overridepublic 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.javaindex 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.javaindex 862625f2d68..a4bae177cff 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@@ -21,9 +21,9 @@ import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax;/** 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();/*** This method is used to get the value converted to {@link String} and escaped using the given@@ -42,5 +42,5 @@ public interface ValueQueryNode<T extends Object> extends QueryNode {* @param escaper the {@link EscapeQuerySyntax} used to escape the value {@link String}* @return the value converted to {@link String} and escaped*/- public CharSequence getTermEscaped(EscapeQuerySyntax escaper);+ CharSequence getTermEscaped(EscapeQuerySyntax escaper);}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.javaindex 6780711d9d6..f68b854eaa6 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.*/@Overridediff --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.javaindex 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";}}