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