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());
}
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());
}
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());
}
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());
}
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."));
}
Aggregations