Search in sources :

Example 11 with WordItem

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

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

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

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

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

the class PhrasingSearcherTestCase method testNoPhrasingIfDifferentIndices.

@Test
public void testNoPhrasingIfDifferentIndices() {
    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", "anotherindex"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertTrue(item.getItem(0) instanceof WordItem);
    WordItem word = (WordItem) item.getItem(0);
    assertEquals("tudor", word.getWord());
    assertTrue(item.getItem(1) instanceof WordItem);
    word = (WordItem) item.getItem(1);
    assertEquals("vidor", word.getWord());
}
Also used : 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) 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