change higlight api to store in document match
This commit is contained in:
parent
8ae8718517
commit
238f3af4bd
|
@ -106,6 +106,11 @@ OUTER:
|
|||
formattedFragments[i] = s.sep + s.formatter.Format(fragment, dm.Locations[field]) + s.sep
|
||||
}
|
||||
|
||||
if dm.Fragments == nil {
|
||||
dm.Fragments = make(FieldFragmentMap, 0)
|
||||
}
|
||||
dm.Fragments[field] = formattedFragments
|
||||
|
||||
return formattedFragments
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,28 @@ type Locations []*Location
|
|||
|
||||
type TermLocationMap map[string]Locations
|
||||
|
||||
func (t TermLocationMap) AddLocation(term string, location *Location) {
|
||||
existingLocations, exists := t[term]
|
||||
if exists {
|
||||
existingLocations = append(existingLocations, location)
|
||||
t[term] = existingLocations
|
||||
} else {
|
||||
locations := make(Locations, 1)
|
||||
locations[0] = location
|
||||
t[term] = locations
|
||||
}
|
||||
}
|
||||
|
||||
type FieldTermLocationMap map[string]TermLocationMap
|
||||
|
||||
type FieldFragmentMap map[string][]string
|
||||
|
||||
type DocumentMatch struct {
|
||||
ID string `json:"id"`
|
||||
Score float64 `json:"score"`
|
||||
Expl *Explanation `json:"explanation,omitempty"`
|
||||
Locations FieldTermLocationMap `json:"locations,omitempty"`
|
||||
Fragments FieldFragmentMap `json:"fragments,omitempty"`
|
||||
}
|
||||
|
||||
type DocumentMatchCollection []*DocumentMatch
|
||||
|
|
Loading…
Reference in New Issue