Search in sources :

Example 16 with QueryTree

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());
}
Also used : QueryTree(com.yahoo.search.query.QueryTree) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 17 with QueryTree

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

Example 18 with QueryTree

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());
}
Also used : QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

Example 19 with QueryTree

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();
        }
    }
}
Also used : IndexedItem(com.yahoo.prelude.query.IndexedItem) QueryTree(com.yahoo.search.query.QueryTree) Test(org.junit.Test)

Example 20 with QueryTree

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));
}
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) QueryTree(com.yahoo.search.query.QueryTree) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Aggregations

QueryTree (com.yahoo.search.query.QueryTree)26 Test (org.junit.Test)13 AndItem (com.yahoo.prelude.query.AndItem)7 PhraseItem (com.yahoo.prelude.query.PhraseItem)7 WordItem (com.yahoo.prelude.query.WordItem)7 IndexedItem (com.yahoo.prelude.query.IndexedItem)6 Item (com.yahoo.prelude.query.Item)6 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)6 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)5 RegExpItem (com.yahoo.prelude.query.RegExpItem)5 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 SuffixItem (com.yahoo.prelude.query.SuffixItem)5 WordAlternativesItem (com.yahoo.prelude.query.WordAlternativesItem)5 Parsable (com.yahoo.search.query.parser.Parsable)3 ParserEnvironment (com.yahoo.search.query.parser.ParserEnvironment)3 IndexFacts (com.yahoo.prelude.IndexFacts)2 IndexModel (com.yahoo.prelude.IndexModel)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 RankItem (com.yahoo.prelude.query.RankItem)2