mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 20:29:54 -06:00
Compile one sorted list of matches and apply the limit if needed
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -46,6 +47,16 @@ type Provider struct {
|
||||
|
||||
type MatchArray []*searchmsg.Match
|
||||
|
||||
func (s MatchArray) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
func (s MatchArray) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
func (s MatchArray) Less(i, j int) bool {
|
||||
return s[i].Score > s[j].Score
|
||||
}
|
||||
|
||||
func New(gwClient gateway.GatewayAPIClient, indexClient search.IndexClient, machineAuthAPIKey string, eventsChan <-chan interface{}, logger log.Logger) *Provider {
|
||||
p := &Provider{
|
||||
gwClient: gwClient,
|
||||
@@ -169,6 +180,16 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s
|
||||
}
|
||||
}
|
||||
|
||||
// compile one sorted list of matches from all spaces and apply the limit if needed
|
||||
sort.Sort(matches)
|
||||
limit := req.PageSize
|
||||
if limit == 0 {
|
||||
limit = 200
|
||||
}
|
||||
if int32(len(matches)) > limit {
|
||||
matches = matches[0:limit]
|
||||
}
|
||||
|
||||
return &searchsvc.SearchResponse{
|
||||
Matches: matches,
|
||||
TotalMatches: total,
|
||||
|
||||
Reference in New Issue
Block a user