summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/yql
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-01-06 15:51:12 +0100
committerJon Bratseth <bratseth@gmail.com>2022-01-06 15:51:12 +0100
commite2e44dbccb30c3b9673518f3204699e137b81fcc (patch)
treec80664011b253a3f2ca2c6daf046fe659fdd00f2 /container-search/src/main/java/com/yahoo/search/yql
parent1366eb01c678345c2879ea092ab8737d0f087a89 (diff)
Allow negative terms only in YQL
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/yql')
-rw-r--r--container-search/src/main/java/com/yahoo/search/yql/YqlParser.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java b/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java
index 8334775b8e2..199cf7bb2a9 100644
--- a/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java
+++ b/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java
@@ -356,6 +356,8 @@ public class YqlParser implements Parser {
return buildFunctionCall(ast);
case LITERAL:
return buildLiteral(ast);
+ case NOT:
+ return buildNot(ast);
default:
throw newUnexpectedArgumentException(ast.getOperator(),
ExpressionOperator.AND, ExpressionOperator.CALL,
@@ -1096,17 +1098,21 @@ public class YqlParser implements Parser {
AndItem andItem = new AndItem();
NotItem notItem = new NotItem();
convertVarArgsAnd(ast, 0, andItem, notItem);
- Preconditions
- .checkArgument(andItem.getItemCount() > 0,
- "Vespa does not support AND with no logically positive branches.");
if (notItem.getItemCount() == 0) {
return andItem;
}
if (andItem.getItemCount() == 1) {
notItem.setPositiveItem(andItem.getItem(0));
- } else {
+ } else if (andItem.getItemCount() > 1) {
notItem.setPositiveItem(andItem);
- }
+ } // else no positives, which is ok
+ return notItem;
+ }
+
+ /** Build a "pure" not, without any positive terms. */
+ private CompositeItem buildNot(OperatorNode<ExpressionOperator> ast) {
+ NotItem notItem = new NotItem();
+ notItem.addNegativeItem(convertExpression(ast.getArgument(0)));
return notItem;
}