Implement Remove for removing entries from the index

This commit is contained in:
André Duffeck
2022-04-11 09:26:48 +02:00
parent 099a89a523
commit a0890eb043
2 changed files with 15 additions and 3 deletions
+4
View File
@@ -64,6 +64,10 @@ func (i *Index) Add(ref *sprovider.Reference, ri *sprovider.ResourceInfo) error
return i.bleveIndex.Index(entity.ID, entity)
}
func (i *Index) Remove(ri *sprovider.ResourceInfo) error {
return i.bleveIndex.Delete(ri.Id.GetStorageId() + ":" + ri.Id.GetOpaqueId())
}
func (i *Index) Search(ctx context.Context, req *search.SearchIndexRequest) (*search.SearchIndexResult, error) {
query := bleve.NewConjunctionQuery(
bleve.NewQueryStringQuery(req.Query),
+11 -3
View File
@@ -90,8 +90,6 @@ var _ = Describe("Index", func() {
}
})
PIt("finds directories by prefix")
Context("and an additional file in a subdirectory", func() {
var (
nestedRef *sprovider.Reference
@@ -187,6 +185,16 @@ var _ = Describe("Index", func() {
})
Describe("Remove", func() {
PIt("removes a resource from the index")
It("removes a resource from the index", func() {
err := i.Add(ref, ri)
Expect(err).ToNot(HaveOccurred())
count, _ := bleveIndex.DocCount()
Expect(count).To(Equal(uint64(1)))
err = i.Remove(ri)
Expect(err).ToNot(HaveOccurred())
count, _ = bleveIndex.DocCount()
Expect(count).To(Equal(uint64(0)))
})
})
})