Search in sources :

Example 96 with Query

use of com.yahoo.search.Query 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 97 with Query

use of com.yahoo.search.Query 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 98 with Query

use of com.yahoo.search.Query 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 99 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class RecallSearcherTestCase method testDenyRankItems.

@Test
public void testDenyRankItems() {
    RecallSearcher searcher = new RecallSearcher();
    Query query = new Query("?recall=foo");
    Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
    assertNotNull(result.hits().getError());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) RecallSearcher(com.yahoo.prelude.querytransform.RecallSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 100 with Query

use of com.yahoo.search.Query in project vespa by vespa-engine.

the class RecallSearcherTestCase method testIgnoreEmptyProperty.

@Test
public void testIgnoreEmptyProperty() {
    RecallSearcher searcher = new RecallSearcher();
    Query query = new Query();
    Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
    assertNull(result.hits().getError());
    assertTrue(query.getModel().getQueryTree().getRoot() instanceof NullItem);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) RecallSearcher(com.yahoo.prelude.querytransform.RecallSearcher) NullItem(com.yahoo.prelude.query.NullItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

Query (com.yahoo.search.Query)689 Test (org.junit.Test)415 Result (com.yahoo.search.Result)229 Execution (com.yahoo.search.searchchain.Execution)184 Searcher (com.yahoo.search.Searcher)82 QueryProfile (com.yahoo.search.query.profile.QueryProfile)63 Hit (com.yahoo.search.result.Hit)52 Chain (com.yahoo.component.chain.Chain)47 IndexFacts (com.yahoo.prelude.IndexFacts)44 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)37 AndItem (com.yahoo.prelude.query.AndItem)33 WordItem (com.yahoo.prelude.query.WordItem)33 FastHit (com.yahoo.prelude.fastsearch.FastHit)31 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)27 HitGroup (com.yahoo.search.result.HitGroup)24 Item (com.yahoo.prelude.query.Item)21 HashMap (java.util.HashMap)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)18 ArrayList (java.util.ArrayList)18