Search in sources :

Example 16 with AndItem

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

the class QueryRewriteTestCase method assertAndNotMovedUp.

@Test
public void assertAndNotMovedUp() {
    Query query = new Query();
    NotItem not = new NotItem();
    not.addPositiveItem(new WordItem("a"));
    not.addNegativeItem(new WordItem("na"));
    AndItem and = new AndItem();
    and.addItem(not);
    query.getModel().getQueryTree().setRoot(and);
    QueryRewrite.optimizeAndNot(query);
    assertTrue(query.getModel().getQueryTree().getRoot() instanceof NotItem);
    NotItem n = (NotItem) query.getModel().getQueryTree().getRoot();
    assertEquals(2, n.getItemCount());
    assertTrue(n.getPositiveItem() instanceof AndItem);
    AndItem a = (AndItem) n.getPositiveItem();
    assertEquals(1, a.getItemCount());
    assertEquals("a", a.getItem(0).toString());
    assertEquals("na", n.getItem(1).toString());
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 17 with AndItem

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

the class QueryRewriteTestCase method assertMultipleAndNotIsCollapsed.

@Test
public void assertMultipleAndNotIsCollapsed() {
    Query query = new Query();
    NotItem not1 = new NotItem();
    not1.addPositiveItem(new WordItem("a"));
    not1.addNegativeItem(new WordItem("na1"));
    not1.addNegativeItem(new WordItem("na2"));
    NotItem not2 = new NotItem();
    not2.addPositiveItem(new WordItem("b"));
    not2.addNegativeItem(new WordItem("nb"));
    AndItem and = new AndItem();
    and.addItem(new WordItem("1"));
    and.addItem(not1);
    and.addItem(new WordItem("2"));
    and.addItem(not2);
    and.addItem(new WordItem("3"));
    query.getModel().getQueryTree().setRoot(and);
    QueryRewrite.optimizeAndNot(query);
    assertTrue(query.getModel().getQueryTree().getRoot() instanceof NotItem);
    NotItem n = (NotItem) query.getModel().getQueryTree().getRoot();
    assertTrue(n.getPositiveItem() instanceof AndItem);
    assertEquals(4, n.getItemCount());
    AndItem a = (AndItem) n.getPositiveItem();
    assertEquals(5, a.getItemCount());
    assertEquals("na1", n.getItem(1).toString());
    assertEquals("na2", n.getItem(2).toString());
    assertEquals("nb", n.getItem(3).toString());
    assertEquals("1", a.getItem(0).toString());
    assertEquals("a", a.getItem(1).toString());
    assertEquals("2", a.getItem(2).toString());
    assertEquals("b", a.getItem(3).toString());
    assertEquals("3", a.getItem(4).toString());
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 18 with AndItem

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

the class QueryCanonicalizerMicroBenchmark method canonicalize.

private void canonicalize() {
    AndItem and = new AndItem();
    and.addItem(new WordItem("shoe", "prod"));
    and.addItem(new WordItem("apparel & accessories", "tcnm"));
    RankItem rank = new RankItem();
    rank.addItem(and);
    for (int i = 0; i < 25; i++) rank.addItem(new WordItem("word" + i, "normbrnd"));
    QueryTree tree = new QueryTree(rank);
    QueryCanonicalizer.canonicalize(tree);
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) QueryTree(com.yahoo.search.query.QueryTree) WordItem(com.yahoo.prelude.query.WordItem)

Example 19 with AndItem

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

the class ParseTestCase method testShortcutsWeb.

/**
 * Shortcut terms are represented as any other terms, but can be rewritten downstream.
 * The information about added bangs is available from the origin as shown (do not use the weight to find this)
 */
@Test
public void testShortcutsWeb() {
    tester.assertParsed("AND map new york", "map new york", Query.Type.WEB);
    AndItem root = (AndItem) tester.assertParsed("AND map!150 new york", "map! new york", Query.Type.WEB);
    assertEquals('!', ((WordItem) root.getItem(0)).getOrigin().charAfter(0));
    root = (AndItem) tester.assertParsed("AND barack obama news!150", "barack obama news!", Query.Type.WEB);
    assertEquals('!', ((WordItem) root.getItem(2)).getOrigin().charAfter(0));
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 20 with AndItem

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

the class ParseTestCase method testPlusWordWebParsing1.

@Test
public void testPlusWordWebParsing1() {
    Item root = tester.assertParsed("AND a b", "+a b", Query.Type.WEB);
    assertTrue(((AndItem) root).getItem(0).isProtected());
    assertFalse(((AndItem) 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) AndItem(com.yahoo.prelude.query.AndItem) 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