diff --git a/postings.go b/postings.go index fcbbd4235c..7365099d84 100644 --- a/postings.go +++ b/postings.go @@ -201,30 +201,7 @@ func (it *mergedPostings) Seek(id uint32) bool { it.aok = it.a.Seek(id) it.bok = it.b.Seek(id) - if !it.aok && !it.bok { - return false - } - - if !it.aok { - it.cur = it.b.At() - - return true - } - if !it.bok { - it.cur = it.a.At() - - return true - } - - acur, bcur := it.a.At(), it.b.At() - - if acur < bcur { - it.cur = acur - } else { - it.cur = bcur - } - - return true + return it.Next() } func (it *mergedPostings) Err() error { diff --git a/postings_test.go b/postings_test.go index 62b0dd726b..4801b486e3 100644 --- a/postings_test.go +++ b/postings_test.go @@ -219,9 +219,18 @@ func TestMerge(t *testing.T) { require.Equal(t, c.success, p.Seek(c.seek)) - res, err := expandPostings(p) - require.NoError(t, err) - require.Equal(t, c.res, res) + if c.success { + // check the current element and then proceed to check the rest. + i := 0 + require.Equal(t, c.res[i], p.At()) + + for p.Next() { + i++ + require.Equal(t, int(c.res[i]), int(p.At())) + } + + require.Equal(t, len(c.res)-1, i) + } } return