Search in sources :

Example 16 with Item

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

the class ParseTestCase method testPlusWordWebParsing2.

@Test
public void testPlusWordWebParsing2() {
    Item root = tester.assertParsed("AND a b", "+a +b", Query.Type.WEB);
    assertTrue(((AndItem) root).getItem(0).isProtected());
    assertTrue(((AndItem) root).getItem(1).isProtected());
}
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) AndItem(com.yahoo.prelude.query.AndItem) Test(org.junit.Test)

Example 17 with Item

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

the class ParseTestCase method testFakeCJKSegmenting.

@Test
public void testFakeCJKSegmenting() {
    // "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 18 with Item

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

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

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

the class CollapsePhraseSearcherTestCase method transformQuery.

private String transformQuery(String rawQuery) {
    CollapsePhraseSearcher searcher = new CollapsePhraseSearcher();
    Query query = new Query(rawQuery);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    Item newRoot = query.getModel().getQueryTree().getRoot();
    if (newRoot != null)
        return newRoot.toString();
    else
        return null;
}
Also used : PhraseItem(com.yahoo.prelude.query.PhraseItem) CompositeItem(com.yahoo.prelude.query.CompositeItem) Item(com.yahoo.prelude.query.Item) AndItem(com.yahoo.prelude.query.AndItem) WordItem(com.yahoo.prelude.query.WordItem) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) CollapsePhraseSearcher(com.yahoo.prelude.querytransform.CollapsePhraseSearcher)

Aggregations

Item (com.yahoo.prelude.query.Item)116 AndItem (com.yahoo.prelude.query.AndItem)85 CompositeItem (com.yahoo.prelude.query.CompositeItem)82 WordItem (com.yahoo.prelude.query.WordItem)73 PhraseItem (com.yahoo.prelude.query.PhraseItem)66 NotItem (com.yahoo.prelude.query.NotItem)62 RankItem (com.yahoo.prelude.query.RankItem)60 SubstringItem (com.yahoo.prelude.query.SubstringItem)60 Test (org.junit.Test)58 OrItem (com.yahoo.prelude.query.OrItem)57 PrefixItem (com.yahoo.prelude.query.PrefixItem)53 SuffixItem (com.yahoo.prelude.query.SuffixItem)53 IntItem (com.yahoo.prelude.query.IntItem)52 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)51 NullItem (com.yahoo.prelude.query.NullItem)24 Query (com.yahoo.search.Query)22 EquivItem (com.yahoo.prelude.query.EquivItem)14 NearItem (com.yahoo.prelude.query.NearItem)14 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)12 IndexedItem (com.yahoo.prelude.query.IndexedItem)12