Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
mattermost-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
sysadmin
mattermost
mattermost-server
Commits
37e00ef9
Commit
37e00ef9
authored
Sep 26, 2018
by
Christopher Speller
Committed by
Harrison Healey
Sep 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding paging to elasticsearch API. (#9425)
parent
bfec808e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
32 deletions
+68
-32
api4/post.go
api4/post.go
+26
-10
api4/post_test.go
api4/post_test.go
+33
-5
app/post.go
app/post.go
+2
-2
einterfaces/elasticsearch.go
einterfaces/elasticsearch.go
+1
-1
model/client4.go
model/client4.go
+0
-11
model/post.go
model/post.go
+6
-3
No files found.
api4/post.go
View file @
37e00ef9
...
...
@@ -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
...
...
api4/post_test.go
View file @
37e00ef9
...
...
@@ -15,6 +15,8 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
...
...
@@ -1323,6 +1325,24 @@ func TestSearchPosts(t *testing.T) {
t
.
Fatal
(
"wrong search"
)
}
terms
=
"search"
page
:=
0
perPage
:=
2
searchParams
=
model
.
SearchParameter
{
Terms
:
&
terms
,
IsOrSearch
:
&
isOrSearch
,
TimeZoneOffset
:
&
timezoneOffset
,
Page
:
&
page
,
PerPage
:
&
perPage
,
}
posts2
,
resp
:=
Client
.
SearchPostsWithParams
(
th
.
BasicTeam
.
Id
,
&
searchParams
)
CheckNoError
(
t
,
resp
)
if
len
(
posts2
.
Order
)
!=
3
{
// We don't support paging for DB search yet, modify this when we do.
t
.
Fatal
(
"Wrong number of posts"
,
len
(
posts2
.
Order
))
}
assert
.
Equal
(
t
,
posts
.
Order
[
0
],
posts2
.
Order
[
0
])
assert
.
Equal
(
t
,
posts
.
Order
[
1
],
posts2
.
Order
[
1
])
posts
,
resp
=
Client
.
SearchPosts
(
th
.
BasicTeam
.
Id
,
"search"
,
false
)
CheckNoError
(
t
,
resp
)
if
len
(
posts
.
Order
)
!=
3
{
...
...
@@ -1341,7 +1361,15 @@ func TestSearchPosts(t *testing.T) {
t
.
Fatal
(
"wrong search"
)
}
posts
,
resp
=
Client
.
SearchPostsIncludeDeletedChannels
(
th
.
BasicTeam
.
Id
,
"#hashtag"
,
false
)
terms
=
"#hashtag"
includeDeletedChannels
:=
true
searchParams
=
model
.
SearchParameter
{
Terms
:
&
terms
,
IsOrSearch
:
&
isOrSearch
,
TimeZoneOffset
:
&
timezoneOffset
,
IncludeDeletedChannels
:
&
includeDeletedChannels
,
}
posts
,
resp
=
Client
.
SearchPostsWithParams
(
th
.
BasicTeam
.
Id
,
&
searchParams
)
CheckNoError
(
t
,
resp
)
if
len
(
posts
.
Order
)
!=
2
{
t
.
Fatal
(
"wrong search"
)
...
...
@@ -1351,7 +1379,7 @@ func TestSearchPosts(t *testing.T) {
*
cfg
.
TeamSettings
.
ExperimentalViewArchivedChannels
=
false
})
posts
,
resp
=
Client
.
SearchPosts
IncludeDeletedChannels
(
th
.
BasicTeam
.
Id
,
"#hashtag"
,
false
)
posts
,
resp
=
Client
.
SearchPosts
WithParams
(
th
.
BasicTeam
.
Id
,
&
searchParams
)
CheckNoError
(
t
,
resp
)
if
len
(
posts
.
Order
)
!=
1
{
t
.
Fatal
(
"wrong search"
)
...
...
@@ -1389,13 +1417,13 @@ func TestSearchHashtagPosts(t *testing.T) {
Client
:=
th
.
Client
message
:=
"#sgtitlereview with space"
_
=
th
.
CreateMessagePost
(
message
)
assert
.
NotNil
(
t
,
th
.
CreateMessagePost
(
message
)
)
message
=
"#sgtitlereview
\n
with return"
_
=
th
.
CreateMessagePost
(
message
)
assert
.
NotNil
(
t
,
th
.
CreateMessagePost
(
message
)
)
message
=
"no hashtag"
_
=
th
.
CreateMessagePost
(
message
)
assert
.
NotNil
(
t
,
th
.
CreateMessagePost
(
message
)
)
posts
,
resp
:=
Client
.
SearchPosts
(
th
.
BasicTeam
.
Id
,
"#sgtitlereview"
,
false
)
CheckNoError
(
t
,
resp
)
...
...
app/post.go
View file @
37e00ef9
...
...
@@ -622,7 +622,7 @@ func (a *App) DeletePostFiles(post *model.Post) {
}
}
func
(
a
*
App
)
SearchPostsInTeam
(
terms
string
,
userId
string
,
teamId
string
,
isOrSearch
bool
,
includeDeletedChannels
bool
,
timeZoneOffset
int
)
(
*
model
.
PostSearchResults
,
*
model
.
AppError
)
{
func
(
a
*
App
)
SearchPostsInTeam
(
terms
string
,
userId
string
,
teamId
string
,
isOrSearch
bool
,
includeDeletedChannels
bool
,
timeZoneOffset
int
,
page
,
perPage
int
)
(
*
model
.
PostSearchResults
,
*
model
.
AppError
)
{
paramsList
:=
model
.
ParseSearchParams
(
terms
,
timeZoneOffset
)
includeDeleted
:=
includeDeletedChannels
&&
*
a
.
Config
()
.
TeamSettings
.
ExperimentalViewArchivedChannels
...
...
@@ -668,7 +668,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
return
nil
,
err
}
postIds
,
matches
,
err
:=
a
.
Elasticsearch
.
SearchPosts
(
userChannels
,
finalParamsList
)
postIds
,
matches
,
err
:=
a
.
Elasticsearch
.
SearchPosts
(
userChannels
,
finalParamsList
,
page
,
perPage
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
einterfaces/elasticsearch.go
View file @
37e00ef9
...
...
@@ -13,7 +13,7 @@ type ElasticsearchInterface interface {
Start
()
*
model
.
AppError
Stop
()
*
model
.
AppError
IndexPost
(
post
*
model
.
Post
,
teamId
string
)
*
model
.
AppError
SearchPosts
(
channels
*
model
.
ChannelList
,
searchParams
[]
*
model
.
SearchParams
)
([]
string
,
model
.
PostSearchMatches
,
*
model
.
AppError
)
SearchPosts
(
channels
*
model
.
ChannelList
,
searchParams
[]
*
model
.
SearchParams
,
page
,
perPage
int
)
([]
string
,
model
.
PostSearchMatches
,
*
model
.
AppError
)
DeletePost
(
post
*
model
.
Post
)
*
model
.
AppError
TestConfig
(
cfg
*
model
.
Config
)
*
model
.
AppError
PurgeIndexes
()
*
model
.
AppError
...
...
model/client4.go
View file @
37e00ef9
...
...
@@ -2168,17 +2168,6 @@ func (c *Client4) SearchPostsWithParams(teamId string, params *SearchParameter)
}
}
// SearchPosts returns any posts with matching terms string including deleted channels.
func
(
c
*
Client4
)
SearchPostsIncludeDeletedChannels
(
teamId
string
,
terms
string
,
isOrSearch
bool
)
(
*
PostList
,
*
Response
)
{
requestBody
:=
map
[
string
]
interface
{}{
"terms"
:
terms
,
"is_or_search"
:
isOrSearch
}
if
r
,
err
:=
c
.
DoApiPost
(
c
.
GetTeamRoute
(
teamId
)
+
"/posts/search?include_deleted_channels=true"
,
StringInterfaceToJson
(
requestBody
));
err
!=
nil
{
return
nil
,
BuildErrorResponse
(
r
,
err
)
}
else
{
defer
closeBody
(
r
)
return
PostListFromJson
(
r
.
Body
),
BuildResponse
(
r
)
}
}
// SearchPosts returns any posts with matching terms string, including .
func
(
c
*
Client4
)
SearchPostsWithMatches
(
teamId
string
,
terms
string
,
isOrSearch
bool
)
(
*
PostSearchResults
,
*
Response
)
{
requestBody
:=
map
[
string
]
interface
{}{
"terms"
:
terms
,
"is_or_search"
:
isOrSearch
}
...
...
model/post.go
View file @
37e00ef9
...
...
@@ -97,9 +97,12 @@ type PostPatch struct {
}
type
SearchParameter
struct
{
Terms
*
string
`json:"terms"`
IsOrSearch
*
bool
`json:"is_or_search"`
TimeZoneOffset
*
int
`json:"time_zone_offset"`
Terms
*
string
`json:"terms"`
IsOrSearch
*
bool
`json:"is_or_search"`
TimeZoneOffset
*
int
`json:"time_zone_offset"`
Page
*
int
`json:"page"`
PerPage
*
int
`json:"per_page"`
IncludeDeletedChannels
*
bool
`json:"include_deleted_channels"`
}
func
(
o
*
PostPatch
)
WithRewrittenImageURLs
(
f
func
(
string
)
string
)
*
PostPatch
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment