mirror of https://github.com/apache/lucene.git
Clean up AnyQueryNode code (#13053)
This commit is contained in:
parent
4f0bc4f35c
commit
08e0f41fea
|
@ -266,6 +266,8 @@ Other
|
||||||
* GITHUB#12967, GITHUB#13038, GITHUB#13040, GITHUB#13042, GITHUB#13047, GITHUB#13048, GITHUB#13049, GITHUB#13050, GITHUB#13051, GITHUB#13039:
|
* GITHUB#12967, GITHUB#13038, GITHUB#13040, GITHUB#13042, GITHUB#13047, GITHUB#13048, GITHUB#13049, GITHUB#13050, GITHUB#13051, GITHUB#13039:
|
||||||
Code cleanups and optimizations. (Dmitry Cherniachenko)
|
Code cleanups and optimizations. (Dmitry Cherniachenko)
|
||||||
|
|
||||||
|
* GITHUB#13053: Minor AnyQueryNode code cleanup (Dmitry Cherniachenko)
|
||||||
|
|
||||||
======================== Lucene 9.9.2 =======================
|
======================== Lucene 9.9.2 =======================
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
|
|
|
@ -21,8 +21,8 @@ import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax;
|
||||||
|
|
||||||
/** A {@link AnyQueryNode} represents an ANY operator performed on a list of nodes. */
|
/** A {@link AnyQueryNode} represents an ANY operator performed on a list of nodes. */
|
||||||
public class AnyQueryNode extends AndQueryNode {
|
public class AnyQueryNode extends AndQueryNode {
|
||||||
private CharSequence field = null;
|
private CharSequence field;
|
||||||
private int minimumMatchingmElements = 0;
|
private int minimumMatchingElements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param clauses - the query nodes to be or'ed
|
* @param clauses - the query nodes to be or'ed
|
||||||
|
@ -30,28 +30,20 @@ public class AnyQueryNode extends AndQueryNode {
|
||||||
public AnyQueryNode(List<QueryNode> clauses, CharSequence field, int minimumMatchingElements) {
|
public AnyQueryNode(List<QueryNode> clauses, CharSequence field, int minimumMatchingElements) {
|
||||||
super(clauses);
|
super(clauses);
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.minimumMatchingmElements = minimumMatchingElements;
|
this.minimumMatchingElements = minimumMatchingElements;
|
||||||
|
|
||||||
if (clauses != null) {
|
if (clauses != null) {
|
||||||
|
|
||||||
for (QueryNode clause : clauses) {
|
for (QueryNode clause : clauses) {
|
||||||
|
|
||||||
if (clause instanceof FieldQueryNode) {
|
if (clause instanceof FieldQueryNode) {
|
||||||
|
((FieldQueryNode) clause).toQueryStringIgnoreFields = true;
|
||||||
if (clause instanceof QueryNodeImpl) {
|
((FieldQueryNode) clause).setField(field);
|
||||||
((QueryNodeImpl) clause).toQueryStringIgnoreFields = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clause instanceof FieldableNode) {
|
|
||||||
((FieldableNode) clause).setField(field);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinimumMatchingElements() {
|
public int getMinimumMatchingElements() {
|
||||||
return this.minimumMatchingmElements;
|
return this.minimumMatchingElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,24 +77,24 @@ public class AnyQueryNode extends AndQueryNode {
|
||||||
AnyQueryNode clone = (AnyQueryNode) super.cloneTree();
|
AnyQueryNode clone = (AnyQueryNode) super.cloneTree();
|
||||||
|
|
||||||
clone.field = this.field;
|
clone.field = this.field;
|
||||||
clone.minimumMatchingmElements = this.minimumMatchingmElements;
|
clone.minimumMatchingElements = this.minimumMatchingElements;
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (getChildren() == null || getChildren().size() == 0)
|
if (getChildren() == null || getChildren().isEmpty())
|
||||||
return "<any field='"
|
return "<any field='"
|
||||||
+ this.field
|
+ this.field
|
||||||
+ "' matchelements="
|
+ "' matchelements="
|
||||||
+ this.minimumMatchingmElements
|
+ this.minimumMatchingElements
|
||||||
+ "/>";
|
+ "/>";
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("<any field='")
|
sb.append("<any field='")
|
||||||
.append(this.field)
|
.append(this.field)
|
||||||
.append("' matchelements=")
|
.append("' matchelements=")
|
||||||
.append(this.minimumMatchingmElements)
|
.append(this.minimumMatchingElements)
|
||||||
.append('>');
|
.append('>');
|
||||||
for (QueryNode clause : getChildren()) {
|
for (QueryNode clause : getChildren()) {
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
|
@ -114,11 +106,11 @@ public class AnyQueryNode extends AndQueryNode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
|
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
|
||||||
String anySTR = "ANY " + this.minimumMatchingmElements;
|
String anySTR = "ANY " + this.minimumMatchingElements;
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (getChildren() == null || getChildren().size() == 0) {
|
if (getChildren() == null || getChildren().isEmpty()) {
|
||||||
// no childs case
|
// no children case
|
||||||
} else {
|
} else {
|
||||||
String filler = "";
|
String filler = "";
|
||||||
for (QueryNode clause : getChildren()) {
|
for (QueryNode clause : getChildren()) {
|
||||||
|
@ -128,9 +120,9 @@ public class AnyQueryNode extends AndQueryNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDefaultField(this.field)) {
|
if (isDefaultField(this.field)) {
|
||||||
return "( " + sb.toString() + " ) " + anySTR;
|
return "( " + sb + " ) " + anySTR;
|
||||||
} else {
|
} else {
|
||||||
return this.field + ":(( " + sb.toString() + " ) " + anySTR + ")";
|
return this.field + ":(( " + sb + " ) " + anySTR + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue