mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-16 22:47:11 -04:00
Limit the search to the relevant fields
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user