Search in sources :

Example 6 with PhraseItem

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

the class WashPhrasesTestCase method testSimplePositive.

@Test
public void testSimplePositive() {
    PhraseItem root = new PhraseItem();
    root.addItem(new WordItem("abc"));
    assertEquals("abc", transformQuery(root));
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 7 with PhraseItem

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

the class PhraseItemTestCase method testAddItem.

@Test
public void testAddItem() {
    PhraseItem p = new PhraseItem();
    PhraseSegmentItem pp = new PhraseSegmentItem("", false, false);
    PhraseItem ppp = new PhraseItem();
    pp.addItem(new WordItem("b"));
    pp.addItem(new WordItem("c"));
    ppp.addItem(new WordItem("e"));
    ppp.addItem(new WordItem("f"));
    p.addItem(new WordItem("a"));
    p.addItem(pp);
    p.addItem(new WordItem("d"));
    p.addItem(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 8 with PhraseItem

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

the class PhraseItemTestCase method testSetItem.

@Test
public void testSetItem() {
    PhraseItem backup = new PhraseItem();
    PhraseSegmentItem segment = new PhraseSegmentItem("", false, false);
    PhraseItem innerPhrase = new PhraseItem();
    WordItem testWord = new WordItem("z");
    PhraseItem p;
    segment.addItem(new WordItem("p"));
    segment.addItem(new WordItem("q"));
    innerPhrase.addItem(new WordItem("x"));
    innerPhrase.addItem(new WordItem("y"));
    backup.addItem(new WordItem("a"));
    backup.addItem(new WordItem("b"));
    backup.addItem(new WordItem("c"));
    p = (PhraseItem) backup.clone();
    p.setItem(0, segment);
    assertEquals("\"'p q' b c\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(1, segment);
    assertEquals("\"a 'p q' c\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(2, segment);
    assertEquals("\"a b 'p q'\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(0, innerPhrase);
    assertEquals("\"x y b c\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(1, innerPhrase);
    assertEquals("\"a x y c\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(2, innerPhrase);
    assertEquals("\"a b x y\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(0, testWord);
    assertEquals("\"z b c\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(1, testWord);
    assertEquals("\"a z c\"", p.toString());
    p = (PhraseItem) backup.clone();
    p.setItem(2, testWord);
    assertEquals("\"a b z\"", 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 9 with PhraseItem

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

the class PhrasingSearcherTestCase method testTotalPhrasing.

@Test
public void testTotalPhrasing() {
    Searcher searcher = new PhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query();
    AndItem andItem = new AndItem();
    andItem.addItem(new WordItem("tudor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    Item item = ((CompositeItem) query.getModel().getQueryTree().getRoot()).getItem(0);
    assertTrue(item instanceof PhraseItem);
    PhraseItem phrase = (PhraseItem) item;
    assertEquals(2, phrase.getItemCount());
    assertEquals("tudor", phrase.getWordItem(0).getWord());
    assertEquals("vidor", phrase.getWordItem(1).getWord());
    assertEquals("someindex", phrase.getIndexName());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) Searcher(com.yahoo.search.Searcher) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) WordItem(com.yahoo.prelude.query.WordItem) PhrasingSearcher(com.yahoo.prelude.querytransform.PhrasingSearcher) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 10 with PhraseItem

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

the class QueryLanguageTestCase method testPhrase.

@Test
public void testPhrase() {
    PhraseItem p = new PhraseItem();
    p.addItem(new WordItem("part"));
    p.addItem(new WordItem("of"));
    p.addItem(new WordItem("phrase"));
    assertEquals("\"part of phrase\"", p.toString());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) 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