summaryrefslogtreecommitdiffstats
path: root/src/result.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-06-02 13:25:35 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-06-02 13:25:35 +0900
commit2e3dc75425d23b4d9e8e05a901395914cf8d3120 (patch)
treebaccbb0305c7337b95207945c55d5e33f726c55b /src/result.go
parent5d6eb5bfd64c6d5d773c71159d819b651dd5f7f1 (diff)
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
Diffstat (limited to 'src/result.go')
-rw-r--r--src/result.go7
1 files changed, 3 insertions, 4 deletions
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()))
}
}
}