本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7KB

  1. // Copyright (c) 2014 Couchbase, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package highlight
  15. import (
  16. "github.com/blevesearch/bleve/document"
  17. "github.com/blevesearch/bleve/search"
  18. )
  19. type Fragment struct {
  20. Orig []byte
  21. ArrayPositions []uint64
  22. Start int
  23. End int
  24. Score float64
  25. Index int // used by heap
  26. }
  27. func (f *Fragment) Overlaps(other *Fragment) bool {
  28. if other.Start >= f.Start && other.Start < f.End {
  29. return true
  30. } else if f.Start >= other.Start && f.Start < other.End {
  31. return true
  32. }
  33. return false
  34. }
  35. type Fragmenter interface {
  36. Fragment([]byte, TermLocations) []*Fragment
  37. }
  38. type FragmentFormatter interface {
  39. Format(f *Fragment, orderedTermLocations TermLocations) string
  40. }
  41. type FragmentScorer interface {
  42. Score(f *Fragment) float64
  43. }
  44. type Highlighter interface {
  45. Fragmenter() Fragmenter
  46. SetFragmenter(Fragmenter)
  47. FragmentFormatter() FragmentFormatter
  48. SetFragmentFormatter(FragmentFormatter)
  49. Separator() string
  50. SetSeparator(string)
  51. BestFragmentInField(*search.DocumentMatch, *document.Document, string) string
  52. BestFragmentsInField(*search.DocumentMatch, *document.Document, string, int) []string
  53. }
上海开阖软件有限公司 沪ICP备12045867号-1