Search in sources :

Example 36 with WordItem

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

the class ParseTestCase method testFakeCJKSegmentingOfPhrase.

@Test
public void testFakeCJKSegmentingOfPhrase() {
    // "first" "second" and "third" are segments in the test language
    Item item = tester.parseQuery("name:\"firstsecondthird\"", null, Language.CHINESE_SIMPLIFIED, Query.Type.ANY, TestLinguistics.INSTANCE);
    assertTrue(item instanceof PhraseSegmentItem);
    PhraseSegmentItem phrase = (PhraseSegmentItem) item;
    assertEquals(3, phrase.getItemCount());
    assertEquals("name:first", phrase.getItem(0).toString());
    assertEquals("name:second", phrase.getItem(1).toString());
    assertEquals("name:third", phrase.getItem(2).toString());
    assertEquals("name", ((WordItem) phrase.getItem(0)).getIndexName());
    assertEquals("name", ((WordItem) phrase.getItem(1)).getIndexName());
    assertEquals("name", ((WordItem) phrase.getItem(2)).getIndexName());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) Test(org.junit.Test)

Example 37 with WordItem

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

the class ParseTestCase method testShortcutsWeb.

/**
 * Shortcut terms are represented as any other terms, but can be rewritten downstream.
 * The information about added bangs is available from the origin as shown (do not use the weight to find this)
 */
@Test
public void testShortcutsWeb() {
    tester.assertParsed("AND map new york", "map new york", Query.Type.WEB);
    AndItem root = (AndItem) tester.assertParsed("AND map!150 new york", "map! new york", Query.Type.WEB);
    assertEquals('!', ((WordItem) root.getItem(0)).getOrigin().charAfter(0));
    root = (AndItem) tester.assertParsed("AND barack obama news!150", "barack obama news!", Query.Type.WEB);
    assertEquals('!', ((WordItem) root.getItem(2)).getOrigin().charAfter(0));
}
Also used : AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Test(org.junit.Test)

Example 38 with WordItem

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

the class ParseTestCase method testIndexSubstringExtraSpace.

@Test
public void testIndexSubstringExtraSpace() {
    Item root = tester.assertParsed("OR foo substring*", "foo:* substring*", Query.Type.ANY);
    assertTrue(((OrItem) root).getItem(0) instanceof WordItem);
    assertTrue(((OrItem) root).getItem(1) instanceof PrefixItem);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) WordItem(com.yahoo.prelude.query.WordItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 39 with WordItem

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

the class ParseTestCase method testIndexSubstringExtraSpace2.

@Test
public void testIndexSubstringExtraSpace2() {
    Item root = tester.assertParsed("OR foo substring", "foo:* substring *", Query.Type.ANY);
    assertTrue(((OrItem) root).getItem(0) instanceof WordItem);
    assertTrue(((OrItem) root).getItem(1) instanceof WordItem);
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) IntItem(com.yahoo.prelude.query.IntItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) WordItem(com.yahoo.prelude.query.WordItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 40 with WordItem

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

the class LowercasingTestCase method slightlyMoreComplexTree.

@Test
public void slightlyMoreComplexTree() {
    Query q = new Query();
    AndItem a0 = new AndItem();
    OrItem o0 = new OrItem();
    PhraseItem p0 = new PhraseItem();
    p0.setIndexName(BAMSE);
    PhraseSegmentItem p1 = new PhraseSegmentItem("Overbuljongterningpakkmesterassistent", true, false);
    p1.setIndexName(BAMSE);
    WordItem tmp;
    tmp = new WordItem("Nalle0", BAMSE, true);
    a0.addItem(tmp);
    tmp = new WordItem("Nalle1", BAMSE, true);
    o0.addItem(tmp);
    tmp = new WordItem("Nalle2", BAMSE, true);
    o0.addItem(tmp);
    a0.addItem(o0);
    tmp = new WordItem("Nalle3", BAMSE, true);
    p0.addItem(tmp);
    p1.addItem(new WordItem("Over", BAMSE, true));
    p1.addItem(new WordItem("buljong", BAMSE, true));
    p1.addItem(new WordItem("terning", BAMSE, true));
    p1.addItem(new WordItem("pakk", BAMSE, true));
    p1.addItem(new WordItem("Mester", BAMSE, true));
    p1.addItem(new WordItem("assistent", BAMSE, true));
    p1.lock();
    p0.addItem(p1);
    a0.addItem(p0);
    q.getModel().getQueryTree().setRoot(a0);
    Result r = execution.search(q);
    AndItem root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    tmp = (WordItem) root.getItem(0);
    assertEquals("nalle0", tmp.getWord());
    OrItem orElement = (OrItem) root.getItem(1);
    tmp = (WordItem) orElement.getItem(0);
    assertEquals("nalle1", tmp.getWord());
    tmp = (WordItem) orElement.getItem(1);
    assertEquals("nalle2", tmp.getWord());
    PhraseItem phrase = (PhraseItem) root.getItem(2);
    tmp = (WordItem) phrase.getItem(0);
    assertEquals("nalle3", tmp.getWord());
    PhraseSegmentItem locked = (PhraseSegmentItem) phrase.getItem(1);
    assertEquals("over", ((WordItem) locked.getItem(0)).getWord());
    assertEquals("buljong", ((WordItem) locked.getItem(1)).getWord());
    assertEquals("terning", ((WordItem) locked.getItem(2)).getWord());
    assertEquals("pakk", ((WordItem) locked.getItem(3)).getWord());
    assertEquals("mester", ((WordItem) locked.getItem(4)).getWord());
    assertEquals("assistent", ((WordItem) locked.getItem(5)).getWord());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Result(com.yahoo.search.Result) 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