Search in sources :

Example 26 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class SerializeItemTestCase method serialize_phrase_item.

@Test
public void serialize_phrase_item() throws ParseException {
    PhraseItem phraseItem = new PhraseItem(new String[] { "first", "second" });
    phraseItem.setIndexName("indexName");
    PhraseItem deSerialized = serializeThenParse(phraseItem);
    assertThat(deSerialized.getItem(0), is(phraseItem.getItem(0)));
    assertThat(deSerialized.getItem(1), is(phraseItem.getItem(1)));
    assertThat(deSerialized.getIndexName(), is(phraseItem.getIndexName()));
}
Also used : PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 27 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem 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 28 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem 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 29 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem 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)

Example 30 with PhraseItem

use of com.yahoo.prelude.query.PhraseItem in project vespa by vespa-engine.

the class PhrasingSearcherTestCase method testPartialPhrasing.

@Test
public void testPartialPhrasing() {
    Searcher searcher = new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query("?query=void%20tudor%20vidor%20kanoo");
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertEquals("void", ((WordItem) item.getItem(0)).getWord());
    assertEquals("kanoo", ((WordItem) item.getItem(2)).getWord());
    PhraseItem phrase = (PhraseItem) item.getItem(1);
    assertEquals(2, phrase.getItemCount());
    assertEquals("tudor", phrase.getWordItem(0).getWord());
    assertEquals("vidor", phrase.getWordItem(1).getWord());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Aggregations

PhraseItem (com.yahoo.prelude.query.PhraseItem)33 WordItem (com.yahoo.prelude.query.WordItem)24 Test (org.junit.Test)23 CompositeItem (com.yahoo.prelude.query.CompositeItem)14 AndItem (com.yahoo.prelude.query.AndItem)13 Item (com.yahoo.prelude.query.Item)10 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)9 OrItem (com.yahoo.prelude.query.OrItem)5 PrefixItem (com.yahoo.prelude.query.PrefixItem)4 SubstringItem (com.yahoo.prelude.query.SubstringItem)4 SuffixItem (com.yahoo.prelude.query.SuffixItem)4 Query (com.yahoo.search.Query)4 IntItem (com.yahoo.prelude.query.IntItem)3 NotItem (com.yahoo.prelude.query.NotItem)3 RankItem (com.yahoo.prelude.query.RankItem)3 TermItem (com.yahoo.prelude.query.TermItem)2 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)2 Searcher (com.yahoo.search.Searcher)2 QueryTree (com.yahoo.search.query.QueryTree)2 Execution (com.yahoo.search.searchchain.Execution)2