summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorDmitry Samuylov <dsamuylov@pharo.com>2018-08-28 13:09:32 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2018-08-28 13:09:32 -0400
commit42806ae965b861955235698f247df862fd655d09 (patch)
tree4a92f098976b089dc832f3f0dc5ecfc0392690ed /store
parent61e27beabc9804fdcf59ed9df2180802175a4f70 (diff)
downloadchat-42806ae965b861955235698f247df862fd655d09.tar.gz
chat-42806ae965b861955235698f247df862fd655d09.tar.bz2
chat-42806ae965b861955235698f247df862fd655d09.zip
Feature/search after before on (#9219)
* initial implementation of after, before, on search flags allowing to restrict the search to a specific day or a date range * missed setting beforeDate in SearchParams in one place * fixed condition when only flags are used for search without any plain terms * changed date format used for after/before/on flags to be in ISO8601 format as suggested in PR comments, added a helper function to pad month and day with zeroes allowing the user user either format, with or without leading zeroes * corrected expected compare to date setting for the TestParseDateFilterToTimeISO8601 test * fixed a bug for the scenario when you only have the date flags without any terms, added a couple of tests for that scenario * updated the date filter logic to use parameters to construct the query instead of simply appending strings together, as suggested in the pull request comments * added search unit test using date flags * added a helper function to create a test post with a createat date manually set, updated the test for search using date flags to create test posts with different createat dates to be able to better test the functionality * MM-11817 Add support for after/before/on search flags with Elasticsearch * add support to search posts to perform the search in context of the client's timezone when filtering by createat date using on: after: before: flags * updated tests to match the new signature
Diffstat (limited to 'store')
-rw-r--r--store/sqlstore/post_store.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go
index 90db80796..14a6039bc 100644
--- a/store/sqlstore/post_store.go
+++ b/store/sqlstore/post_store.go
@@ -783,7 +783,7 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
termMap := map[string]bool{}
terms := params.Terms
- if terms == "" && len(params.InChannels) == 0 && len(params.FromUsers) == 0 {
+ if terms == "" && len(params.InChannels) == 0 && len(params.FromUsers) == 0 && len(params.OnDate) == 0 && len(params.AfterDate) == 0 && len(params.BeforeDate) == 0 {
result.Data = []*model.Post{}
return
}
@@ -829,6 +829,7 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
AND UserId = :UserId
` + deletedQueryPart + `
CHANNEL_FILTER)
+ CREATEDATE_CLAUSE
SEARCH_CLAUSE
ORDER BY CreateAt DESC
LIMIT 100`
@@ -889,6 +890,41 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
searchQuery = strings.Replace(searchQuery, "POST_FILTER", "", 1)
}
+ // handle after: before: on: filters
+ if len(params.AfterDate) > 1 || len(params.BeforeDate) > 1 || len(params.OnDate) > 1 {
+ if len(params.OnDate) > 1 {
+ onDateStart, onDateEnd := params.GetOnDateMillis()
+ queryParams["OnDateStart"] = strconv.FormatInt(onDateStart, 10)
+ queryParams["OnDateEnd"] = strconv.FormatInt(onDateEnd, 10)
+
+ // between `on date` start of day and end of day
+ searchQuery = strings.Replace(searchQuery, "CREATEDATE_CLAUSE", "AND CreateAt BETWEEN :OnDateStart AND :OnDateEnd ", 1)
+ } else if len(params.AfterDate) > 1 && len(params.BeforeDate) > 1 {
+ afterDate := params.GetAfterDateMillis()
+ beforeDate := params.GetBeforeDateMillis()
+ queryParams["OnDateStart"] = strconv.FormatInt(afterDate, 10)
+ queryParams["OnDateEnd"] = strconv.FormatInt(beforeDate, 10)
+
+ // between clause
+ searchQuery = strings.Replace(searchQuery, "CREATEDATE_CLAUSE", "AND CreateAt BETWEEN :OnDateStart AND :OnDateEnd ", 1)
+ } else if len(params.AfterDate) > 1 {
+ afterDate := params.GetAfterDateMillis()
+ queryParams["AfterDate"] = strconv.FormatInt(afterDate, 10)
+
+ // greater than `after date`
+ searchQuery = strings.Replace(searchQuery, "CREATEDATE_CLAUSE", "AND CreateAt >= :AfterDate ", 1)
+ } else if len(params.BeforeDate) > 1 {
+ beforeDate := params.GetBeforeDateMillis()
+ queryParams["BeforeDate"] = strconv.FormatInt(beforeDate, 10)
+
+ // less than `before date`
+ searchQuery = strings.Replace(searchQuery, "CREATEDATE_CLAUSE", "AND CreateAt <= :BeforeDate ", 1)
+ }
+ } else {
+ // no create date filters set
+ searchQuery = strings.Replace(searchQuery, "CREATEDATE_CLAUSE", "", 1)
+ }
+
if terms == "" {
// we've already confirmed that we have a channel or user to search for
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)