Search in sources :

Example 41 with AndItem

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

the class RangeQueryOptimizerTestCase method testRangeOptimizingCarriesOverItemAttributesWhenOptimized.

@Test
public void testRangeOptimizingCarriesOverItemAttributesWhenOptimized() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    Item intItem1 = new IntItem(">" + 15, "s");
    intItem1.setFilter(true);
    intItem1.setRanked(false);
    intItem1.setWeight(500);
    root.addItem(intItem1);
    Item intItem2 = new IntItem("<" + 30, "s");
    intItem2.setFilter(true);
    intItem2.setRanked(false);
    intItem2.setWeight(500);
    root.addItem(intItem2);
    assertOptimized("Optimized", "AND |s:<15;30>!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 42 with AndItem

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

the class RangeQueryOptimizerTestCase method testNoRangeOptimizingWhenAttributesAreIncompatible.

@Test
public void testNoRangeOptimizingWhenAttributesAreIncompatible() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    Item intItem1 = new IntItem(">" + 15, "s");
    intItem1.setFilter(true);
    intItem1.setRanked(false);
    intItem1.setWeight(500);
    root.addItem(intItem1);
    Item intItem2 = new IntItem("<" + 30, "s");
    // Disagrees with item1
    intItem2.setFilter(false);
    intItem2.setRanked(false);
    intItem2.setWeight(500);
    root.addItem(intItem2);
    assertOptimized("Not optimized", "AND |s:<15;]!500 s:[;30>!500", query);
    IntItem transformedIntItem1 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertTrue("Filter was carried over", transformedIntItem1.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem1.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem1.getWeight());
    IntItem transformedIntItem2 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(1);
    assertFalse("Filter was carried over", transformedIntItem2.isFilter());
    assertFalse("Ranked was carried over", transformedIntItem2.isRanked());
    assertEquals("Weight was carried over", 500, transformedIntItem2.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 43 with AndItem

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

the class RangeQueryOptimizerTestCase method testDifferentCompatibleRangesPerFieldAreOptimizedSeparately.

@Test
public void testDifferentCompatibleRangesPerFieldAreOptimizedSeparately() {
    Query query = new Query();
    AndItem root = new AndItem();
    query.getModel().getQueryTree().setRoot(root);
    // Two internally compatible items
    Item intItem1 = new IntItem(">" + 15, "s");
    intItem1.setRanked(false);
    root.addItem(intItem1);
    Item intItem2 = new IntItem("<" + 30, "s");
    intItem2.setRanked(false);
    root.addItem(intItem2);
    // Two other internally compatible items incompatible with the above
    Item intItem3 = new IntItem(">" + 100, "s");
    root.addItem(intItem3);
    Item intItem4 = new IntItem("<" + 150, "s");
    root.addItem(intItem4);
    assertOptimized("Optimized", "AND s:<15;30> s:<100;150>", query);
    IntItem transformedIntItem1 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertFalse("Ranked was carried over", transformedIntItem1.isRanked());
    IntItem transformedIntItem2 = (IntItem) ((AndItem) query.getModel().getQueryTree().getRoot()).getItem(1);
    assertTrue("Ranked was carried over", transformedIntItem2.isRanked());
}
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 44 with AndItem

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

the class YqlParserTestCase method testRaw.

@Test
public void testRaw() {
    Item root = parse("select foo from bar where baz contains (\"yoni jo dima\");").getRoot();
    assertTrue(root instanceof WordItem);
    assertFalse(root instanceof ExactStringItem);
    assertEquals("yoni jo dima", ((WordItem) root).getWord());
    root = parse("select foo from bar where baz contains ([{\"grammar\":\"raw\"}]\"yoni jo dima\");").getRoot();
    assertTrue(root instanceof WordItem);
    assertFalse(root instanceof ExactStringItem);
    assertEquals("yoni jo dima", ((WordItem) root).getWord());
    root = parse("select foo from bar where userInput(\"yoni jo dima\");").getRoot();
    assertTrue(root instanceof AndItem);
    AndItem andItem = (AndItem) root;
    assertEquals(3, andItem.getItemCount());
    root = parse("select foo from bar where [{\"grammar\":\"raw\"}]userInput(\"yoni jo dima\");").getRoot();
    assertTrue(root instanceof WordItem);
    assertTrue(root instanceof ExactStringItem);
    assertEquals("yoni jo dima", ((WordItem) root).getWord());
}
Also used : WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) IndexedItem(com.yahoo.prelude.query.IndexedItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) Test(org.junit.Test)

Example 45 with AndItem

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

the class YqlParserTestCase method testConnectivity.

@Test
public void testConnectivity() {
    QueryTree parsed = parse("select foo from bar where " + "title contains ([{\"id\": 1, \"connectivity\": {\"id\": 3, \"weight\": 7.0}}]\"madonna\") " + "and title contains ([{\"id\": 2}]\"saint\") " + "and title contains ([{\"id\": 3}]\"angel\");");
    assertEquals("AND title:madonna title:saint title:angel", parsed.toString());
    AndItem root = (AndItem) parsed.getRoot();
    WordItem first = (WordItem) root.getItem(0);
    WordItem second = (WordItem) root.getItem(1);
    WordItem third = (WordItem) root.getItem(2);
    assertTrue(first.getConnectedItem() == third);
    assertEquals(first.getConnectivity(), 7.0d, 1E-6);
    assertNull(second.getConnectedItem());
    assertParseFail("select foo from bar where " + "title contains ([{\"id\": 1, \"connectivity\": {\"id\": 4, \"weight\": 7.0}}]\"madonna\") " + "and title contains ([{\"id\": 2}]\"saint\") " + "and title contains ([{\"id\": 3}]\"angel\");", new NullPointerException("Item 'title:madonna' was specified to connect to item with ID 4, " + "which does not exist in the query."));
}
Also used : WeakAndItem(com.yahoo.prelude.query.WeakAndItem) AndItem(com.yahoo.prelude.query.AndItem) QueryTree(com.yahoo.search.query.QueryTree) WordItem(com.yahoo.prelude.query.WordItem) 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