From 2e3dc75425d23b4d9e8e05a901395914cf8d3120 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 2 Jun 2017 13:25:35 +0900 Subject: Fix inconsistent tiebreak scores when --nth is used Make sure to consistently calculate tiebreak scores based on the original line. This change may not be preferable if you filter aligned tabular input on a subset of columns using --nth. However, if we calculate length tiebreak only on the matched components instead of the entire line, the result can be very confusing when multiple --nth components are specified, so let's keep it simple and consistent. Close #926 --- src/result.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/result.go') diff --git a/src/result.go b/src/result.go index e071a9ee..0b1fbf0d 100644 --- a/src/result.go +++ b/src/result.go @@ -29,7 +29,7 @@ type Result struct { rank rank } -func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result { +func buildResult(item *Item, offsets []Offset, score int) *Result { if len(offsets) > 1 { sort.Sort(ByOrder(offsets)) } @@ -57,8 +57,7 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result { // Higher is better val = math.MaxUint16 - util.AsUint16(score) case byLength: - // If offsets is empty, trimLen will be 0, but we don't care - val = util.AsUint16(trimLen) + val = util.AsUint16(int(item.TrimLength())) case byBegin, byEnd: if validOffsetFound { whitePrefixLen := 0 @@ -72,7 +71,7 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result { if criterion == byBegin { val = util.AsUint16(minEnd - whitePrefixLen) } else { - val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/trimLen) + val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/int(item.TrimLength())) } } } -- cgit v1.2.3