enhancement(search): implement engine restore

This commit is contained in:
fschade committed 2025-08-28 09:30:59 +02:00
1 parent 59b6788b28
commit bd5dec7327
2 files changed
+36 -1

No files matched your search

+9
View File
@@ -61,6 +61,15 @@ func (e *Engine) Delete(id string) error {
}
func (e *Engine) Restore(id string) error {
_, err := e.client.Update(context.Background(), opensearchgoAPI.UpdateReq{
Index: e.index,
DocumentID: id,
Body: bytes.NewReader([]byte(`{"doc": {"Deleted": false}}`)),
})
if err != nil {
return fmt.Errorf("failed to mark document as deleted: %w", err)
}
return nil
}
+27 -1
View File
@@ -57,7 +57,33 @@ func TestEngine_Delete(t *testing.T) {
})
}
func TestEngine_Restore(t *testing.T) {}
func TestEngine_Restore(t *testing.T) {
index := "test-engine-delete"
tc := ostest.NewDefaultTestClient(t)
tc.Require.IndicesReset([]string{index})
tc.Require.IndicesCount([]string{index}, "", 0)
defer tc.Require.IndicesDelete([]string{index})
engine, err := opensearch.NewEngine(index, tc.Client())
assert.NoError(t, err)
t.Run("mark document as not deleted", func(t *testing.T) {
document := ostest.Testdata.Resources.Full
document.Deleted = true
tc.Require.DocumentCreate(index, document.ID, toJSON(t, document))
tc.Require.IndicesCount([]string{index}, "", 1)
tc.Require.IndicesCount([]string{index}, opensearch.NewRootQuery(
opensearch.NewTermQuery[bool]("Deleted").Value(true),
).String(), 1)
assert.NoError(t, engine.Restore(document.ID))
tc.Require.IndicesCount([]string{index}, opensearch.NewRootQuery(
opensearch.NewTermQuery[bool]("Deleted").Value(true),
).String(), 0)
})
}
func TestEngine_Purge(t *testing.T) {
index := "test-engine-purge"