Change the index query string to contain the field name

This increases flexibility when searching the index
This commit is contained in:
André Duffeck
2022-05-12 09:27:02 +02:00
parent ae68d5d522
commit 22f5e471bd
4 changed files with 27 additions and 14 deletions

View File

@@ -212,7 +212,7 @@ func (i *Index) Search(ctx context.Context, req *searchsvc.SearchIndexRequest) (
deletedQuery := bleve.NewBoolFieldQuery(false)
deletedQuery.SetField("Deleted")
query := bleve.NewConjunctionQuery(
bleve.NewQueryStringQuery("Name:"+strings.ToLower(req.Query)),
bleve.NewQueryStringQuery(req.Query),
deletedQuery, // Skip documents that have been marked as deleted
bleve.NewQueryStringQuery("RootID:"+req.Ref.ResourceId.StorageId+"!"+req.Ref.ResourceId.OpaqueId), // Limit search to the space
bleve.NewQueryStringQuery("Path:"+utils.MakeRelativePath(path.Join(req.Ref.Path, "/"))+"*"), // Limit search to this directory in the space

View File

@@ -26,7 +26,7 @@ var _ = Describe("Index", func() {
}
ref = &sprovider.Reference{
ResourceId: rootId,
Path: "./foo.pdf",
Path: "./Foo.pdf",
}
ri = &sprovider.ResourceInfo{
Id: &sprovider.ResourceId{
@@ -133,14 +133,14 @@ var _ = Describe("Index", func() {
OpaqueId: "differentopaqueid",
},
},
Query: "foo.pdf",
Query: "Name:foo.pdf",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(len(res.Matches)).To(Equal(0))
})
It("limits the search to the relevant fields", func() {
It("limits the search to the specified fields", func() {
res, err := i.Search(ctx, &searchsvc.SearchIndexRequest{
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
@@ -148,7 +148,7 @@ var _ = Describe("Index", func() {
OpaqueId: ref.ResourceId.OpaqueId,
},
},
Query: "*" + ref.ResourceId.OpaqueId + "*",
Query: "Name:*" + ref.ResourceId.OpaqueId + "*",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
@@ -163,7 +163,7 @@ var _ = Describe("Index", func() {
OpaqueId: ref.ResourceId.OpaqueId,
},
},
Query: "foo.pdf",
Query: "Name:foo.pdf",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
@@ -203,7 +203,7 @@ var _ = Describe("Index", func() {
}
})
It("is case-insensitive", func() {
It("uses a lower-case index", func() {
res, err := i.Search(ctx, &searchsvc.SearchIndexRequest{
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
@@ -211,11 +211,24 @@ var _ = Describe("Index", func() {
OpaqueId: ref.ResourceId.OpaqueId,
},
},
Query: "Foo*",
Query: "Name:foo*",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(len(res.Matches)).To(Equal(1))
res, err = i.Search(ctx, &searchsvc.SearchIndexRequest{
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: ref.ResourceId.StorageId,
OpaqueId: ref.ResourceId.OpaqueId,
},
},
Query: "Name:Foo*",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(len(res.Matches)).To(Equal(0))
})
Context("and an additional file in a subdirectory", func() {
@@ -271,7 +284,7 @@ var _ = Describe("Index", func() {
},
Path: "./nested/",
},
Query: "foo.pdf",
Query: "Name:foo.pdf",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
@@ -372,7 +385,7 @@ var _ = Describe("Index", func() {
assertDocCount(rootId, "subdir", 0)
res, err := i.Search(ctx, &searchsvc.SearchIndexRequest{
Query: "child.pdf",
Query: "Name:child.pdf",
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: rootId.StorageId,

View File

@@ -125,7 +125,7 @@ func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*s
_, rootStorageID := storagespace.SplitStorageID(space.Root.StorageId)
res, err := p.indexClient.Search(ctx, &searchsvc.SearchIndexRequest{
Query: req.Query,
Query: "Name:" + strings.ToLower(req.Query),
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: space.Root.StorageId,

View File

@@ -160,7 +160,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 == "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 == ""
}))
})
})
@@ -225,7 +225,7 @@ var _ = Describe("Searchprovider", func() {
}, nil)
res, err := p.Search(ctx, &searchsvc.SearchRequest{
Query: "foo",
Query: "Foo",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
@@ -237,7 +237,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 == "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"
}))
})