summaryrefslogtreecommitdiffstats
path: root/model/post_search_results.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2018-06-19 05:46:29 -0400
committerCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-06-19 11:46:29 +0200
commit226d4b2ac8888646271b9e9e83a513cd6e62d620 (patch)
treeb79a3eff5768f4b9f589b78a7e18324a53cf8e5b /model/post_search_results.go
parent6d8140337ef0f68f5177988f3c87bba5e4946399 (diff)
downloadchat-226d4b2ac8888646271b9e9e83a513cd6e62d620.tar.gz
chat-226d4b2ac8888646271b9e9e83a513cd6e62d620.tar.bz2
chat-226d4b2ac8888646271b9e9e83a513cd6e62d620.zip
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
Diffstat (limited to 'model/post_search_results.go')
-rw-r--r--model/post_search_results.go40
1 files changed, 40 insertions, 0 deletions
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(&copy)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func PostSearchResultsFromJson(data io.Reader) *PostSearchResults {
+ var o *PostSearchResults
+ json.NewDecoder(data).Decode(&o)
+ return o
+}