@Test
    void testCollapsingWithMultipleFields() {
        // 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, 1, 0));
        r.hits().add(createHit("http://acme.org/b.html", 9, 1, 1));
        r.hits().add(createHit("http://acme.org/c.html", 8, 0, 1));
        r.hits().add(createHit("http://acme.org/d.html", 7, 1, 0));
        r.setTotalHitCount(4);
        docsource.addResult(q, r);

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

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

        docsource.resetQueryCount();

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

        assertEquals(1, r.getHitCount());
        assertEquals(1, docsource.getQueryCount());
        assertHit("http://acme.org/a.html", 10, 1, 0, r.hits().get(0));
    }
Tests that collapsing hits with 2 fields works,
this test also shows that field order is important
container-search/src/test/java/com/yahoo/prelude/searcher/test/FieldCollapsingSearcherTestCase.java