summaryrefslogtreecommitdiff
path: root/src/result.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/result.go')
-rw-r--r--src/result.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/result.go b/src/result.go
index c4acb5fa..1212cabe 100644
--- a/src/result.go
+++ b/src/result.go
@@ -50,20 +50,21 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
// Higher is better
val = math.MaxUint16 - util.AsUint16(score)
case byChunk:
- b := minBegin
- e := maxEnd
- l := item.text.Length()
- for ; b >= 1; b-- {
- if unicode.IsSpace(item.text.Get(b - 1)) {
- break
+ if validOffsetFound {
+ b := minBegin
+ e := maxEnd
+ for ; b >= 1; b-- {
+ if unicode.IsSpace(item.text.Get(b - 1)) {
+ break
+ }
}
- }
- for ; e < l; e++ {
- if unicode.IsSpace(item.text.Get(e)) {
- break
+ for ; e < numChars; e++ {
+ if unicode.IsSpace(item.text.Get(e)) {
+ break
+ }
}
+ val = util.AsUint16(e - b)
}
- val = util.AsUint16(e - b)
case byLength:
val = item.TrimLength()
case byBegin, byEnd: