mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 05:43:36 -05:00
feat(search): native order_by sorting in the bleve backend
(cherry picked from commit 66a0755ad69a6a1af07e0b8335b08d63793777ce)
This commit is contained in:
1 parent
01bca083a6
commit
a36f74edef
1 file changed
+13
-2
@@ -109,8 +109,19 @@ func (b *Backend) Search(ctx context.Context, sir *search.IndexQuery) (*search.I
|
||||
|
||||
bleveReq := bleve.NewSearchRequest(q)
|
||||
bleveReq.Highlight = bleve.NewHighlight()
|
||||
// ties by id, like the cross-space merge
|
||||
bleveReq.SortBy([]string{"-_score", "_id"})
|
||||
// order_by first, then like the cross-space merge: score, ties by id
|
||||
sortOrder := make([]string, 0, len(sir.OrderBy)+2)
|
||||
for _, sp := range sir.OrderBy {
|
||||
field, ok := search.SortIndexField(sp.GetName())
|
||||
if !ok {
|
||||
return nil, errtypes.BadRequest(fmt.Sprintf("field %q is not sortable", sp.GetName()))
|
||||
}
|
||||
if sp.GetIsDescending() {
|
||||
field = "-" + field
|
||||
}
|
||||
sortOrder = append(sortOrder, field)
|
||||
}
|
||||
bleveReq.SortBy(append(sortOrder, "-_score", "_id"))
|
||||
bleveReq.Size = search.EnginePageSize(sir.PageSize, math.MaxInt)
|
||||
|
||||
collector, err := newAggCollector(sir.Aggregations)
|
||||
|
||||
Reference in new issue
Block a user