From 226d4b2ac8888646271b9e9e83a513cd6e62d620 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 19 Jun 2018 05:46:29 -0400 Subject: MM-6992 Added highlighting to elasticsearch results (#8861) * MM-6992 Added highlighting to elasticsearch results * Added a unique type for post search matches * Fixed Elasticsearch matches not being sent through API --- model/post_search_results.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 model/post_search_results.go (limited to 'model/post_search_results.go') diff --git a/model/post_search_results.go b/model/post_search_results.go new file mode 100644 index 000000000..2317f1831 --- /dev/null +++ b/model/post_search_results.go @@ -0,0 +1,40 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +type PostSearchMatches map[string][]string + +type PostSearchResults struct { + *PostList + Matches PostSearchMatches `json:"matches"` +} + +func MakePostSearchResults(posts *PostList, matches PostSearchMatches) *PostSearchResults { + return &PostSearchResults{ + posts, + matches, + } +} + +func (o *PostSearchResults) ToJson() string { + copy := *o + copy.PostList.StripActionIntegrations() + b, err := json.Marshal(©) + if err != nil { + return "" + } else { + return string(b) + } +} + +func PostSearchResultsFromJson(data io.Reader) *PostSearchResults { + var o *PostSearchResults + json.NewDecoder(data).Decode(&o) + return o +} -- cgit v1.2.3-1-g7c22