mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-09 16:25:33 +01:00
added autocomplete to backend
This commit is contained in:
parent
fb0ad94a9c
commit
653edc1fdc
3 changed files with 41 additions and 1 deletions
|
|
@ -75,6 +75,7 @@ def update_document(writer, doc):
|
|||
content=doc.content
|
||||
)
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=Document)
|
||||
def add_document_to_index(sender, instance, **kwargs):
|
||||
ix = open_index()
|
||||
|
|
@ -102,3 +103,13 @@ def query_index(ix, querystr):
|
|||
'score': r.score,
|
||||
'title': r['title']
|
||||
} for r in results]
|
||||
|
||||
|
||||
def autocomplete(ix, term, limit=10):
|
||||
with ix.reader() as reader:
|
||||
terms = []
|
||||
for t in reader.expand_prefix("content", term.lower()):
|
||||
terms.append(t)
|
||||
if len(terms) >= limit:
|
||||
break
|
||||
return terms
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue