Search in sources :

Example 16 with WordItem

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

the class PhrasingSearcherTestCase method testNoFileNoChange.

@Test
public void testNoFileNoChange() {
    Searcher searcher = new PhrasingSearcher("");
    Query query = new Query();
    AndItem andItem = new AndItem();
    andItem.addItem(new WordItem("no", "anindex"));
    andItem.addItem(new WordItem("such", "anindex"));
    andItem.addItem(new WordItem("phrase", "indexo"));
    OrItem orItem = new OrItem();
    orItem.addItem(new WordItem("habla"));
    orItem.addItem(new WordItem("babla"));
    orItem.addItem(new WordItem("habla"));
    andItem.addItem(orItem);
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertEquals("AND anindex:no anindex:such indexo:phrase (OR habla babla habla)", 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 17 with WordItem

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

the class PhrasingSearcherTestCase method testNoDetection.

@Test
public void testNoDetection() {
    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("no"));
    andItem.addItem(new WordItem("such"));
    andItem.addItem(new WordItem("phrase"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertEquals("AND no such phrase", 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) Test(org.junit.Test)

Example 18 with WordItem

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

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

the class QueryLanguageTestCase method testPhrase.

@Test
public void testPhrase() {
    PhraseItem p = new PhraseItem();
    p.addItem(new WordItem("part"));
    p.addItem(new WordItem("of"));
    p.addItem(new WordItem("phrase"));
    assertEquals("\"part of phrase\"", p.toString());
}
Also used : WordItem(com.yahoo.prelude.query.WordItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) Test(org.junit.Test)

Example 20 with WordItem

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

the class QueryLanguageTestCase method testNotItem.

@Test
public void testNotItem() {
    NotItem n = new NotItem();
    n.addNegativeItem(new WordItem("notthis"));
    n.addNegativeItem(new WordItem("andnotthis"));
    n.addPositiveItem(new WordItem("butthis"));
    assertEquals("+butthis -notthis -andnotthis", n.toString());
}
Also used : NotItem(com.yahoo.prelude.query.NotItem) WordItem(com.yahoo.prelude.query.WordItem) 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