fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

eval: prefer longer candidateMatch when removing overlaps (#727)

When thinking about transforming queries like 'foo bar' into '(foo bar)
or "foo bar"' we would want to keep the phrase candidateMatch and not
throw it away in gatherMatches. By sorting longer matches before others
that start at the same offset we end up keeping those.

Note: this only affects ChunkMatch, since for LineMatch we merge when we
find overlaps.

Test Plan: This was quite hard to test with our existing e2e tests due
to them not recording offsets, only matching lines. So instead I am just
relying on the fact we didn't break anything and once we add proper
support for phrases we will have a test then.

+4
+4
eval.go
··· 537 537 func (m sortByOffsetSlice) Len() int { return len(m) } 538 538 func (m sortByOffsetSlice) Swap(i, j int) { m[i], m[j] = m[j], m[i] } 539 539 func (m sortByOffsetSlice) Less(i, j int) bool { 540 + if m[i].byteOffset == m[j].byteOffset { // tie break if same offset 541 + // Prefer longer candidates if starting at same position 542 + return m[i].byteMatchSz > m[j].byteMatchSz 543 + } 540 544 return m[i].byteOffset < m[j].byteOffset 541 545 } 542 546