Search in sources :

Example 6 with NotItem

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;
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) AndItem(com.yahoo.prelude.query.AndItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 7 with 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);
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 8 with 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);
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 9 with NotItem

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;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) SimpleIndexedItem(com.yahoo.prelude.query.SimpleIndexedItem) OrItem(com.yahoo.prelude.query.OrItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem) NotItem(com.yahoo.prelude.query.NotItem)

Example 10 with NotItem

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());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NotItem(com.yahoo.prelude.query.NotItem) Test(org.junit.Test)

Aggregations

NotItem (com.yahoo.prelude.query.NotItem)11 WordItem (com.yahoo.prelude.query.WordItem)9 Test (org.junit.Test)8 AndItem (com.yahoo.prelude.query.AndItem)6 CompositeItem (com.yahoo.prelude.query.CompositeItem)4 Item (com.yahoo.prelude.query.Item)3 OrItem (com.yahoo.prelude.query.OrItem)3 RankItem (com.yahoo.prelude.query.RankItem)3 SubstringItem (com.yahoo.prelude.query.SubstringItem)3 Query (com.yahoo.search.Query)3 IntItem (com.yahoo.prelude.query.IntItem)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)2 PrefixItem (com.yahoo.prelude.query.PrefixItem)2 SuffixItem (com.yahoo.prelude.query.SuffixItem)2 Index (com.yahoo.prelude.Index)1 EquivItem (com.yahoo.prelude.query.EquivItem)1 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)1 NearItem (com.yahoo.prelude.query.NearItem)1 NullItem (com.yahoo.prelude.query.NullItem)1