Search in sources :

Example 6 with OrItem

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

Example 7 with OrItem

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

the class SerializeItemTestCase method serialize_connectivity.

@Test
public void serialize_connectivity() throws ParseException {
    OrItem orItem = new OrItem();
    {
        WordItem first = new WordItem("first");
        WordItem second = new WordItem("second");
        first.setConnectivity(second, 3.14);
        orItem.addItem(first);
        orItem.addItem(second);
    }
    OrItem deSerialized = serializeThenParse(orItem);
    WordItem first = (WordItem) deSerialized.getItem(0);
    Item second = deSerialized.getItem(1);
    assertThat(first.getConnectedItem(), is(second));
    assertThat(first.getConnectivity(), is(3.14));
}
Also used : 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) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) EquivItem(com.yahoo.prelude.query.EquivItem) WordItem(com.yahoo.prelude.query.WordItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 8 with OrItem

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

the class QueryTestCase method testCloneWithConnectivity.

@Test
public void testCloneWithConnectivity() {
    List<String> l = new ArrayList();
    l.add("a");
    l.add("b");
    l.add("c");
    l.add("a");
    printIt(l.stream().filter(i -> isA(i)).collect(Collectors.toList()));
    printIt(l.stream().filter(i -> !isA(i)).collect(Collectors.toList()));
    Query q = new Query();
    WordItem a = new WordItem("a");
    WordItem b = new WordItem("b");
    WordItem c = new WordItem("c");
    WordItem d = new WordItem("d");
    WordItem e = new WordItem("e");
    WordItem f = new WordItem("f");
    WordItem g = new WordItem("g");
    OrItem or = new OrItem();
    or.addItem(c);
    or.addItem(d);
    AndItem and1 = new AndItem();
    and1.addItem(a);
    and1.addItem(b);
    and1.addItem(or);
    and1.addItem(e);
    AndItem and2 = new AndItem();
    and2.addItem(f);
    and2.addItem(g);
    RankItem rank = new RankItem();
    rank.addItem(and1);
    rank.addItem(and2);
    a.setConnectivity(b, 0.1);
    b.setConnectivity(c, 0.2);
    c.setConnectivity(d, 0.3);
    d.setConnectivity(e, 0.4);
    e.setConnectivity(f, 0.5);
    f.setConnectivity(g, 0.6);
    q.getModel().getQueryTree().setRoot(rank);
    Query qClone = q.clone();
    assertEquals(q, qClone);
    RankItem rankClone = (RankItem) qClone.getModel().getQueryTree().getRoot();
    AndItem and1Clone = (AndItem) rankClone.getItem(0);
    AndItem and2Clone = (AndItem) rankClone.getItem(1);
    OrItem orClone = (OrItem) and1Clone.getItem(2);
    WordItem aClone = (WordItem) and1Clone.getItem(0);
    WordItem bClone = (WordItem) and1Clone.getItem(1);
    WordItem cClone = (WordItem) orClone.getItem(0);
    WordItem dClone = (WordItem) orClone.getItem(1);
    WordItem eClone = (WordItem) and1Clone.getItem(3);
    WordItem fClone = (WordItem) and2Clone.getItem(0);
    WordItem gClone = (WordItem) and2Clone.getItem(1);
    assertTrue(rankClone != rank);
    assertTrue(and1Clone != and1);
    assertTrue(and2Clone != and2);
    assertTrue(orClone != or);
    assertTrue(aClone != a);
    assertTrue(bClone != b);
    assertTrue(cClone != c);
    assertTrue(dClone != d);
    assertTrue(eClone != e);
    assertTrue(fClone != f);
    assertTrue(gClone != g);
    assertTrue(aClone.getConnectedItem() == bClone);
    assertTrue(bClone.getConnectedItem() == cClone);
    assertTrue(cClone.getConnectedItem() == dClone);
    assertTrue(dClone.getConnectedItem() == eClone);
    assertTrue(eClone.getConnectedItem() == fClone);
    assertTrue(fClone.getConnectedItem() == gClone);
    double delta = 0.0000001;
    assertEquals(0.1, aClone.getConnectivity(), delta);
    assertEquals(0.2, bClone.getConnectivity(), delta);
    assertEquals(0.3, cClone.getConnectivity(), delta);
    assertEquals(0.4, dClone.getConnectivity(), delta);
    assertEquals(0.5, eClone.getConnectivity(), delta);
    assertEquals(0.6, fClone.getConnectivity(), delta);
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WordItem(com.yahoo.prelude.query.WordItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 9 with OrItem

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

the class PhrasingSearcherTestCase method testMultiplePhrases.

@Test
public void testMultiplePhrases() {
    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("tudor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    andItem.addItem(new WordItem("vidor", "someindex"));
    OrItem orItem = new OrItem();
    andItem.addItem(orItem);
    orItem.addItem(new WordItem("tudor"));
    AndItem andItem2 = new AndItem();
    andItem2.addItem(new WordItem("this", "anotherindex"));
    andItem2.addItem(new WordItem("is", "anotherindex"));
    andItem2.addItem(new WordItem("a", "anotherindex"));
    andItem2.addItem(new WordItem("test", "anotherindex"));
    andItem2.addItem(new WordItem("tudor", "anotherindex"));
    andItem2.addItem(new WordItem("vidor", "anotherindex"));
    orItem.addItem(andItem2);
    orItem.addItem(new WordItem("vidor"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertEquals("AND someindex:tudor someindex:\"tudor vidor\" someindex:vidor (OR tudor (AND anotherindex:\"this is a test\" anotherindex:\"tudor vidor\") vidor)", query.getModel().getQueryTree().getRoot().toString());
}
Also used : 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) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Example 10 with OrItem

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

the class ParseTestCase method testSubstringAndWordTerms.

@Test
public void testSubstringAndWordTerms() {
    Item root = tester.assertParsed("OR foo *substring* bar", "foo *substring* bar", Query.Type.ANY);
    assertTrue(((OrItem) root).getItem(1) instanceof SubstringItem);
}
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) SubstringItem(com.yahoo.prelude.query.SubstringItem) OrItem(com.yahoo.prelude.query.OrItem) Test(org.junit.Test)

Aggregations

AndItem (com.yahoo.prelude.query.AndItem)12 OrItem (com.yahoo.prelude.query.OrItem)12 Test (org.junit.Test)12 WordItem (com.yahoo.prelude.query.WordItem)11 PhraseItem (com.yahoo.prelude.query.PhraseItem)8 RankItem (com.yahoo.prelude.query.RankItem)8 Item (com.yahoo.prelude.query.Item)7 NotItem (com.yahoo.prelude.query.NotItem)7 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)7 CompositeItem (com.yahoo.prelude.query.CompositeItem)6 IntItem (com.yahoo.prelude.query.IntItem)6 PrefixItem (com.yahoo.prelude.query.PrefixItem)6 SubstringItem (com.yahoo.prelude.query.SubstringItem)6 SuffixItem (com.yahoo.prelude.query.SuffixItem)6 Query (com.yahoo.search.Query)4 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)2 Searcher (com.yahoo.search.Searcher)2 Execution (com.yahoo.search.searchchain.Execution)2 EquivItem (com.yahoo.prelude.query.EquivItem)1 NearItem (com.yahoo.prelude.query.NearItem)1