Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish search #4094

Merged
merged 4 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/polish-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Polish search

We improved the feedback when providing invalid search queries and added support for limiting the number of results returned.

https://github.com/owncloud/ocis/pull/4094
3 changes: 3 additions & 0 deletions services/search/pkg/search/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (i *Index) Search(ctx context.Context, req *searchsvc.SearchIndexRequest) (
)
bleveReq := bleve.NewSearchRequest(query)
bleveReq.Size = 200
if req.PageSize > 0 {
bleveReq.Size = int(req.PageSize)
}
bleveReq.Fields = []string{"*"}
res, err := i.bleveIndex.Search(bleveReq)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion services/search/pkg/search/provider/searchprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func New(gwClient gateway.GatewayAPIClient, indexClient search.IndexClient, mach

func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*searchsvc.SearchResponse, error) {
if req.Query == "" {
return nil, errtypes.PreconditionFailed("empty query provided")
return nil, errtypes.BadRequest("empty query provided")
}
p.logger.Debug().Str("query", req.Query).Msg("performing a search")

Expand Down Expand Up @@ -144,6 +144,7 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s
},
Path: mountpointPrefix,
},
PageSize: req.PageSize,
})
if err != nil {
p.logger.Error().Err(err).Str("space", space.Id.OpaqueId).Msg("failed to search the index")
Expand Down
12 changes: 10 additions & 2 deletions services/search/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"github.com/blevesearch/bleve/v2"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/events/server"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/go-micro/plugins/v4/events/natsjs"
merrors "go-micro.dev/v4/errors"
"go-micro.dev/v4/metadata"
grpcmetadata "google.golang.org/grpc/metadata"

Expand Down Expand Up @@ -92,10 +94,16 @@ func (s Service) Search(ctx context.Context, in *searchsvc.SearchRequest, out *s
ctx = grpcmetadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)

res, err := s.provider.Search(ctx, &searchsvc.SearchRequest{
Query: in.Query,
Query: in.Query,
PageSize: in.PageSize,
})
if err != nil {
return err
switch err.(type) {
case errtypes.BadRequest:
return merrors.BadRequest(s.id, err.Error())
default:
return merrors.InternalServerError(s.id, err.Error())
}
}

out.Matches = res.Matches
Expand Down
3 changes: 2 additions & 1 deletion services/webdav/pkg/service/v0/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
ctx := revactx.ContextSetToken(r.Context(), t)
ctx = metadata.Set(ctx, revactx.TokenHeader, t)
rsp, err := g.searchClient.Search(ctx, &searchsvc.SearchRequest{
Query: rep.SearchFiles.Search.Pattern,
Query: rep.SearchFiles.Search.Pattern,
PageSize: int32(rep.SearchFiles.Search.Limit),
})
if err != nil {
e := merrors.Parse(err.Error())
Expand Down
4 changes: 0 additions & 4 deletions tests/acceptance/expected-failures-API-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,6 @@ _ocdav: api compatibility, return correct status code_
- [apiWebdavOperations/search.feature:264](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavOperations/search.feature#L264)
- [apiWebdavOperations/search.feature:270](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavOperations/search.feature#L270)

### [Different response status code while searching with empty pattern with new webdav](https://github.com/owncloud/ocis/issues/4016)

- [apiWebdavOperations/search.feature:103](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavOperations/search.feature#L103)

### [No permisions propertry in response while searching for files and folders on ocis with new webdav](https://github.com/owncloud/ocis/issues/4009)

- [apiWebdavOperations/search.feature:208](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavOperations/search.feature#L208)
Expand Down