@Test
    void testCollapsingOnMoreFieldsWithManySimilarFieldValues() {
        // Set up
        Map<Searcher, Searcher> chained = new HashMap<>();
        FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(4, 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(createHit("http://acme.org/a.html", 10, 0, 1, 1)); // first hit
        r.hits().add(createHit("http://acme.org/b.html", 9, 0, 1, 2));
        r.hits().add(createHit("http://acme.org/c.html", 9, 0, 6, 2)); // - - 1. search: 1
        r.hits().add(createHit("http://acme.org/d.html", 8, 0, 6, 3));
        r.hits().add(createHit("http://acme.org/e.html", 8, 0, 6, 3));
        r.hits().add(createHit("http://acme.org/f.html", 7, 0, 6, 3)); // - - 1. search: 2
        r.hits().add(createHit("http://acme.org/g.html", 7, 0, 1, 1));
        r.hits().add(createHit("http://acme.org/h.html", 6, 1, 1, 1));
        r.hits().add(createHit("http://acme.org/i.html", 5, 2, 2, 1)); // - - 1. search: 3
        r.hits().add(createHit("http://acme.org/j.html", 4, 3, 3, 2)); // 3rd hit, cmid new
        r.hits().add(createHit("http://acme.org/k.html", 4, 3, 4, 3));
        r.hits().add(createHit("http://acme.org/l.html", 4, 3, 5, 3)); // - - 1. search: 4
        r.hits().add(createHit("http://acme.org/m.html", 4, 4, 6, 3)); // 4th hit, amid new
        r.hits().add(createHit("http://acme.org/n.html", 4, 4, 7, 4));
        r.setTotalHitCount(14);
        docsource.addResult(q, r);

        // Test collapsing
        q = new Query("?query=test_collapse&collapsesize=1&collapsefield=amid,bmid,cmid");
        r = doSearch(collapse, q, 0, 2, chained);

        assertEquals(2, r.getHitCount());
        assertEquals(4, docsource.getQueryCount());
        assertHit("http://acme.org/a.html", 10, 0, 1, 1, r.hits().get(0));
        assertHit("http://acme.org/j.html", 4, 3, 3, 2, r.hits().get(1));

        // Next results
        docsource.resetQueryCount();
        r = doSearch(collapse, q, 2, 2, chained);
        assertEquals(1, r.getHitCount());
        assertEquals(3, docsource.getQueryCount());
        assertHit("http://acme.org/m.html", 4, 4, 6, 3, r.hits().get(0));
    }
Tests that collapsing on multiple fields works if we have to search multiple
time to get enough hits
container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java