選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

fragment_scorer_simple.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 simple
  15. import (
  16. "github.com/blevesearch/bleve/search"
  17. "github.com/blevesearch/bleve/search/highlight"
  18. )
  19. // FragmentScorer will score fragments by how many
  20. // unique terms occur in the fragment with no regard for
  21. // any boost values used in the original query
  22. type FragmentScorer struct {
  23. tlm search.TermLocationMap
  24. }
  25. func NewFragmentScorer(tlm search.TermLocationMap) *FragmentScorer {
  26. return &FragmentScorer{
  27. tlm: tlm,
  28. }
  29. }
  30. func (s *FragmentScorer) Score(f *highlight.Fragment) {
  31. score := 0.0
  32. OUTER:
  33. for _, locations := range s.tlm {
  34. for _, location := range locations {
  35. if location.ArrayPositions.Equals(f.ArrayPositions) && int(location.Start) >= f.Start && int(location.End) <= f.End {
  36. score += 1.0
  37. // once we find a term in the fragment
  38. // don't care about additional matches
  39. continue OUTER
  40. }
  41. }
  42. }
  43. f.Score = score
  44. }