Skip to content

Commit

Permalink
#12 Add Highlights as a structured interface in SearchResult instead …
Browse files Browse the repository at this point in the history
…of a simple string to be able to return Fragments from different fields
  • Loading branch information
Estelle Maudet committed Oct 22, 2018
1 parent 9e045ba commit 8791d8e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/fulltext/search/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type QueryRequest struct {
}

type SearchResult struct {
id string `json:"_id"`
docType string `json:"docType"`
rev string `json:"_rev"`
Name string `json:"name"`
Highlight string `json:"highlight"`
id string `json:"_id"`
docType string `json:"docType"`
rev string `json:"_rev"`
Name string `json:"name"`
Highlight map[string][]string `json:"highlight"`
}

func (r *SearchResult) Rev() string { return r.rev }
Expand Down Expand Up @@ -183,10 +183,10 @@ func BuildQuery(request QueryRequest, prefix bool) *bleve.SearchRequest {
func BuildResults(request QueryRequest, searchResults *bleve.SearchResult) []SearchResult {
fetched := make([]SearchResult, len(searchResults.Hits))
for i, result := range searchResults.Hits {
currFetched := SearchResult{result.ID, (result.Fields["docType"]).(string), "", "", ""}
currFetched := SearchResult{result.ID, (result.Fields["docType"]).(string), "", "", nil}

if request.Highlight {
currFetched.Highlight = result.Fragments["name"][0] //TODO deal with Fragments better, what if not on name field ?
currFetched.Highlight = result.Fragments
}
if request.Name {
currFetched.Name = result.Fields["name"].(string)
Expand Down

0 comments on commit 8791d8e

Please sign in to comment.