mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 17:17:26 +01:00
28 lines
717 B
Python
28 lines
717 B
Python
|
|
from django.core.management import BaseCommand
|
||
|
|
from whoosh.writing import AsyncWriter
|
||
|
|
|
||
|
|
import documents.index as index
|
||
|
|
from documents.mixins import Renderable
|
||
|
|
from documents.models import Document
|
||
|
|
|
||
|
|
|
||
|
|
class Command(Renderable, BaseCommand):
|
||
|
|
|
||
|
|
help = "Recreates the document index"
|
||
|
|
|
||
|
|
def __init__(self, *args, **kwargs):
|
||
|
|
self.verbosity = 0
|
||
|
|
BaseCommand.__init__(self, *args, **kwargs)
|
||
|
|
|
||
|
|
def handle(self, *args, **options):
|
||
|
|
|
||
|
|
self.verbosity = options["verbosity"]
|
||
|
|
|
||
|
|
documents = Document.objects.all()
|
||
|
|
|
||
|
|
ix = index.open_index(recreate=True)
|
||
|
|
|
||
|
|
with AsyncWriter(ix) as writer:
|
||
|
|
for document in documents:
|
||
|
|
index.update_document(writer, document)
|