Search in sources :

Example 21 with AndItem

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

the class QueryTreeUtil method andQueryItemWithRoot.

public static void andQueryItemWithRoot(QueryTree tree, Item item) {
    if (tree.isEmpty()) {
        tree.setRoot(item);
    } else {
        Item oldRoot = tree.getRoot();
        if (oldRoot.getClass() == AndItem.class) {
            ((AndItem) oldRoot).addItem(item);
        } else {
            AndItem newRoot = new AndItem();
            newRoot.addItem(oldRoot);
            newRoot.addItem(item);
            tree.setRoot(newRoot);
        }
    }
}
Also used : Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) AndItem(com.yahoo.prelude.query.AndItem)

Example 22 with AndItem

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

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

the class LowercasingTestCase method testWeightedSet.

@Test
public void testWeightedSet() {
    Query q = new Query();
    AndItem root = new AndItem();
    WeightedSetItem tmp;
    tmp = new WeightedSetItem(BAMSE);
    tmp.addToken("AbC", 3);
    root.addItem(tmp);
    tmp = new WeightedSetItem(TEDDY);
    tmp.addToken("dEf", 5);
    root.addItem(tmp);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    WeightedSetItem w0 = (WeightedSetItem) root.getItem(0);
    WeightedSetItem w1 = (WeightedSetItem) root.getItem(1);
    assertEquals(1, w0.getNumTokens());
    assertEquals(1, w1.getNumTokens());
    assertEquals("abc", w0.getTokens().next().getKey());
    assertEquals("dEf", w1.getTokens().next().getKey());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 24 with AndItem

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

the class LowercasingTestCase method testDisableLowercasingWeightedSet.

@Test
public void testDisableLowercasingWeightedSet() {
    execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder().transform_weighted_sets(false)))), Execution.Context.createContextStub(settings));
    Query q = new Query();
    AndItem root = new AndItem();
    WeightedSetItem tmp;
    tmp = new WeightedSetItem(BAMSE);
    tmp.addToken("AbC", 3);
    root.addItem(tmp);
    tmp = new WeightedSetItem(TEDDY);
    tmp.addToken("dEf", 5);
    root.addItem(tmp);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    WeightedSetItem w0 = (WeightedSetItem) root.getItem(0);
    WeightedSetItem w1 = (WeightedSetItem) root.getItem(1);
    assertEquals(1, w0.getNumTokens());
    assertEquals(1, w1.getNumTokens());
    assertEquals("AbC", w0.getTokens().next().getKey());
    assertEquals("dEf", w1.getTokens().next().getKey());
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 25 with AndItem

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

the class LowercasingTestCase method smoke.

@Test
public void smoke() {
    Query q = new Query();
    AndItem root = new AndItem();
    WordItem tmp;
    tmp = new WordItem("Gnuff", BAMSE, true);
    root.addItem(tmp);
    tmp = new WordItem("Blaff", TEDDY, true);
    root.addItem(tmp);
    tmp = new WordItem("Blyant", "", true);
    root.addItem(tmp);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    WordItem w0 = (WordItem) root.getItem(0);
    WordItem w1 = (WordItem) root.getItem(1);
    WordItem w2 = (WordItem) root.getItem(2);
    assertEquals("gnuff", w0.getWord());
    assertEquals("Blaff", w1.getWord());
    assertEquals("blyant", w2.getWord());
}
Also used : Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

AndItem (com.yahoo.prelude.query.AndItem)50 Test (org.junit.Test)39 WordItem (com.yahoo.prelude.query.WordItem)36 Query (com.yahoo.search.Query)24 Item (com.yahoo.prelude.query.Item)13 CompositeItem (com.yahoo.prelude.query.CompositeItem)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)12 OrItem (com.yahoo.prelude.query.OrItem)10 Execution (com.yahoo.search.searchchain.Execution)10 IntItem (com.yahoo.prelude.query.IntItem)9 NotItem (com.yahoo.prelude.query.NotItem)7 RankItem (com.yahoo.prelude.query.RankItem)7 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhraseMatcher (com.yahoo.prelude.querytransform.PhraseMatcher)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)5 Searcher (com.yahoo.search.Searcher)5 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 WeakAndItem (com.yahoo.prelude.query.WeakAndItem)4 Result (com.yahoo.search.Result)4 IndexFacts (com.yahoo.prelude.IndexFacts)3