mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-27 10:34:42 -05:00
fix(search)!: remove the unlimited page size
A page size of -1 asked for every match. Bleve returned them all, OpenSearch silently stopped at 1000 per space (#4153). OpenSearch has no unlimited page, and nothing sends -1 anymore since the tag listing moved to an aggregation. Negative page sizes are rejected with a bad request now, in the search service and as limit of the WebDAV search report. BREAKING CHANGE: <oc:limit>-1</oc:limit> in the WebDAV search report and a page size of -1 on the gRPC API of the search service answer 400 instead of returning every match.
This commit is contained in:
1 parent
7793ff4a3e
commit
85fad211cf
8 files changed
+12
-27
No files matched your search
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -117,7 +116,7 @@ func (b *Backend) Search(ctx context.Context, sir *search.IndexQuery) (*search.I
|
||||
bleveReq.Highlight = bleve.NewHighlight()
|
||||
// ties by id, like the cross-space merge
|
||||
bleveReq.SortBy([]string{"-_score", "_id"})
|
||||
bleveReq.Size = search.EnginePageSize(sir.PageSize, math.MaxInt)
|
||||
bleveReq.Size = int(search.PageSizeOrDefault(sir.PageSize))
|
||||
|
||||
collector, err := newAggCollector(sir.Aggregations)
|
||||
if err != nil {
|
||||
|
||||
@@ -135,7 +135,7 @@ func (b *Backend) Search(ctx context.Context, sir *search.IndexQuery) (*search.I
|
||||
TrackScores: conversions.ToPointer(true),
|
||||
// count every match, the default stops at 10000
|
||||
TrackTotalHits: true,
|
||||
Size: conversions.ToPointer(search.EnginePageSize(sir.PageSize, 1000)),
|
||||
Size: conversions.ToPointer(int(search.PageSizeOrDefault(sir.PageSize))),
|
||||
}
|
||||
// replicas may score a document differently, so a user reads every page
|
||||
// from the same shard copies; a preference must not start with an underscore
|
||||
|
||||
@@ -426,7 +426,6 @@ Fixtures:
|
||||
| EVERYTHING-01 | `*` | alpha.txt, beta.txt, box | alpha.txt, beta.txt, box | alpha.txt, beta.txt, box | ✅ |
|
||||
| EVERYTHING-02 | `name:"*"` | alpha.txt, beta.txt, box | alpha.txt, beta.txt, box | alpha.txt, beta.txt, box | ✅ |
|
||||
| EVERYTHING-03 | `*` with a limit of 2 | 2 items | alpha.txt, beta.txt | alpha.txt, beta.txt | ✅ |
|
||||
| EVERYTHING-04 | `*` with a limit of -1 | 3 items | alpha.txt, beta.txt, box | alpha.txt, beta.txt, box | ✅ |
|
||||
|
||||
### range
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ func everythingGroup() queryGroup {
|
||||
{id: 1, query: `*`, want: []string{"alpha.txt", "beta.txt", "box"}},
|
||||
{id: 2, query: `name:"*"`, want: []string{"alpha.txt", "beta.txt", "box"}},
|
||||
{id: 3, query: `*`, limit: 2, wantCount: conversions.ToPointer(2)},
|
||||
{id: 4, query: `*`, limit: -1, wantCount: conversions.ToPointer(3)},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,8 @@ func ExpandQueryTemplate(template, query string, space *provider.StorageSpace) s
|
||||
|
||||
// Search processes a search request and passes it down to the engine.
|
||||
func (s *Service) Search(ctx context.Context, req *searchsvc.SearchRequest) (*searchsvc.SearchResponse, error) {
|
||||
if PageSizeOrDefault(req.PageSize) < -1 {
|
||||
return nil, errtypes.BadRequest("page size must be -1, 0 or positive")
|
||||
if PageSizeOrDefault(req.PageSize) < 0 {
|
||||
return nil, errtypes.BadRequest("page size must not be negative")
|
||||
}
|
||||
if err := aggregation.ValidateOptions(req.GetAggregations(), AggregatableFieldType); err != nil {
|
||||
return nil, errtypes.BadRequest(err.Error())
|
||||
@@ -384,7 +384,7 @@ func (s *Service) Search(ctx context.Context, req *searchsvc.SearchRequest) (*se
|
||||
matches = nil
|
||||
}
|
||||
}
|
||||
if limit != -1 && int32(len(matches)) > limit {
|
||||
if int32(len(matches)) > limit {
|
||||
matches = matches[0:limit]
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ func (s *Service) Search(ctx context.Context, req *searchsvc.SearchRequest) (*se
|
||||
}, nil
|
||||
}
|
||||
|
||||
// PageSizeOrDefault reads an absent page size as 200; -1 is no limit.
|
||||
// PageSizeOrDefault reads an absent page size as 200.
|
||||
func PageSizeOrDefault(pageSize *int32) int32 {
|
||||
if pageSize != nil {
|
||||
return *pageSize
|
||||
@@ -404,16 +404,6 @@ func PageSizeOrDefault(pageSize *int32) int32 {
|
||||
return 200
|
||||
}
|
||||
|
||||
// EnginePageSize is the page an engine fetches: the default for an absent
|
||||
// size, unlimited for -1.
|
||||
func EnginePageSize(pageSize *int32, unlimited int) int {
|
||||
size := PageSizeOrDefault(pageSize)
|
||||
if size == -1 {
|
||||
return unlimited
|
||||
}
|
||||
return int(size)
|
||||
}
|
||||
|
||||
// engineFetchSize: the global offset cannot be distributed across spaces, so
|
||||
// every space must return the full prefix up to from+limit for the merge.
|
||||
func engineFetchSize(from int32, pageSize *int32) int32 {
|
||||
|
||||
@@ -899,7 +899,7 @@ var _ = Describe("Searchprovider", func() {
|
||||
indexClient.AssertNotCalled(GinkgoT(), "Search", mock.Anything, mock.Anything)
|
||||
gatewayClient.AssertNotCalled(GinkgoT(), "ListStorageSpaces", mock.Anything, mock.Anything)
|
||||
},
|
||||
Entry("a page size below -1", &searchsvc.SearchRequest{Query: "foo", PageSize: conversions.ToPointer(int32(-2))}),
|
||||
Entry("a negative page size", &searchsvc.SearchRequest{Query: "foo", PageSize: conversions.ToPointer(int32(-1))}),
|
||||
// the rules are pinned in the aggregation package
|
||||
Entry("an aggregation on an internal field", &searchsvc.SearchRequest{Query: "foo",
|
||||
Aggregations: []*searchsvc.AggregationOption{{Field: "Favorites"}}}),
|
||||
|
||||
@@ -122,11 +122,11 @@ func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
|
||||
g.sendSearchResponse(davPrefix, rsp, w, r, user)
|
||||
}
|
||||
|
||||
// searchRequestOf maps the search element of the report: limit -1 is no
|
||||
// limit, 0 the default, offset skips leading matches of the merged list.
|
||||
// searchRequestOf maps the search element of the report: limit 0 is the
|
||||
// default, offset skips leading matches of the merged list.
|
||||
func searchRequestOf(search reportSearchFilesSearch) (*searchsvc.SearchRequest, error) {
|
||||
if search.Limit < -1 {
|
||||
return nil, fmt.Errorf("limit must be -1, 0 or positive")
|
||||
if search.Limit < 0 {
|
||||
return nil, fmt.Errorf("limit must not be negative")
|
||||
}
|
||||
if search.Offset < 0 {
|
||||
return nil, fmt.Errorf("offset must not be negative")
|
||||
|
||||
@@ -109,8 +109,6 @@ var _ = Describe("searchRequestOf", func() {
|
||||
reportSearchFilesSearch{Pattern: "notes"}, &searchsvc.SearchRequest{Query: "notes"}),
|
||||
Entry("a limit", reportSearchFilesSearch{Pattern: "notes", Limit: 25},
|
||||
&searchsvc.SearchRequest{Query: "notes", PageSize: conversions.ToPointer(int32(25))}),
|
||||
Entry("no limit", reportSearchFilesSearch{Pattern: "notes", Limit: -1},
|
||||
&searchsvc.SearchRequest{Query: "notes", PageSize: conversions.ToPointer(int32(-1))}),
|
||||
Entry("an offset pages the merged list", reportSearchFilesSearch{Pattern: "notes", Limit: 25, Offset: 50},
|
||||
&searchsvc.SearchRequest{Query: "notes", PageSize: conversions.ToPointer(int32(25)), From: 50}),
|
||||
)
|
||||
@@ -121,6 +119,6 @@ var _ = Describe("searchRequestOf", func() {
|
||||
Expect(err).To(HaveOccurred())
|
||||
},
|
||||
Entry("a negative offset", reportSearchFilesSearch{Pattern: "notes", Offset: -1}),
|
||||
Entry("a limit below -1", reportSearchFilesSearch{Pattern: "notes", Limit: -2}),
|
||||
Entry("a negative limit", reportSearchFilesSearch{Pattern: "notes", Limit: -1}),
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user