0
0

change default fragment size to 200, also behavior if no matches

now if there are no matches, but you requested highlight for the
field we return a single fragment containing the first <fragsize>
bytes.  this works well for cases where you want to display a
field highlighted, but still show it even if there were no
matches in that same field
This commit is contained in:
Marty Schoch 2014-08-28 14:46:30 -04:00
parent c9423aa24b
commit 949accc3e4

View File

@ -10,7 +10,7 @@ package search
import ()
const DEFAULT_FRAGMENT_SIZE = 100
const DEFAULT_FRAGMENT_SIZE = 200
type SimpleFragmenter struct {
fragmentSize int
@ -71,6 +71,16 @@ func (s *SimpleFragmenter) Fragment(orig []byte, ot termLocations) []*Fragment {
maxbegin = termLocation.End
}
if len(ot) == 0 {
// if there were no terms to highlight
// produce a single fragment from the beginning
start := 0
end := start + s.fragmentSize
if end > len(orig) {
end = len(orig)
}
rv = append(rv, &Fragment{orig: orig, start: start, end: end})
}
return rv
}