Cleanup TokenizedPhraseQueryNode code ()

This commit is contained in:
Dmitry Cherniachenko 2024-02-15 11:04:58 +01:00 committed by GitHub
parent c9e4434cc3
commit f24b1de351
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 19 deletions
lucene
CHANGES.txt
queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes

View File

@ -193,6 +193,8 @@ Improvements
* GITHUB#13092: `static final Map` constants have been made immutable (Dmitry Cherniachenko)
* GITHUB#13041: TokenizedPhraseQueryNode code cleanup (Dmitry Cherniachenko)
Optimizations
---------------------
(No changes)

View File

@ -32,10 +32,11 @@ public class TokenizedPhraseQueryNode extends QueryNodeImpl implements Fieldable
@Override
public String toString() {
if (getChildren() == null || getChildren().size() == 0) return "<tokenizedphrase/>";
List<QueryNode> children = getChildren();
if (children == null || children.isEmpty()) return "<tokenizedphrase/>";
StringBuilder sb = new StringBuilder();
sb.append("<tokenizedtphrase>");
for (QueryNode child : getChildren()) {
sb.append("<tokenizedphrase>");
for (QueryNode child : children) {
sb.append("\n");
sb.append(child.toString());
}
@ -46,16 +47,15 @@ public class TokenizedPhraseQueryNode extends QueryNodeImpl implements Fieldable
// This text representation is not re-parseable
@Override
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
if (getChildren() == null || getChildren().size() == 0) return "";
List<QueryNode> children = getChildren();
if (children == null || children.isEmpty()) return "";
StringBuilder sb = new StringBuilder();
String filler = "";
for (QueryNode child : getChildren()) {
for (QueryNode child : children) {
sb.append(filler).append(child.toQueryString(escapeSyntaxParser));
filler = ",";
}
return "[TP[" + sb.toString() + "]]";
return "[TP[" + sb + "]]";
}
@Override
@ -70,27 +70,25 @@ public class TokenizedPhraseQueryNode extends QueryNodeImpl implements Fieldable
@Override
public CharSequence getField() {
List<QueryNode> children = getChildren();
if (children == null || children.size() == 0) {
return null;
} else {
return ((FieldableNode) children.get(0)).getField();
if (children != null) {
for (QueryNode child : children) {
if (child instanceof FieldableNode) {
return ((FieldableNode) child).getField();
}
}
}
return null;
}
@Override
public void setField(CharSequence fieldName) {
List<QueryNode> children = getChildren();
if (children != null) {
for (QueryNode child : getChildren()) {
for (QueryNode child : children) {
if (child instanceof FieldableNode) {
((FieldableNode) child).setField(fieldName);
}
}
}
}
} // end class MultitermQueryNode
}