mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-23 16:58:12 -04:00
enhancement(search): implement engine restore
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user