@Test
    void testFieldCollapsingTwoPhase() {
        Map<Searcher, Searcher> chained = new HashMap<>();

        // Set up
        FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(1, 1.0);
        DocumentSourceSearcher docsource = new DocumentSourceSearcher();
        chained.put(collapse, docsource);

        Query q = new Query("?query=test_collapse");
        Result r = new Result(q);
        r.hits().add(createHitAmid("http://acme.org/a.html", 10, 0));
        r.hits().add(createHitAmid("http://acme.org/b.html", 9, 0));
        r.hits().add(createHitAmid("http://acme.org/c.html", 9, 1));
        r.hits().add(createHitAmid("http://acme.org/d.html", 8, 1));
        r.hits().add(createHitAmid("http://acme.org/e.html", 8, 2));
        r.hits().add(createHitAmid("http://acme.org/f.html", 7, 2));
        r.hits().add(createHitAmid("http://acme.org/g.html", 7, 3));
        r.hits().add(createHitAmid("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, 4, chained);

        assertEquals(4, r.getHitCount());
        assertEquals(2, docsource.getQueryCount());
        assertHitAmid("http://acme.org/a.html", 10, 0, r.hits().get(0));
        assertHitAmid("http://acme.org/c.html", 9, 1, r.hits().get(1));
        assertHitAmid("http://acme.org/e.html", 8, 2, r.hits().get(2));
        assertHitAmid("http://acme.org/g.html", 7, 3, r.hits().get(3));
    }
Test that collapsing works if multiple searches are necessary.
container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java