Merge pull request #4094 from aduffeck/polish-search

Polish search
This commit is contained in:
Andre Duffeck
2022-07-06 08:44:43 +02:00
committed by GitHub
6 changed files with 22 additions and 8 deletions
+5
View File
@@ -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
@@ -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 {
@@ -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")
@@ -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")
+10 -2
View File
@@ -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"
@@ -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
+2 -1
View File
@@ -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())
@@ -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)