From 12bd29db809d78978866f5167d4337b8cf8f8f23 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Wed, 28 Sep 2016 08:28:20 -0400 Subject: [PATCH] add unit test for skipping more than number of hits found --- search/collectors/topn_test.go | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/search/collectors/topn_test.go b/search/collectors/topn_test.go index d80ef5af..2cbf9761 100644 --- a/search/collectors/topn_test.go +++ b/search/collectors/topn_test.go @@ -224,6 +224,68 @@ func TestTop10ScoresSkip10(t *testing.T) { } } +func TestTop10ScoresSkip10Only9Hits(t *testing.T) { + + // a stub search with only 10 matches + searcher := &stubSearcher{ + matches: []*search.DocumentMatch{ + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("a"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("c"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("e"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("g"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("i"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("j"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("k"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("m"), + Score: 11, + }, + &search.DocumentMatch{ + IndexInternalID: index.IndexInternalID("n"), + Score: 11, + }, + }, + } + + collector := NewTopNCollector(10, 10, search.SortOrder{&search.SortScore{Desc: true}}) + err := collector.Collect(context.Background(), searcher, &stubReader{}) + if err != nil { + t.Fatal(err) + } + + total := collector.Total() + if total != 9 { + t.Errorf("expected 9 total results, got %d", total) + } + + results := collector.Results() + + if len(results) != 0 { + t.Fatalf("expected 0 results, got %d", len(results)) + } +} + func TestPaginationSameScores(t *testing.T) { // a stub search with more than 10 matches