use of com.yahoo.prelude.query.NotItem in project vespa by vespa-engine.
the class YqlParser method buildAnd.
@NonNull
private CompositeItem buildAnd(OperatorNode<ExpressionOperator> ast) {
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 {
notItem.setPositiveItem(andItem);
}
return notItem;
}
use of com.yahoo.prelude.query.NotItem in project vespa by vespa-engine.
the class SerializeItemTestCase method serialize_not_item.
@Test
public void serialize_not_item() throws ParseException {
NotItem notItem = new NotItem();
{
notItem.addItem(new WordItem("first"));
notItem.addItem(new WordItem("second"));
}
serializeThenParse(notItem);
}
use of com.yahoo.prelude.query.NotItem in project vespa by vespa-engine.
the class VespaSerializerTestCase method testLongAndNot.
@Test
public final void testLongAndNot() {
NotItem item = new NotItem();
item.addItem(new WordItem("a"));
item.addItem(new WordItem("b"));
item.addItem(new WordItem("c"));
item.addItem(new WordItem("d"));
String q = VespaSerializer.serialize(item);
assertEquals("(default contains ([{\"implicitTransforms\": false}]\"a\")) AND !(default contains ([{\"implicitTransforms\": false}]\"b\") OR default contains ([{\"implicitTransforms\": false}]\"c\") OR default contains ([{\"implicitTransforms\": false}]\"d\"))", q);
}
use of com.yahoo.prelude.query.NotItem in project vespa by vespa-engine.
the class QueryRewrite method extractAndNot.
private static CompositeItem extractAndNot(AndItem parent) {
NotItem theOnlyNot = null;
for (int i = 0; i < parent.getItemCount(); i++) {
Item child = parent.getItem(i);
if (child instanceof NotItem) {
NotItem thisNot = (NotItem) child;
parent.setItem(i, thisNot.getPositiveItem());
if (theOnlyNot == null) {
theOnlyNot = thisNot;
theOnlyNot.setPositiveItem(parent);
} else {
for (int j = 1; j < thisNot.getItemCount(); j++) {
theOnlyNot.addNegativeItem(thisNot.getItem(j));
}
}
}
}
return (theOnlyNot != null) ? theOnlyNot : parent;
}
use of com.yahoo.prelude.query.NotItem in project vespa by vespa-engine.
the class ParseTestCase method testNegativeWordsParsing2.
@Test
public void testNegativeWordsParsing2() {
Item root = tester.assertParsed("+a -b", "+a -b", Query.Type.WEB);
assertTrue(((NotItem) root).getItem(0).isProtected());
assertTrue(((NotItem) root).getItem(1).isProtected());
}
Aggregations