Search in sources :

Example 81 with Query

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

the class FieldCollapsingSearcherTestCase method testFieldCollapsing.

@Test
public void testFieldCollapsing() {
    Map<Searcher, Searcher> chained = new HashMap<>();
    // Set up
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(collapse, 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
    q = new Query("?query=test_collapse&collapsefield=amid");
    r = doSearch(collapse, q, 0, 10, chained);
    assertEquals(4, r.getHitCount());
    assertEquals(1, docsource.getQueryCount());
    assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0));
    assertHit("http://acme.org/c.html", 9, 1, r.hits().get(1));
    assertHit("http://acme.org/e.html", 8, 2, r.hits().get(2));
    assertHit("http://acme.org/g.html", 7, 3, r.hits().get(3));
}
Also used : Query(com.yahoo.search.Query) HashMap(java.util.HashMap) 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) Test(org.junit.Test)

Example 82 with Query

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

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

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

the class JuniperSearcherTestCase method createSearchChain.

/**
 * Creates a search chain which always returns a result with one hit containing information given in this
 *
 * @param sdName the search definition type of the returned hit
 * @param content the content of the "dynteaser" field of the returned hit
 */
private Chain<Searcher> createSearchChain(String sdName, String content) {
    JuniperSearcher searcher = new JuniperSearcher(new ComponentId("test"), new QrSearchersConfig(new QrSearchersConfig.Builder()));
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    addResult(new Query("?query=12"), sdName, content, docsource);
    addResult(new Query("?query=12&bolding=false"), sdName, content, docsource);
    return new Chain<Searcher>(searcher, docsource);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) QrSearchersConfig(com.yahoo.container.QrSearchersConfig) JuniperSearcher(com.yahoo.prelude.searcher.JuniperSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) ComponentId(com.yahoo.component.ComponentId)

Example 85 with Query

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

the class PosSearcherTestCase method testNotOverridingOldStyleParameters.

@Test
public void testNotOverridingOldStyleParameters() {
    PosSearcher searcher = new PosSearcher();
    Query q = new Query("?query=test&pos.ll=N10.15;E6.08&location=(2,-1100222,0,300,0,1,0,CalcLatLon)");
    q.setTraceLevel(1);
    doSearch(searcher, q, 0, 10);
    assertEquals("(2,-1100222,0,300,0,1,0,4294967295)", q.getRanking().getLocation().toString());
}
Also used : Query(com.yahoo.search.Query) PosSearcher(com.yahoo.prelude.searcher.PosSearcher) 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