summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-05-09 12:00:08 -0400
committerCorey Hulen <corey@hulen.com>2016-05-09 09:00:08 -0700
commit07126101d379b900724c7c5cfc82070b42c235d6 (patch)
tree80b2485b61eb1684cd6127473267af206c3ab1c2 /store
parent9e07f4b021b28a3e301359a48cf950298f3e552e (diff)
downloadchat-07126101d379b900724c7c5cfc82070b42c235d6.tar.gz
chat-07126101d379b900724c7c5cfc82070b42c235d6.tar.bz2
chat-07126101d379b900724c7c5cfc82070b42c235d6.zip
Recent mention searches now OR terms instead of AND (#2931)
Diffstat (limited to 'store')
-rw-r--r--store/sql_post_store.go18
-rw-r--r--store/sql_post_store_test.go5
2 files changed, 17 insertions, 6 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 54b526191..d7d009ce4 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -725,7 +725,11 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
terms = wildcard.ReplaceAllLiteralString(terms, ":* ")
}
- terms = strings.Join(strings.Fields(terms), " & ")
+ if params.OrTerms {
+ terms = strings.Join(strings.Fields(terms), " | ")
+ } else {
+ terms = strings.Join(strings.Fields(terms), " & ")
+ }
searchClause := fmt.Sprintf("AND %s @@ to_tsquery(:Terms)", searchType)
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
@@ -733,12 +737,14 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
searchClause := fmt.Sprintf("AND MATCH (%s) AGAINST (:Terms IN BOOLEAN MODE)", searchType)
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
- splitTerms := strings.Fields(terms)
- for i, t := range strings.Fields(terms) {
- splitTerms[i] = "+" + t
- }
+ if !params.OrTerms {
+ splitTerms := strings.Fields(terms)
+ for i, t := range strings.Fields(terms) {
+ splitTerms[i] = "+" + t
+ }
- terms = strings.Join(splitTerms, " ")
+ terms = strings.Join(splitTerms, " ")
+ }
}
queryParams["Terms"] = terms
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index 62db6efb5..3c317b926 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -767,6 +767,11 @@ func TestPostStoreSearch(t *testing.T) {
if len(r12.Order) != 1 {
t.Fatal("returned wrong search result")
}
+
+ r13 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "Jersey corey", IsHashtag: false, OrTerms: true})).Data.(*model.PostList)
+ if len(r13.Order) != 2 {
+ t.Fatal("returned wrong search result")
+ }
}
func TestUserCountsWithPostsByDay(t *testing.T) {