2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-10-01 12:12:39 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/search/query"
|
|
|
|
queryV1 "github.com/nspcc-dev/neofs-node/pkg/services/object/search/query/v1"
|
2020-09-29 15:05:22 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2020-09-29 15:05:22 +00:00
|
|
|
func toPrm(body *object.SearchRequestBody, req *object.SearchRequest) (*searchsvc.Prm, error) {
|
2020-09-22 06:51:47 +00:00
|
|
|
var q query.Query
|
|
|
|
|
2020-09-29 15:05:22 +00:00
|
|
|
switch v := body.GetVersion(); v {
|
2020-09-22 06:51:47 +00:00
|
|
|
default:
|
|
|
|
return nil, errors.Errorf("unsupported query version #%d", v)
|
|
|
|
case 1:
|
2020-10-01 12:12:39 +00:00
|
|
|
q = queryV1.New(
|
|
|
|
objectSDK.NewSearchFiltersFromV2(body.GetFilters()),
|
|
|
|
)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new(searchsvc.Prm).
|
|
|
|
WithContainerID(
|
2020-09-29 15:05:22 +00:00
|
|
|
container.NewIDFromV2(body.GetContainerID()),
|
2020-09-22 06:51:47 +00:00
|
|
|
).
|
|
|
|
WithSearchQuery(q).
|
2020-09-29 15:05:22 +00:00
|
|
|
WithCommonPrm(util.CommonPrmFromV2(req)), nil
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func fromResponse(r *searchsvc.Response) *object.SearchResponse {
|
|
|
|
ids := r.IDList()
|
|
|
|
idsV2 := make([]*refs.ObjectID, 0, len(ids))
|
|
|
|
|
|
|
|
for i := range ids {
|
|
|
|
idsV2 = append(idsV2, ids[i].ToV2())
|
|
|
|
}
|
|
|
|
|
|
|
|
body := new(object.SearchResponseBody)
|
|
|
|
body.SetIDList(idsV2)
|
|
|
|
|
|
|
|
resp := new(object.SearchResponse)
|
|
|
|
resp.SetBody(body)
|
|
|
|
|
|
|
|
return resp
|
|
|
|
}
|