|
1 | 1 | package datawave.query.rules;
|
2 | 2 |
|
3 | 3 | import java.util.List;
|
4 |
| -import java.util.stream.Collectors; |
5 | 4 |
|
6 | 5 | import org.apache.log4j.Logger;
|
7 |
| -import org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode; |
8 | 6 | import org.apache.lucene.queryparser.flexible.core.nodes.NotBooleanQueryNode;
|
9 | 7 | import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;
|
10 | 8 |
|
@@ -61,26 +59,21 @@ private String formatMessage(NotBooleanQueryNode node) {
|
61 | 59 | StringBuilder sb = new StringBuilder();
|
62 | 60 | sb.append("Ambiguous usage of NOT detected with multiple unwrapped preceding terms: ");
|
63 | 61 |
|
64 |
| - String precedingTerms = getPrecedingTerms(node); |
| 62 | + String lastPrecedingTerm = getLastPrecedingTerm(node); |
| 63 | + |
65 | 64 | // @formatter:off
|
66 |
| - return sb.append("\"") |
67 |
| - .append(precedingTerms) |
68 |
| - .append(" NOT\" should be \"(") |
69 |
| - .append(precedingTerms) |
70 |
| - .append(") NOT\".") |
| 65 | + return sb.append("the NOT clause will only be applied to \"") |
| 66 | + .append(lastPrecedingTerm) |
| 67 | + .append("\".") |
71 | 68 | .toString();
|
72 | 69 | // @formatter:on
|
73 | 70 | }
|
74 | 71 |
|
75 |
| - // Return the terms preceding the NOT in the given node as a nicely formatted query string. |
76 |
| - private String getPrecedingTerms(NotBooleanQueryNode node) { |
| 72 | + // Return the last term preceding the NOT in the given, in query format. |
| 73 | + private String getLastPrecedingTerm(NotBooleanQueryNode node) { |
77 | 74 | QueryNode junctionNode = node.getChildren().get(0);
|
78 |
| - String junction = junctionNode instanceof AndQueryNode ? " AND " : " OR "; |
79 |
| - // @formatter:off |
80 |
| - return junctionNode.getChildren().stream() |
81 |
| - .map(LuceneQueryStringBuildingVisitor::build) |
82 |
| - .collect(Collectors.joining(junction)); |
83 |
| - // @formatter:on |
| 75 | + List<QueryNode> children = junctionNode.getChildren(); |
| 76 | + QueryNode lastChild = children.get(children.size() - 1); |
| 77 | + return LuceneQueryStringBuildingVisitor.build(lastChild); |
84 | 78 | }
|
85 |
| - |
86 | 79 | }
|
0 commit comments