Search in sources :

Example 26 with AndItem

use of com.yahoo.prelude.query.AndItem 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 27 with AndItem

use of com.yahoo.prelude.query.AndItem in project vespa by vespa-engine.

the class ItemEncodingTestCase method testAndItemEncoding.

@Test
public void testAndItemEncoding() {
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    AndItem and = new AndItem();
    and.addItem(a);
    and.addItem(b);
    ByteBuffer buffer = ByteBuffer.allocate(128);
    int count = and.encode(buffer);
    buffer.flip();
    assertEquals("Serialization count", 3, count);
    assertType(buffer, 1, 0);
    assertEquals("And arity", 2, buffer.get());
    assertWord(buffer, "a");
    assertWord(buffer, "b");
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) MarkerWordItem(com.yahoo.prelude.query.MarkerWordItem) WordItem(com.yahoo.prelude.query.WordItem) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 28 with AndItem

use of com.yahoo.prelude.query.AndItem in project vespa by vespa-engine.

the class RangeQueryOptimizerTestCase method testRangeOptimizingCarriesOverItemAttributesWhenNotOptimized.

@Test
public void testRangeOptimizingCarriesOverItemAttributesWhenNotOptimized() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    Item intItem = new IntItem(">" + 15, "s");
    intItem.setWeight(500);
    intItem.setFilter(true);
    intItem.setRanked(false);
    root.addItem(intItem);
    assertOptimized("Not optimized", "AND |s:<15;]!500", query);
    IntItem transformedIntItem = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertTrue("Filter was carried over", transformedIntItem.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem.getWeight());
}
Also used : IntItem(com.yahoo.prelude.query.IntItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) IntItem(com.yahoo.prelude.query.IntItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Example 29 with AndItem

use of com.yahoo.prelude.query.AndItem in project vespa by vespa-engine.

the class NGramSearcherTestCase method testNGramRewritingAdditionalTermInfo.

public void testNGramRewritingAdditionalTermInfo() {
    Query q = new Query("?query=gram3:engul!50+foo+gram2:123!150");
    new Execution(searcher, Execution.Context.createContextStub(indexFacts)).search(q);
    AndItem root = (AndItem) q.getModel().getQueryTree().getRoot();
    AndItem gram3And = (AndItem) root.getItem(0);
    AndItem gram2And = (AndItem) root.getItem(2);
    assertExtraTermInfo(50, "engul", gram3And.getItem(0));
    assertExtraTermInfo(50, "engul", gram3And.getItem(1));
    assertExtraTermInfo(50, "engul", gram3And.getItem(2));
    assertExtraTermInfo(150, "123", gram2And.getItem(0));
    assertExtraTermInfo(150, "123", gram2And.getItem(1));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem)

Example 30 with AndItem

use of com.yahoo.prelude.query.AndItem in project vespa by vespa-engine.

the class QueryTestCase method testCloneWithConnectivity.

@Test
public void testCloneWithConnectivity() {
    List<String> l = new ArrayList();
    l.add("a");
    l.add("b");
    l.add("c");
    l.add("a");
    printIt(l.stream().filter(i -> isA(i)).collect(Collectors.toList()));
    printIt(l.stream().filter(i -> !isA(i)).collect(Collectors.toList()));
    Query q = new Query();
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    WordItem c = new WordItem("c");
    WordItem d = new WordItem("d");
    WordItem e = new WordItem("e");
    WordItem f = new WordItem("f");
    WordItem g = new WordItem("g");
    OrItem or = new OrItem();
    or.addItem(c);
    or.addItem(d);
    AndItem and1 = new AndItem();
    and1.addItem(a);
    and1.addItem(b);
    and1.addItem(or);
    and1.addItem(e);
    AndItem and2 = new AndItem();
    and2.addItem(f);
    and2.addItem(g);
    RankItem rank = new RankItem();
    rank.addItem(and1);
    rank.addItem(and2);
    a.setConnectivity(b, 0.1);
    b.setConnectivity(c, 0.2);
    c.setConnectivity(d, 0.3);
    d.setConnectivity(e, 0.4);
    e.setConnectivity(f, 0.5);
    f.setConnectivity(g, 0.6);
    q.getModel().getQueryTree().setRoot(rank);
    Query qClone = q.clone();
    assertEquals(q, qClone);
    RankItem rankClone = (RankItem) qClone.getModel().getQueryTree().getRoot();
    AndItem and1Clone = (AndItem) rankClone.getItem(0);
    AndItem and2Clone = (AndItem) rankClone.getItem(1);
    OrItem orClone = (OrItem) and1Clone.getItem(2);
    WordItem aClone = (WordItem) and1Clone.getItem(0);
    WordItem bClone = (WordItem) and1Clone.getItem(1);
    WordItem cClone = (WordItem) orClone.getItem(0);
    WordItem dClone = (WordItem) orClone.getItem(1);
    WordItem eClone = (WordItem) and1Clone.getItem(3);
    WordItem fClone = (WordItem) and2Clone.getItem(0);
    WordItem gClone = (WordItem) and2Clone.getItem(1);
    assertTrue(rankClone != rank);
    assertTrue(and1Clone != and1);
    assertTrue(and2Clone != and2);
    assertTrue(orClone != or);
    assertTrue(aClone != a);
    assertTrue(bClone != b);
    assertTrue(cClone != c);
    assertTrue(dClone != d);
    assertTrue(eClone != e);
    assertTrue(fClone != f);
    assertTrue(gClone != g);
    assertTrue(aClone.getConnectedItem() == bClone);
    assertTrue(bClone.getConnectedItem() == cClone);
    assertTrue(cClone.getConnectedItem() == dClone);
    assertTrue(dClone.getConnectedItem() == eClone);
    assertTrue(eClone.getConnectedItem() == fClone);
    assertTrue(fClone.getConnectedItem() == gClone);
    double delta = 0.0000001;
    assertEquals(0.1, aClone.getConnectivity(), delta);
    assertEquals(0.2, bClone.getConnectivity(), delta);
    assertEquals(0.3, cClone.getConnectivity(), delta);
    assertEquals(0.4, dClone.getConnectivity(), delta);
    assertEquals(0.5, eClone.getConnectivity(), delta);
    assertEquals(0.6, fClone.getConnectivity(), delta);
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WordItem(com.yahoo.prelude.query.WordItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Aggregations

AndItem (com.yahoo.prelude.query.AndItem)50 Test (org.junit.Test)39 WordItem (com.yahoo.prelude.query.WordItem)36 Query (com.yahoo.search.Query)24 Item (com.yahoo.prelude.query.Item)13 CompositeItem (com.yahoo.prelude.query.CompositeItem)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)12 OrItem (com.yahoo.prelude.query.OrItem)10 Execution (com.yahoo.search.searchchain.Execution)10 IntItem (com.yahoo.prelude.query.IntItem)9 NotItem (com.yahoo.prelude.query.NotItem)7 RankItem (com.yahoo.prelude.query.RankItem)7 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)5 Searcher (com.yahoo.search.Searcher)5 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)4 Result (com.yahoo.search.Result)4 IndexFacts (com.yahoo.prelude.IndexFacts)3