Search in sources :

Example 11 with CompositeItem

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

the class RecallSearcherTestCase method assertQueryTree.

private static void assertQueryTree(String query, List<String> ranked, List<String> unranked) {
    RecallSearcher searcher = new RecallSearcher();
    Query obj = new Query(query);
    Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(obj);
    if (result.hits().getError() != null) {
        fail(result.hits().getError().toString());
    }
    List<String> myRanked = new ArrayList<>(ranked);
    List<String> myUnranked = new ArrayList<>(unranked);
    Stack<Item> stack = new Stack<>();
    stack.push(obj.getModel().getQueryTree().getRoot());
    while (!stack.isEmpty()) {
        Item item = stack.pop();
        if (item instanceof WordItem) {
            String word = ((WordItem) item).getWord();
            if (item.isRanked()) {
                int idx = myRanked.indexOf(word);
                if (idx < 0) {
                    fail("Term '" + word + "' not expected as ranked term.");
                }
                myRanked.remove(idx);
            } else {
                int idx = myUnranked.indexOf(word);
                if (idx < 0) {
                    fail("Term '" + word + "' not expected as unranked term.");
                }
                myUnranked.remove(idx);
            }
        }
        if (item instanceof CompositeItem) {
            CompositeItem lst = (CompositeItem) item;
            for (Iterator<?> it = lst.getItemIterator(); it.hasNext(); ) {
                stack.push((Item) it.next());
            }
        }
    }
    if (!myRanked.isEmpty()) {
        fail("Ranked terms " + myRanked + " not found.");
    }
    if (!myUnranked.isEmpty()) {
        fail("Unranked terms " + myUnranked + " not found.");
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) RecallSearcher(com.yahoo.prelude.querytransform.RecallSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) Stack(java.util.Stack) CompositeItem(com.yahoo.prelude.query.CompositeItem) NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) WordItem(com.yahoo.prelude.query.WordItem) Execution(com.yahoo.search.searchchain.Execution) WordItem(com.yahoo.prelude.query.WordItem)

Example 12 with CompositeItem

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

the class CollapsePhraseSearcherTestCase method testPositive2.

@Test
public void testPositive2() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    CompositeItem embedded = new AndItem();
    embedded.addItem(new WordItem("bcd"));
    CompositeItem phrase = new PhraseItem();
    phrase.addItem(new WordItem("def"));
    embedded.addItem(phrase);
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a (AND bcd def) e", transformQuery(root));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 13 with CompositeItem

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

the class CollapsePhraseSearcherTestCase method testNegative3.

@Test
public void testNegative3() {
    AndItem root = new AndItem();
    root.addItem(new WordItem("a"));
    CompositeItem embedded = new AndItem();
    embedded.addItem(new WordItem("bcd"));
    CompositeItem phrase = new PhraseItem();
    phrase.addItem(new WordItem("def"));
    phrase.addItem(new WordItem("ghi"));
    embedded.addItem(phrase);
    root.addItem(embedded);
    root.addItem(new WordItem("e"));
    assertEquals("AND a (AND bcd \"def ghi\") e", transformQuery(root));
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 14 with CompositeItem

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

the class NonPhrasingSearcherTestCase method testNoNonPhrasingIfNoOtherPhrases.

@Test
public void testNoNonPhrasingIfNoOtherPhrases() {
    searcher = new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query("?query=tudor+vidor");
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertEquals(2, item.getItemCount());
    assertEquals("tudor", ((WordItem) item.getItem(0)).getWord());
    assertEquals("vidor", ((WordItem) item.getItem(1)).getWord());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) NonPhrasingSearcher(com.yahoo.prelude.querytransform.NonPhrasingSearcher) Test(org.junit.Test)

Example 15 with CompositeItem

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

the class NonPhrasingSearcherTestCase method testMultipleWordNonPhrasing.

@Test
public void testMultipleWordNonPhrasing() {
    searcher = new NonPhrasingSearcher("src/test/java/com/yahoo/prelude/querytransform/test/test-fsa.fsa");
    Query query = new Query("?query=void+tudor+vidor+kanoo");
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertEquals(2, item.getItemCount());
    assertEquals("void", ((WordItem) item.getItem(0)).getWord());
    assertEquals("kanoo", ((WordItem) item.getItem(1)).getWord());
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) NonPhrasingSearcher(com.yahoo.prelude.querytransform.NonPhrasingSearcher) Test(org.junit.Test)

Aggregations

CompositeItem (com.yahoo.prelude.query.CompositeItem)25 AndItem (com.yahoo.prelude.query.AndItem)13 Test (org.junit.Test)13 Item (com.yahoo.prelude.query.Item)12 PhraseItem (com.yahoo.prelude.query.PhraseItem)10 WordItem (com.yahoo.prelude.query.WordItem)10 Query (com.yahoo.search.Query)10 Execution (com.yahoo.search.searchchain.Execution)9 NotItem (com.yahoo.prelude.query.NotItem)6 NullItem (com.yahoo.prelude.query.NullItem)6 OrItem (com.yahoo.prelude.query.OrItem)6 EquivItem (com.yahoo.prelude.query.EquivItem)5 NearItem (com.yahoo.prelude.query.NearItem)5 RankItem (com.yahoo.prelude.query.RankItem)5 SimpleIndexedItem (com.yahoo.prelude.query.SimpleIndexedItem)5 SubstringItem (com.yahoo.prelude.query.SubstringItem)5 PhrasingSearcher (com.yahoo.prelude.querytransform.PhrasingSearcher)4 Searcher (com.yahoo.search.Searcher)4 NonPhrasingSearcher (com.yahoo.prelude.querytransform.NonPhrasingSearcher)3 TermItem (com.yahoo.prelude.query.TermItem)2