Limit the search to the relevant fields

This commit is contained in:
André Duffeck
2022-04-22 17:54:42 +02:00
parent fe61ef58e6
commit b14bded1d3
2 changed files with 16 additions and 1 deletions

View File

@@ -75,7 +75,7 @@ func (i *Index) Remove(ri *sprovider.ResourceInfo) error {
// Search searches the index according to the criteria specified in the given SearchIndexRequest
func (i *Index) Search(ctx context.Context, req *searchsvc.SearchIndexRequest) (*searchsvc.SearchIndexResponse, error) {
query := bleve.NewConjunctionQuery(
bleve.NewQueryStringQuery(req.Query),
bleve.NewQueryStringQuery("Name:"+req.Query),
bleve.NewQueryStringQuery("RootID:"+req.Ref.ResourceId.StorageId+"!"+req.Ref.ResourceId.OpaqueId), // Limit search to the space
bleve.NewQueryStringQuery("Path:"+req.Ref.Path+"*"), // Limit search to this directory in the space
)

View File

@@ -86,6 +86,21 @@ var _ = Describe("Index", func() {
Expect(len(res.Matches)).To(Equal(0))
})
It("limits the search to the relevant fields", func() {
res, err := i.Search(ctx, &searchsvc.SearchIndexRequest{
Ref: &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: ref.ResourceId.StorageId,
OpaqueId: ref.ResourceId.OpaqueId,
},
},
Query: "*" + ref.ResourceId.OpaqueId + "*",
})
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(len(res.Matches)).To(Equal(0))
})
It("finds files by name, prefix or substring match", func() {
queries := []string{"foo.pdf", "foo*", "*oo.p*"}
for _, query := range queries {