0
0
Fork 0

change higlight api to store in document match

This commit is contained in:
Marty Schoch 2014-07-03 14:53:44 -04:00
parent 8ae8718517
commit 238f3af4bd
2 changed files with 20 additions and 0 deletions

View File

@ -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
}

View File

@ -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