use of com.yahoo.prelude.query.WordItem 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());
}
use of com.yahoo.prelude.query.WordItem 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());
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class GroupingExecutorTestCase method testIllegalQuery.
@Test
public void testIllegalQuery() {
Execution exc = newExecution(new GroupingExecutor());
Query query = new Query();
NotItem notItem = new NotItem();
notItem.addNegativeItem(new WordItem("negative"));
query.getModel().getQueryTree().setRoot(notItem);
Result result = exc.search(query);
com.yahoo.search.result.ErrorMessage message = result.hits().getError();
assertNotNull("Got error", message);
assertEquals("Illegal query", message.getMessage());
assertEquals("Can not search for only negative items", message.getDetailedMessage());
assertEquals(3, message.getCode());
}
use of com.yahoo.prelude.query.WordItem 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);
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class ParseTestCase method testPrefixExtraSpace.
@Test
public void testPrefixExtraSpace() {
Item root = tester.assertParsed("prefix", "prefix *", Query.Type.ANY);
assertTrue(root instanceof WordItem);
}
Aggregations