Skip to content

Commit 7c7a1a2

Browse files
committed
Clean up query node classes (#14737)
1 parent f2eb4d9 commit 7c7a1a2

File tree

15 files changed

+37
-67
lines changed

15 files changed

+37
-67
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Improvements
3333

3434
* GITHUB#14443: Support adaptive refresh in Searcher Managers (Vigya Sharma)
3535

36+
* GITHUB#14737: Clean up redundant code and comments in query node classes. (Stefan Vodita)
37+
3638
Optimizations
3739
---------------------
3840
* GITHUB#14418: Quick exit on filter query matching no docs when rewriting knn query. (Pan Guixin)

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AndQueryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
5959
// in case is root or the parent is a group node avoid parenthesis
6060
if ((getParent() != null && getParent() instanceof GroupQueryNode) || isRoot())
6161
return sb.toString();
62-
else return "( " + sb.toString() + " )";
62+
else return "( " + sb + " )";
6363
}
6464
}

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/AnyQueryNode.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,14 @@ public int getMinimumMatchingElements() {
4747
}
4848

4949
/**
50-
* returns null if the field was not specified
51-
*
52-
* @return the field
50+
* @return the field or null if the field is unspecified
5351
*/
5452
public CharSequence getField() {
5553
return this.field;
5654
}
5755

5856
/**
59-
* returns - null if the field was not specified
60-
*
61-
* @return the field as a String
57+
* @return the field as a String or null if the field is unspecified
6258
*/
6359
public String getFieldAsString() {
6460
if (this.field == null) return null;

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BooleanQueryNode.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public BooleanQueryNode(List<QueryNode> clauses) {
3737

3838
@Override
3939
public String toString() {
40-
if (getChildren() == null || getChildren().size() == 0) return "<boolean operation='default'/>";
40+
if (getChildren() == null || getChildren().isEmpty()) return "<boolean operation='default'/>";
4141
StringBuilder sb = new StringBuilder();
4242
sb.append("<boolean operation='default'>");
4343
for (QueryNode child : getChildren()) {
@@ -50,7 +50,7 @@ public String toString() {
5050

5151
@Override
5252
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
53-
if (getChildren() == null || getChildren().size() == 0) return "";
53+
if (getChildren() == null || getChildren().isEmpty()) return "";
5454

5555
StringBuilder sb = new StringBuilder();
5656
String filler = "";
@@ -62,15 +62,11 @@ public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
6262
// in case is root or the parent is a group node avoid parenthesis
6363
if ((getParent() != null && getParent() instanceof GroupQueryNode) || isRoot())
6464
return sb.toString();
65-
else return "( " + sb.toString() + " )";
65+
else return "( " + sb + " )";
6666
}
6767

6868
@Override
6969
public QueryNode cloneTree() throws CloneNotSupportedException {
70-
BooleanQueryNode clone = (BooleanQueryNode) super.cloneTree();
71-
72-
// nothing to do here
73-
74-
return clone;
70+
return super.cloneTree();
7571
}
7672
}

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/BoostQueryNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ public BoostQueryNode(QueryNode query, float value) {
5151
}
5252

5353
/**
54-
* Returns the single child which this node boosts.
55-
*
5654
* @return the single child which this node boosts
5755
*/
5856
public QueryNode getChild() {
5957
List<QueryNode> children = getChildren();
6058

61-
if (children == null || children.size() == 0) {
59+
if (children == null || children.isEmpty()) {
6260
return null;
6361
}
6462

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/DeletedQueryNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public String toString() {
4141

4242
@Override
4343
public QueryNode cloneTree() throws CloneNotSupportedException {
44-
DeletedQueryNode clone = (DeletedQueryNode) super.cloneTree();
45-
46-
return clone;
44+
return super.cloneTree();
4745
}
4846
}

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldQueryNode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ public void setPositionIncrement(int pi) {
135135
}
136136

137137
/**
138-
* Returns the term.
139-
*
140138
* @return The "original" form of the term.
141139
*/
142140
@Override

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldValuePairQueryNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@
2323
* @see FieldableNode
2424
* @see ValueQueryNode
2525
*/
26-
public interface FieldValuePairQueryNode<T extends Object>
27-
extends FieldableNode, ValueQueryNode<T> {}
26+
public interface FieldValuePairQueryNode<T> extends FieldableNode, ValueQueryNode<T> {}

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FieldableNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
public interface FieldableNode extends QueryNode {
2727

2828
/**
29-
* Returns the field associated to the node and every node under it.
30-
*
31-
* @return the field name
29+
* @return name of the filed associated to the node and every node under it
3230
*/
3331
CharSequence getField();
3432

lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/FuzzyQueryNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public class FuzzyQueryNode extends FieldQueryNode {
2525

2626
private int prefixLength;
2727

28-
/**
29-
* @param field Name of the field query will use.
30-
* @param termStr Term token to use for building term for the query
31-
*/
3228
/**
3329
* @param field - Field name
3430
* @param term - Value

0 commit comments

Comments
 (0)