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.

42 lines
1.3 KiB

  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 search
  15. func MergeLocations(locations []FieldTermLocationMap) FieldTermLocationMap {
  16. rv := locations[0]
  17. for i := 1; i < len(locations); i++ {
  18. nextLocations := locations[i]
  19. for field, termLocationMap := range nextLocations {
  20. rvTermLocationMap, rvHasField := rv[field]
  21. if rvHasField {
  22. rv[field] = MergeTermLocationMaps(rvTermLocationMap, termLocationMap)
  23. } else {
  24. rv[field] = termLocationMap
  25. }
  26. }
  27. }
  28. return rv
  29. }
  30. func MergeTermLocationMaps(rv, other TermLocationMap) TermLocationMap {
  31. for term, locationMap := range other {
  32. // for a given term/document there cannot be different locations
  33. // if they came back from different clauses, overwrite is ok
  34. rv[term] = locationMap
  35. }
  36. return rv
  37. }