summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-03-21 07:31:05 -0400
committerChristopher Speller <crspeller@gmail.com>2016-03-21 07:31:05 -0400
commit85837efe06a93b38e449c750108a4105cc629611 (patch)
treec20f4c8c076c395a22cc8a439b3a294401d5f09f /store
parent6f747b8b18d8a542ddbe353d6fa11a474bdbcae5 (diff)
parent8326025d5bcb85e5dda40f375561c975e17ceba6 (diff)
downloadchat-85837efe06a93b38e449c750108a4105cc629611.tar.gz
chat-85837efe06a93b38e449c750108a4105cc629611.tar.bz2
chat-85837efe06a93b38e449c750108a4105cc629611.zip
Merge pull request #2475 from mattermost/plt-1606
PLT-1606/PLT-714 Change searches to AND terms instead of OR
Diffstat (limited to 'store')
-rw-r--r--store/sql_post_store.go9
-rw-r--r--store/sql_post_store_test.go9
2 files changed, 15 insertions, 3 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 3346534ab..68c22f7f6 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -726,13 +726,20 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
terms = wildcard.ReplaceAllLiteralString(terms, ":* ")
}
- terms = strings.Join(strings.Fields(terms), " | ")
+ terms = strings.Join(strings.Fields(terms), " & ")
searchClause := fmt.Sprintf("AND %s @@ to_tsquery(:Terms)", searchType)
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
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
+ }
+
+ terms = strings.Join(splitTerms, " ")
}
queryParams["Terms"] = terms
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index d69f7906c..62db6efb5 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -744,12 +744,17 @@ func TestPostStoreSearch(t *testing.T) {
}
r9 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "mattermost jersey", IsHashtag: false})).Data.(*model.PostList)
- if len(r9.Order) != 2 {
+ if len(r9.Order) != 0 {
+ t.Fatal("returned wrong search result")
+ }
+
+ r9a := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "corey new york", IsHashtag: false})).Data.(*model.PostList)
+ if len(r9a.Order) != 1 {
t.Fatal("returned wrong search result")
}
r10 := (<-store.Post().Search(teamId, userId, &model.SearchParams{Terms: "matter* jer*", IsHashtag: false})).Data.(*model.PostList)
- if len(r10.Order) != 2 {
+ if len(r10.Order) != 0 {
t.Fatal("returned wrong search result")
}