mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-05-16 11:35:24 +00:00
Covers the reindex --recreate path and documents the flag
This commit is contained in:
@@ -463,11 +463,17 @@ the search yields non-existing documents or won't find anything, you
|
||||
may need to recreate the index manually.
|
||||
|
||||
```
|
||||
document_index {reindex,optimize}
|
||||
document_index {reindex,optimize} [--recreate] [--if-needed]
|
||||
```
|
||||
|
||||
Specify `reindex` to have the index created from scratch. This may take
|
||||
some time.
|
||||
Specify `reindex` to rebuild the index from all documents in the database. This
|
||||
may take some time.
|
||||
|
||||
Pass `--recreate` to wipe the existing index before rebuilding. Use this when the
|
||||
index is corrupted or you want a fully clean rebuild.
|
||||
|
||||
Pass `--if-needed` to skip the rebuild if the index is already up to date (schema
|
||||
version and search language match). Safe to run on every startup or upgrade.
|
||||
|
||||
Specify `optimize` to optimize the index. This command is regularly invoked by the
|
||||
task scheduler.
|
||||
|
||||
@@ -117,6 +117,32 @@ class TestMakeIndex:
|
||||
"""Optimize command must execute without error (Tantivy handles optimization automatically)."""
|
||||
call_command("document_index", "optimize", skip_checks=True)
|
||||
|
||||
def test_reindex_recreate_wipes_index(self, mocker: MockerFixture) -> None:
|
||||
"""Reindex with --recreate must wipe the index before rebuilding."""
|
||||
mock_wipe = mocker.patch(
|
||||
"documents.management.commands.document_index.wipe_index",
|
||||
)
|
||||
mock_get_backend = mocker.patch(
|
||||
"documents.management.commands.document_index.get_backend",
|
||||
)
|
||||
call_command("document_index", "reindex", recreate=True, skip_checks=True)
|
||||
mock_wipe.assert_called_once()
|
||||
mock_get_backend.return_value.rebuild.assert_called_once()
|
||||
|
||||
def test_reindex_without_recreate_does_not_wipe_index(
|
||||
self,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
"""Reindex without --recreate must not wipe the index."""
|
||||
mock_wipe = mocker.patch(
|
||||
"documents.management.commands.document_index.wipe_index",
|
||||
)
|
||||
mocker.patch(
|
||||
"documents.management.commands.document_index.get_backend",
|
||||
)
|
||||
call_command("document_index", "reindex", skip_checks=True)
|
||||
mock_wipe.assert_not_called()
|
||||
|
||||
def test_reindex_if_needed_skips_when_up_to_date(
|
||||
self,
|
||||
mocker: MockerFixture,
|
||||
|
||||
Reference in New Issue
Block a user