Recent mention searches now OR terms instead of AND (#2931)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
9e07f4b021
Коммит
07126101d3
@@ -30,7 +30,7 @@ func TestMsgCommands(t *testing.T) {
|
|||||||
if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user3.Id) && !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user3.Id+"__"+user1.Id) {
|
if !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user3.Id) && !strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user3.Id+"__"+user1.Id) {
|
||||||
t.Fatal("failed to create second direct channel")
|
t.Fatal("failed to create second direct channel")
|
||||||
}
|
}
|
||||||
if result := Client.Must(Client.SearchPosts("foobar")).Data.(*model.PostList); len(result.Order) == 0 {
|
if result := Client.Must(Client.SearchPosts("foobar", false)).Data.(*model.PostList); len(result.Order) == 0 {
|
||||||
t.Fatalf("post did not get sent to direct message")
|
t.Fatalf("post did not get sent to direct message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
api/post.go
11
api/post.go
@@ -25,7 +25,7 @@ import (
|
|||||||
func InitPost() {
|
func InitPost() {
|
||||||
l4g.Debug(utils.T("api.post.init.debug"))
|
l4g.Debug(utils.T("api.post.init.debug"))
|
||||||
|
|
||||||
BaseRoutes.NeedTeam.Handle("/posts/search", ApiUserRequired(searchPosts)).Methods("GET")
|
BaseRoutes.NeedTeam.Handle("/posts/search", ApiUserRequired(searchPosts)).Methods("POST")
|
||||||
BaseRoutes.NeedTeam.Handle("/posts/{post_id}", ApiUserRequired(getPostById)).Methods("GET")
|
BaseRoutes.NeedTeam.Handle("/posts/{post_id}", ApiUserRequired(getPostById)).Methods("GET")
|
||||||
BaseRoutes.NeedTeam.Handle("/pltmp/{post_id}", ApiUserRequired(getPermalinkTmp)).Methods("GET")
|
BaseRoutes.NeedTeam.Handle("/pltmp/{post_id}", ApiUserRequired(getPermalinkTmp)).Methods("GET")
|
||||||
|
|
||||||
@@ -1289,17 +1289,24 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
terms := r.FormValue("terms")
|
props := model.StringInterfaceFromJson(r.Body)
|
||||||
|
|
||||||
|
terms := props["terms"].(string)
|
||||||
if len(terms) == 0 {
|
if len(terms) == 0 {
|
||||||
c.SetInvalidParam("search", "terms")
|
c.SetInvalidParam("search", "terms")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isOrSearch := false
|
||||||
|
if val, ok := props["is_or_search"]; ok && val != nil {
|
||||||
|
isOrSearch = val.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
paramsList := model.ParseSearchParams(terms)
|
paramsList := model.ParseSearchParams(terms)
|
||||||
channels := []store.StoreChannel{}
|
channels := []store.StoreChannel{}
|
||||||
|
|
||||||
for _, params := range paramsList {
|
for _, params := range paramsList {
|
||||||
|
params.OrTerms = isOrSearch
|
||||||
// don't allow users to search for everything
|
// don't allow users to search for everything
|
||||||
if params.Terms != "*" {
|
if params.Terms != "*" {
|
||||||
channels = append(channels, Srv.Store.Post().Search(c.TeamId, c.Session.UserId, params))
|
channels = append(channels, Srv.Store.Post().Search(c.TeamId, c.Session.UserId, params))
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ func BenchmarkSearchPosts(b *testing.B) {
|
|||||||
// Benchmark Start
|
// Benchmark Start
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Client.Must(Client.SearchPosts("nothere"))
|
Client.Must(Client.SearchPosts("nothere", false))
|
||||||
Client.Must(Client.SearchPosts("n"))
|
Client.Must(Client.SearchPosts("n", false))
|
||||||
Client.Must(Client.SearchPosts("#tag"))
|
Client.Must(Client.SearchPosts("#tag", false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -357,27 +357,33 @@ func TestSearchPosts(t *testing.T) {
|
|||||||
post4 := &model.Post{ChannelId: channel1.Id, Message: "hashtag for post4"}
|
post4 := &model.Post{ChannelId: channel1.Id, Message: "hashtag for post4"}
|
||||||
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
||||||
|
|
||||||
r1 := Client.Must(Client.SearchPosts("search")).Data.(*model.PostList)
|
r1 := Client.Must(Client.SearchPosts("search", false)).Data.(*model.PostList)
|
||||||
|
|
||||||
if len(r1.Order) != 3 {
|
if len(r1.Order) != 3 {
|
||||||
t.Fatal("wrong search")
|
t.Fatal("wrong search")
|
||||||
}
|
}
|
||||||
|
|
||||||
r2 := Client.Must(Client.SearchPosts("post2")).Data.(*model.PostList)
|
r2 := Client.Must(Client.SearchPosts("post2", false)).Data.(*model.PostList)
|
||||||
|
|
||||||
if len(r2.Order) != 1 && r2.Order[0] == post2.Id {
|
if len(r2.Order) != 1 && r2.Order[0] == post2.Id {
|
||||||
t.Fatal("wrong search")
|
t.Fatal("wrong search")
|
||||||
}
|
}
|
||||||
|
|
||||||
r3 := Client.Must(Client.SearchPosts("#hashtag")).Data.(*model.PostList)
|
r3 := Client.Must(Client.SearchPosts("#hashtag", false)).Data.(*model.PostList)
|
||||||
|
|
||||||
if len(r3.Order) != 1 && r3.Order[0] == post3.Id {
|
if len(r3.Order) != 1 && r3.Order[0] == post3.Id {
|
||||||
t.Fatal("wrong search")
|
t.Fatal("wrong search")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r4 := Client.Must(Client.SearchPosts("*")).Data.(*model.PostList); len(r4.Order) != 0 {
|
if r4 := Client.Must(Client.SearchPosts("*", false)).Data.(*model.PostList); len(r4.Order) != 0 {
|
||||||
t.Fatal("searching for just * shouldn't return any results")
|
t.Fatal("searching for just * shouldn't return any results")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r5 := Client.Must(Client.SearchPosts("post1 post2", true)).Data.(*model.PostList)
|
||||||
|
|
||||||
|
if len(r5.Order) != 2 {
|
||||||
|
t.Fatal("wrong search results")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchHashtagPosts(t *testing.T) {
|
func TestSearchHashtagPosts(t *testing.T) {
|
||||||
@@ -394,7 +400,7 @@ func TestSearchHashtagPosts(t *testing.T) {
|
|||||||
post3 := &model.Post{ChannelId: channel1.Id, Message: "no hashtag"}
|
post3 := &model.Post{ChannelId: channel1.Id, Message: "no hashtag"}
|
||||||
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
|
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
|
||||||
|
|
||||||
r1 := Client.Must(Client.SearchPosts("#sgtitlereview")).Data.(*model.PostList)
|
r1 := Client.Must(Client.SearchPosts("#sgtitlereview", false)).Data.(*model.PostList)
|
||||||
|
|
||||||
if len(r1.Order) != 2 {
|
if len(r1.Order) != 2 {
|
||||||
t.Fatal("wrong search")
|
t.Fatal("wrong search")
|
||||||
@@ -425,47 +431,47 @@ func TestSearchPostsInChannel(t *testing.T) {
|
|||||||
post4 := &model.Post{ChannelId: channel3.Id, Message: "other message with no return"}
|
post4 := &model.Post{ChannelId: channel3.Id, Message: "other message with no return"}
|
||||||
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("channel:")).Data.(*model.PostList); len(result.Order) != 0 {
|
if result := Client.Must(Client.SearchPosts("channel:", false)).Data.(*model.PostList); len(result.Order) != 0 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("in:")).Data.(*model.PostList); len(result.Order) != 0 {
|
if result := Client.Must(Client.SearchPosts("in:", false)).Data.(*model.PostList); len(result.Order) != 0 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("channel:" + channel1.Name)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("channel:"+channel1.Name, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("in: " + channel2.Name)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("in: "+channel2.Name, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("channel: " + channel2.Name)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("channel: "+channel2.Name, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("ChAnNeL: " + channel2.Name)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("ChAnNeL: "+channel2.Name, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("sgtitlereview")).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("sgtitlereview", false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("sgtitlereview channel:" + channel1.Name)).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("sgtitlereview channel:"+channel1.Name, false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("sgtitlereview in: " + channel2.Name)).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("sgtitlereview in: "+channel2.Name, false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("sgtitlereview channel: " + channel2.Name)).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("sgtitlereview channel: "+channel2.Name, false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("channel: " + channel2.Name + " channel: " + channel3.Name)).Data.(*model.PostList); len(result.Order) != 3 {
|
if result := Client.Must(Client.SearchPosts("channel: "+channel2.Name+" channel: "+channel3.Name, false)).Data.(*model.PostList); len(result.Order) != 3 {
|
||||||
t.Fatalf("wrong number of posts returned :) %v :) %v", result.Posts, result.Order)
|
t.Fatalf("wrong number of posts returned :) %v :) %v", result.Posts, result.Order)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -493,22 +499,22 @@ func TestSearchPostsFromUser(t *testing.T) {
|
|||||||
post2 := &model.Post{ChannelId: channel2.Id, Message: "sgtitlereview\n with return"}
|
post2 := &model.Post{ChannelId: channel2.Id, Message: "sgtitlereview\n with return"}
|
||||||
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
|
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user1.Username)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("from: "+user1.Username, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username)).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username, false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username + " sgtitlereview")).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username+" sgtitlereview", false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
post3 := &model.Post{ChannelId: channel1.Id, Message: "hullo"}
|
post3 := &model.Post{ChannelId: channel1.Id, Message: "hullo"}
|
||||||
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
|
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username + " in:" + channel1.Name)).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username+" in:"+channel1.Name, false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,22 +523,22 @@ func TestSearchPostsFromUser(t *testing.T) {
|
|||||||
// wait for the join/leave messages to be created for user3 since they're done asynchronously
|
// wait for the join/leave messages to be created for user3 since they're done asynchronously
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username + " from: " + user3.Username)).Data.(*model.PostList); len(result.Order) != 2 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username+" from: "+user3.Username, false)).Data.(*model.PostList); len(result.Order) != 2 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username + " from: " + user3.Username + " in:" + channel2.Name)).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username+" from: "+user3.Username+" in:"+channel2.Name, false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
|
|
||||||
post4 := &model.Post{ChannelId: channel2.Id, Message: "coconut"}
|
post4 := &model.Post{ChannelId: channel2.Id, Message: "coconut"}
|
||||||
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
||||||
|
|
||||||
if result := Client.Must(Client.SearchPosts("from: " + user2.Username + " from: " + user3.Username + " in:" + channel2.Name + " coconut")).Data.(*model.PostList); len(result.Order) != 1 {
|
if result := Client.Must(Client.SearchPosts("from: "+user2.Username+" from: "+user3.Username+" in:"+channel2.Name+" coconut", false)).Data.(*model.PostList); len(result.Order) != 1 {
|
||||||
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
t.Fatalf("wrong number of posts returned %v", len(result.Order))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -918,8 +918,11 @@ func (c *Client) DeletePost(channelId string, postId string) (*Result, *AppError
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SearchPosts(terms string) (*Result, *AppError) {
|
func (c *Client) SearchPosts(terms string, isOrSearch bool) (*Result, *AppError) {
|
||||||
if r, err := c.DoApiGet(c.GetTeamRoute()+"/posts/search?terms="+url.QueryEscape(terms), "", ""); err != nil {
|
data := map[string]interface{}{}
|
||||||
|
data["terms"] = terms
|
||||||
|
data["is_or_search"] = isOrSearch
|
||||||
|
if r, err := c.DoApiPost(c.GetTeamRoute()+"/posts/search", StringInterfaceToJson(data)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ type SearchParams struct {
|
|||||||
IsHashtag bool
|
IsHashtag bool
|
||||||
InChannels []string
|
InChannels []string
|
||||||
FromUsers []string
|
FromUsers []string
|
||||||
|
OrTerms bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchFlags = [...]string{"from", "channel", "in"}
|
var searchFlags = [...]string{"from", "channel", "in"}
|
||||||
|
|||||||
@@ -725,7 +725,11 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
|
|||||||
terms = wildcard.ReplaceAllLiteralString(terms, ":* ")
|
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)
|
searchClause := fmt.Sprintf("AND %s @@ to_tsquery(:Terms)", searchType)
|
||||||
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
|
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)
|
searchClause := fmt.Sprintf("AND MATCH (%s) AGAINST (:Terms IN BOOLEAN MODE)", searchType)
|
||||||
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
|
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
|
||||||
|
|
||||||
splitTerms := strings.Fields(terms)
|
if !params.OrTerms {
|
||||||
for i, t := range strings.Fields(terms) {
|
splitTerms := strings.Fields(terms)
|
||||||
splitTerms[i] = "+" + t
|
for i, t := range strings.Fields(terms) {
|
||||||
}
|
splitTerms[i] = "+" + t
|
||||||
|
}
|
||||||
|
|
||||||
terms = strings.Join(splitTerms, " ")
|
terms = strings.Join(splitTerms, " ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queryParams["Terms"] = terms
|
queryParams["Terms"] = terms
|
||||||
|
|||||||
@@ -767,6 +767,11 @@ func TestPostStoreSearch(t *testing.T) {
|
|||||||
if len(r12.Order) != 1 {
|
if len(r12.Order) != 1 {
|
||||||
t.Fatal("returned wrong search result")
|
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) {
|
func TestUserCountsWithPostsByDay(t *testing.T) {
|
||||||
|
|||||||
@@ -1267,13 +1267,17 @@ export default class Client {
|
|||||||
this.track('api', 'api_posts_delete');
|
this.track('api', 'api_posts_delete');
|
||||||
}
|
}
|
||||||
|
|
||||||
search = (terms, success, error) => {
|
search = (terms, isOrSearch, success, error) => {
|
||||||
|
const data = {};
|
||||||
|
data.terms = terms;
|
||||||
|
data.is_or_search = isOrSearch;
|
||||||
|
|
||||||
request.
|
request.
|
||||||
get(`${this.getTeamNeededRoute()}/posts/search`).
|
post(`${this.getTeamNeededRoute()}/posts/search`).
|
||||||
set(this.defaultHeaders).
|
set(this.defaultHeaders).
|
||||||
type('application/json').
|
type('application/json').
|
||||||
accept('application/json').
|
accept('application/json').
|
||||||
query({terms}).
|
send(data).
|
||||||
end(this.handleResponse.bind(this, 'search', success, error));
|
end(this.handleResponse.bind(this, 'search', success, error));
|
||||||
|
|
||||||
this.track('api', 'api_posts_search');
|
this.track('api', 'api_posts_search');
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ class SearchBar extends React.Component {
|
|||||||
|
|
||||||
client.search(
|
client.search(
|
||||||
terms,
|
terms,
|
||||||
|
isMentionSearch,
|
||||||
(data) => {
|
(data) => {
|
||||||
this.setState({isSearching: false});
|
this.setState({isSearching: false});
|
||||||
if (utils.isMobile()) {
|
if (utils.isMobile()) {
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ describe('Client.Posts', function() {
|
|||||||
TestHelper.initBasic(() => {
|
TestHelper.initBasic(() => {
|
||||||
TestHelper.basicClient().search(
|
TestHelper.basicClient().search(
|
||||||
'unit test',
|
'unit test',
|
||||||
|
false,
|
||||||
function(data) {
|
function(data) {
|
||||||
assert.equal(data.order[0], TestHelper.basicPost().id);
|
assert.equal(data.order[0], TestHelper.basicPost().id);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ export function getAllTeamListings() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search(terms) {
|
export function search(terms, isOrSearch) {
|
||||||
if (isCallInProgress('search_' + String(terms))) {
|
if (isCallInProgress('search_' + String(terms))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -475,6 +475,7 @@ export function search(terms) {
|
|||||||
callTracker['search_' + String(terms)] = utils.getTimestamp();
|
callTracker['search_' + String(terms)] = utils.getTimestamp();
|
||||||
Client.search(
|
Client.search(
|
||||||
terms,
|
terms,
|
||||||
|
isOrSearch,
|
||||||
(data) => {
|
(data) => {
|
||||||
callTracker['search_' + String(terms)] = 0;
|
callTracker['search_' + String(terms)] = 0;
|
||||||
|
|
||||||
@@ -1370,4 +1371,4 @@ export function getPublicLink(filename, success, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user