Search in sources :

Example 16 with Searcher

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

the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithGrouping.

@Test
public void testFieldCollapsingWithGrouping() {
    // Set up
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    Chain<Searcher> chain = new Chain<>(collapse, new AddAggregationStyleGroupingResultSearcher(), docsource);
    // Caveat: Collapse is set to false, because that's what the
    // collapser asks for
    Query q = new Query("?query=test_collapse&collapsefield=amid");
    // The searcher turns off collapsing further on in the chain
    q.properties().set("collapse", "0");
    Result r = new Result(q);
    r.hits().add(createHit("http://acme.org/a.html", 10, 0));
    r.hits().add(createHit("http://acme.org/b.html", 9, 0));
    r.hits().add(createHit("http://acme.org/c.html", 9, 1));
    r.hits().add(createHit("http://acme.org/d.html", 8, 1));
    r.hits().add(createHit("http://acme.org/e.html", 8, 2));
    r.hits().add(createHit("http://acme.org/f.html", 7, 2));
    r.hits().add(createHit("http://acme.org/g.html", 7, 3));
    r.hits().add(createHit("http://acme.org/h.html", 6, 3));
    r.setTotalHitCount(8);
    docsource.addResult(q, r);
    // Test basic collapsing on mid
    Query query = new Query("?query=test_collapse&collapsefield=amid");
    Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
    // Assert that the regular hits are collapsed
    assertEquals(4 + 1, result.getHitCount());
    assertEquals(1, docsource.getQueryCount());
    assertHit("http://acme.org/a.html", 10, 0, result.hits().get(0));
    assertHit("http://acme.org/c.html", 9, 1, result.hits().get(1));
    assertHit("http://acme.org/e.html", 8, 2, result.hits().get(2));
    assertHit("http://acme.org/g.html", 7, 3, result.hits().get(3));
    // Assert that the aggregation group hierarchy is left intact
    HitGroup root = getFirstGroupIn(result.hits());
    assertNotNull(root);
    // The id ends by a global counter currently
    assertEquals("group:root:", root.getId().stringValue().substring(0, 11));
    assertEquals(1, root.size());
    HitGroup groupList = (GroupList) root.get("grouplist:g1");
    assertNotNull(groupList);
    assertEquals(1, groupList.size());
    HitGroup group = (HitGroup) groupList.get("group:long:37");
    assertNotNull(group);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) GroupList(com.yahoo.search.grouping.result.GroupList) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 17 with Searcher

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

the class JuniperSearcherTestCase method createResult.

private Result createResult(String sdName, String content, boolean bolding) {
    Chain<Searcher> chain = createSearchChain(sdName, content);
    Query query = new Query("?query=12");
    if (!bolding)
        query = new Query("?query=12&bolding=false");
    Execution execution = createExecution(chain);
    Result result = execution.search(query);
    execution.fill(result);
    return result;
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) JuniperSearcher(com.yahoo.prelude.searcher.JuniperSearcher) Result(com.yahoo.search.Result)

Example 18 with Searcher

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

the class QueryValidatingSearcherTestCase method testBasic.

public void testBasic() {
    // Setup
    Map<Searcher, Searcher> chained = new HashMap<>();
    Query query = new Query("?query=test");
    Result result = new Result(query);
    result.hits().add(new Hit("ymail://1111111111/AQAAAP7JgwEAj6XjQQAAAO/+ggA=", 950));
    Searcher validator = new QueryValidatingSearcher();
    DocumentSourceSearcher source = new DocumentSourceSearcher();
    chained.put(validator, source);
    source.addResult(query, result);
    // Exercise
    Result returnedResult = doSearch(validator, query, 0, 10, chained);
    // Validate
    assertEquals(1, returnedResult.getHitCount());
    assertNull(returnedResult.hits().getError());
    returnedResult = doSearch(validator, query, 0, 1001, chained);
    assertEquals(0, returnedResult.getConcreteHitCount());
    assertEquals(4, returnedResult.hits().getError().getCode());
    returnedResult = doSearch(validator, query, 1001, 10, chained);
    assertEquals(0, returnedResult.getConcreteHitCount());
    assertEquals(4, returnedResult.hits().getError().getCode());
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) QueryValidatingSearcher(com.yahoo.prelude.searcher.QueryValidatingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) QueryValidatingSearcher(com.yahoo.prelude.searcher.QueryValidatingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) Result(com.yahoo.search.Result)

Example 19 with Searcher

use of com.yahoo.search.Searcher 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 20 with Searcher

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

the class PhrasingSearcherTestCase method testNoPhrasingIfDifferentIndices.

@Test
public void testNoPhrasingIfDifferentIndices() {
    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", "anotherindex"));
    query.getModel().getQueryTree().setRoot(andItem);
    new Execution(searcher, Execution.Context.createContextStub()).search(query);
    CompositeItem item = (CompositeItem) query.getModel().getQueryTree().getRoot();
    assertTrue(item.getItem(0) instanceof WordItem);
    WordItem word = (WordItem) item.getItem(0);
    assertEquals("tudor", word.getWord());
    assertTrue(item.getItem(1) instanceof WordItem);
    word = (WordItem) item.getItem(1);
    assertEquals("vidor", word.getWord());
}
Also used : 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) Test(org.junit.Test)

Aggregations

Searcher (com.yahoo.search.Searcher)130 Result (com.yahoo.search.Result)94 Execution (com.yahoo.search.searchchain.Execution)88 Query (com.yahoo.search.Query)82 Test (org.junit.Test)74 Chain (com.yahoo.component.chain.Chain)57 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 Hit (com.yahoo.search.result.Hit)17 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)14 HashMap (java.util.HashMap)14 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)11 FieldCollapsingSearcher (com.yahoo.prelude.searcher.FieldCollapsingSearcher)10 ArrayList (java.util.ArrayList)10 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)9 ComponentId (com.yahoo.component.ComponentId)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)8