Search in sources :

Example 6 with FieldCollapsingSearcher

use of com.yahoo.prelude.searcher.FieldCollapsingSearcher 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 7 with FieldCollapsingSearcher

use of com.yahoo.prelude.searcher.FieldCollapsingSearcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testNoCollapsingIfNotAskedTo.

@Test
public void testNoCollapsingIfNotAskedTo() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher();
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(collapse, docsource);
    Query q = new Query("?query=test_collapse");
    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 that no collapsing occured
    q = new Query("?query=test_collapse");
    r = doSearch(collapse, q, 0, 10, chained);
    assertEquals(8, r.getHitCount());
    assertEquals(1, docsource.getQueryCount());
}
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 8 with FieldCollapsingSearcher

use of com.yahoo.prelude.searcher.FieldCollapsingSearcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testCollapsingDispersedCollection.

/**
 * Tests collapsing of "messy" data
 */
@Test
public void testCollapsingDispersedCollection() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(1, 2.0, "amid");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(collapse, docsource);
    Query q = new Query("?query=test_collapse&collapse=true&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, 1));
    r.hits().add(createHit("http://acme.org/b.html", 10, 1));
    r.hits().add(createHit("http://acme.org/c.html", 10, 0));
    r.hits().add(createHit("http://acme.org/d.html", 10, 0));
    r.hits().add(createHit("http://acme.org/e.html", 10, 0));
    r.hits().add(createHit("http://acme.org/f.html", 10, 0));
    r.hits().add(createHit("http://acme.org/g.html", 10, 0));
    r.hits().add(createHit("http://acme.org/h.html", 10, 0));
    r.hits().add(createHit("http://acme.org/i.html", 10, 0));
    r.hits().add(createHit("http://acme.org/j.html", 10, 1));
    r.setTotalHitCount(10);
    docsource.addResult(q, r);
    // Test collapsing
    q = new Query("?query=test_collapse&collapse=true&collapsefield=amid");
    r = doSearch(collapse, q, 0, 3, chained);
    assertEquals(2, r.getHitCount());
    assertHit("http://acme.org/a.html", 10, 1, r.hits().get(0));
    assertHit("http://acme.org/c.html", 10, 0, r.hits().get(1));
}
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 9 with FieldCollapsingSearcher

use of com.yahoo.prelude.searcher.FieldCollapsingSearcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithoutHits.

@Test
public void testFieldCollapsingWithoutHits() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
    ZeroHitsControl checker = new ZeroHitsControl();
    chained.put(collapse, checker);
    Query q = new Query("?query=test_collapse&collapsefield=amid");
    Result r = doSearch(collapse, q, 0, 0, chained);
    assertEquals(0, r.getHitCount());
    assertNull(r.hits().getError());
    assertEquals(1, checker.queryCount);
}
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) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 10 with FieldCollapsingSearcher

use of com.yahoo.prelude.searcher.FieldCollapsingSearcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testCollapsingLargeCollection.

/**
 * Tests that collapsing many hits from one site works, and without
 * an excessive number of backend requests
 */
@Test
public void testCollapsingLargeCollection() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(4, 2.0, "amid");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(collapse, docsource);
    Query q = new Query("?query=test_collapse&collapsesize=1&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, 0));
    r.hits().add(createHit("http://acme.org/d.html", 8, 0));
    r.hits().add(createHit("http://acme.org/e.html", 8, 0));
    r.hits().add(createHit("http://acme.org/f.html", 7, 0));
    r.hits().add(createHit("http://acme.org/g.html", 7, 0));
    r.hits().add(createHit("http://acme.org/h.html", 6, 0));
    r.hits().add(createHit("http://acme.org/i.html", 5, 1));
    r.hits().add(createHit("http://acme.org/j.html", 4, 2));
    r.setTotalHitCount(10);
    docsource.addResult(q, r);
    // Test collapsing
    q = new Query("?query=test_collapse&collapsesize=1&collapsefield=amid");
    r = doSearch(collapse, q, 0, 2, chained);
    assertEquals(2, r.getHitCount());
    assertEquals(2, docsource.getQueryCount());
    assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0));
    assertHit("http://acme.org/i.html", 5, 1, r.hits().get(1));
    // Next results
    docsource.resetQueryCount();
    r = doSearch(collapse, q, 2, 2, chained);
    assertEquals(1, r.getHitCount());
    assertEquals(2, docsource.getQueryCount());
    assertHit("http://acme.org/j.html", 4, 2, r.hits().get(0));
}
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)

Aggregations

FieldCollapsingSearcher (com.yahoo.prelude.searcher.FieldCollapsingSearcher)10 Query (com.yahoo.search.Query)10 Result (com.yahoo.search.Result)10 Searcher (com.yahoo.search.Searcher)10 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 Chain (com.yahoo.component.chain.Chain)1 GroupList (com.yahoo.search.grouping.result.GroupList)1 HitGroup (com.yahoo.search.result.HitGroup)1 Execution (com.yahoo.search.searchchain.Execution)1