Skip to content

Commit

Permalink
Cleanup TokenizedPhraseQueryNode code (apache#13041)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabi0 authored Feb 15, 2024
1 parent c9e4434 commit f24b1de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public TokenizedPhraseQueryNode() {

@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());
}
Expand All @@ -46,16 +47,15 @@ public String toString() {
// 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
Expand All @@ -70,27 +70,25 @@ public QueryNode cloneTree() throws CloneNotSupportedException {
@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
}

0 comments on commit f24b1de

Please sign in to comment.