diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-09-26 07:27:04 -0700 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2018-09-26 10:27:04 -0400 |
commit | 37e00ef916af9a5aeae760a01fa0a0cf8ca93637 (patch) | |
tree | 280c92b115a4614ee74ed4bb0efcaefe9cc8454f /api4/post.go | |
parent | bfec808e53772fc79860412cd11c77ca1629739f (diff) | |
download | chat-37e00ef916af9a5aeae760a01fa0a0cf8ca93637.tar.gz chat-37e00ef916af9a5aeae760a01fa0a0cf8ca93637.tar.bz2 chat-37e00ef916af9a5aeae760a01fa0a0cf8ca93637.zip |
Adding paging to elasticsearch API. (#9425)
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/api4/post.go b/api4/post.go index 46c688014..6500cba32 100644 --- a/api4/post.go +++ b/api4/post.go @@ -330,26 +330,42 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { return } - includeDeletedChannels := r.URL.Query().Get("include_deleted_channels") == "true" + params := model.SearchParameterFromJson(r.Body) - props := model.StringInterfaceFromJson(r.Body) - - terms, ok := props["terms"].(string) - if !ok || len(terms) == 0 { + if params.Terms == nil || len(*params.Terms) == 0 { c.SetInvalidParam("terms") return } + terms := *params.Terms + + timeZoneOffset := 0 + if params.TimeZoneOffset != nil { + timeZoneOffset = *params.TimeZoneOffset + } + + isOrSearch := false + if params.IsOrSearch != nil { + isOrSearch = *params.IsOrSearch + } + + page := 0 + if params.Page != nil { + page = *params.Page + } - timeZoneOffset, ok := props["time_zone_offset"].(float64) - if !ok { - timeZoneOffset = 0 + perPage := 60 + if params.PerPage != nil { + perPage = *params.PerPage } - isOrSearch, _ := props["is_or_search"].(bool) + includeDeletedChannels := false + if params.IncludeDeletedChannels != nil { + includeDeletedChannels = *params.IncludeDeletedChannels + } startTime := time.Now() - results, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch, includeDeletedChannels, int(timeZoneOffset)) + results, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch, includeDeletedChannels, int(timeZoneOffset), page, perPage) elapsedTime := float64(time.Since(startTime)) / float64(time.Second) metrics := c.App.Metrics |