mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-05 07:46:54 -05:00
Allow using lowercase fields
This commit is contained in:
@@ -220,8 +220,13 @@ func (p *Provider) logDocCount() {
|
||||
|
||||
func formatQuery(q string) string {
|
||||
query := q
|
||||
if strings.Contains(q, ":") {
|
||||
return q // Sophisticated field based search
|
||||
fields := []string{"RootID", "Path", "ID", "Name", "Size", "Mtime", "MimeType", "Type"}
|
||||
for _, field := range fields {
|
||||
query = strings.ReplaceAll(query, strings.ToLower(field)+":", field+":")
|
||||
}
|
||||
|
||||
if strings.Contains(query, ":") {
|
||||
return query // Sophisticated field based search
|
||||
}
|
||||
|
||||
// this is a basic filename search
|
||||
|
||||
@@ -151,7 +151,7 @@ var _ = Describe("Searchprovider", func() {
|
||||
Query: "Foo.pdf",
|
||||
})
|
||||
indexClient.AssertCalled(GinkgoT(), "Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool {
|
||||
return req.Query == "Name:foo.pdf"
|
||||
return req.Query == "Name:*foo.pdf*"
|
||||
}))
|
||||
})
|
||||
|
||||
@@ -164,12 +164,29 @@ var _ = Describe("Searchprovider", func() {
|
||||
}))
|
||||
})
|
||||
|
||||
It("uppercases field names", func() {
|
||||
tests := []struct {
|
||||
Original string
|
||||
Expected string
|
||||
}{
|
||||
{Original: "size:<100", Expected: "Size:<100"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
p.Search(ctx, &searchsvc.SearchRequest{
|
||||
Query: test.Original,
|
||||
})
|
||||
indexClient.AssertCalled(GinkgoT(), "Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool {
|
||||
return req.Query == test.Expected
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
It("escapes special characters", func() {
|
||||
p.Search(ctx, &searchsvc.SearchRequest{
|
||||
Query: "Foo oo.pdf",
|
||||
})
|
||||
indexClient.AssertCalled(GinkgoT(), "Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool {
|
||||
return req.Query == `Name:foo\ oo.pdf`
|
||||
return req.Query == `Name:*foo\ oo.pdf*`
|
||||
}))
|
||||
})
|
||||
|
||||
@@ -187,7 +204,7 @@ var _ = Describe("Searchprovider", func() {
|
||||
Expect(match.Entity.Ref.Path).To(Equal("./path/to/Foo.pdf"))
|
||||
|
||||
indexClient.AssertCalled(GinkgoT(), "Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool {
|
||||
return req.Query == "Name:foo" && req.Ref.ResourceId.OpaqueId == personalSpace.Root.OpaqueId && req.Ref.Path == ""
|
||||
return req.Query == "Name:*foo*" && req.Ref.ResourceId.OpaqueId == personalSpace.Root.OpaqueId && req.Ref.Path == ""
|
||||
}))
|
||||
})
|
||||
})
|
||||
@@ -264,7 +281,7 @@ var _ = Describe("Searchprovider", func() {
|
||||
Expect(match.Entity.Ref.Path).To(Equal("./to/Shared.pdf"))
|
||||
|
||||
indexClient.AssertCalled(GinkgoT(), "Search", mock.Anything, mock.MatchedBy(func(req *searchsvc.SearchIndexRequest) bool {
|
||||
return req.Query == "Name:foo" && req.Ref.ResourceId.StorageId == grantSpace.Root.StorageId && req.Ref.Path == "./grant/path"
|
||||
return req.Query == "Name:*foo*" && req.Ref.ResourceId.StorageId == grantSpace.Root.StorageId && req.Ref.Path == "./grant/path"
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user