use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class YqlParserTestCase method testAnnotatedPhrase.
@Test
public void testAnnotatedPhrase() {
QueryTree parsed = parse("select foo from bar where baz contains ([{\"label\": \"hello world\"}]phrase(\"a\", \"b\"));");
assertEquals("baz:\"a b\"", parsed.toString());
PhraseItem phrase = (PhraseItem) parsed.getRoot();
assertEquals("hello world", phrase.getLabel());
}
use of com.yahoo.search.query.QueryTree 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.search.query.QueryTree in project vespa by vespa-engine.
the class YqlParserTestCase method testLanguageDetection.
@Test
public void testLanguageDetection() {
// SimpleDetector used here can detect japanese and will set that as language at the root of the user input
QueryTree tree = parse("select * from sources * where userInput(\"\u30ab\u30bf\u30ab\u30ca\");");
assertEquals(Language.JAPANESE, tree.getRoot().getLanguage());
}
use of com.yahoo.search.query.QueryTree in project vespa by vespa-engine.
the class YqlParserTestCase method testMoreInheritedAnnotations.
@Test
public void testMoreInheritedAnnotations() {
final String yqlQuery = "select * from sources * where " + "([{\"ranked\": false}](foo contains \"a\" " + "and ([{\"ranked\": true}](bar contains \"b\" " + "or ([{\"ranked\": false}](foo contains \"c\" " + "and foo contains ([{\"ranked\": true}]\"d\")))))));";
QueryTree x = parse(yqlQuery);
List<IndexedItem> terms = QueryTree.getPositiveTerms(x);
assertEquals(4, terms.size());
for (IndexedItem term : terms) {
switch(term.getIndexedString()) {
case "a":
case "c":
assertFalse(((Item) term).isRanked());
break;
case "b":
case "d":
assertTrue(((Item) term).isRanked());
break;
default:
fail();
}
}
}
use of com.yahoo.search.query.QueryTree 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));
}
Aggregations