use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class YqlParserTestCase method getRootWord.
private WordItem getRootWord(String yqlQuery) {
Item root = parse(yqlQuery).getRoot();
assertTrue(root instanceof WordItem);
return (WordItem) root;
}
use of com.yahoo.prelude.query.WordItem 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.WordItem 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."));
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class YqlParserTestCase method testWordAlternativesInPhrase.
@Test
public void testWordAlternativesInPhrase() {
QueryTree x = parse("select * from sources * where" + " foo contains phrase(\"forest\", alternatives({\"trees\": 1.0, \"tree\": 0.7}));");
Item root = x.getRoot();
assertSame(PhraseItem.class, root.getClass());
PhraseItem phrase = (PhraseItem) root;
assertEquals(2, phrase.getItemCount());
assertEquals("forest", ((WordItem) phrase.getItem(0)).getWord());
checkWordAlternativesContent((WordAlternativesItem) phrase.getItem(1));
}
use of com.yahoo.prelude.query.WordItem in project vespa by vespa-engine.
the class PhraseItemTestCase method testAddItemWithIndex.
@Test
public void testAddItemWithIndex() {
PhraseItem p = new PhraseItem();
PhraseSegmentItem pp = new PhraseSegmentItem("", false, false);
PhraseItem ppp = new PhraseItem();
pp.addItem(new WordItem("a"));
pp.addItem(new WordItem("b"));
ppp.addItem(new WordItem("c"));
ppp.addItem(new WordItem("d"));
p.addItem(0, new WordItem("e"));
p.addItem(0, pp);
p.addItem(2, new WordItem("f"));
p.addItem(1, ppp);
assertEquals("\"'a b' c d e f\"", p.toString());
}
Aggregations