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:
parent
c9423aa24b
commit
949accc3e4
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user