Allow using lowercase fields

This commit is contained in:
André Duffeck
2022-05-12 11:35:29 +02:00
parent c6c718eb41
commit 4a36ba7811
2 changed files with 28 additions and 6 deletions

View File

@@ -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

View File

@@ -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"
}))
})