Search in sources :

Example 81 with WordItem

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;
}
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) WordItem(com.yahoo.prelude.query.WordItem)

Example 82 with WordItem

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());
}
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) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) Test(org.junit.Test)

Example 83 with WordItem

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

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

Example 85 with WordItem

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

Aggregations

WordItem (com.yahoo.prelude.query.WordItem)93 Test (org.junit.Test)76 AndItem (com.yahoo.prelude.query.AndItem)45 PhraseItem (com.yahoo.prelude.query.PhraseItem)31 Query (com.yahoo.search.Query)25 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)20 CompositeItem (com.yahoo.prelude.query.CompositeItem)18 Item (com.yahoo.prelude.query.Item)17 MarkerWordItem (com.yahoo.prelude.query.MarkerWordItem)16 NotItem (com.yahoo.prelude.query.NotItem)16 OrItem (com.yahoo.prelude.query.OrItem)13 ByteBuffer (java.nio.ByteBuffer)11 PrefixItem (com.yahoo.prelude.query.PrefixItem)10 SubstringItem (com.yahoo.prelude.query.SubstringItem)10 SuffixItem (com.yahoo.prelude.query.SuffixItem)10 Execution (com.yahoo.search.searchchain.Execution)10 RankItem (com.yahoo.prelude.query.RankItem)9 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)9 IntItem (com.yahoo.prelude.query.IntItem)8 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)7