Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup TokenizedPhraseQueryNode code #13041

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ Improvements
Tests are running with random byte order to ensure that the order does not affect correctness
of code. Native order was enabled for LZ4 compression. (Uwe Schindler)

* GITHUB#13041: TokenizedPhraseQueryNode code cleanup (Dmitry Cherniachenko)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have to move up to version 9.11 because 9.10 is already in the release process.


Optimizations
---------------------

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
}
Loading