moved some code

This commit is contained in:
Jonas Winkler
2020-11-08 11:30:16 +01:00
parent 942fab7298
commit 7747e6512a
2 changed files with 19 additions and 14 deletions

View File

@@ -2,9 +2,11 @@ import logging
from django.db import models
from django.dispatch import receiver
from whoosh import highlight
from whoosh.fields import Schema, TEXT, NUMERIC
from whoosh.highlight import Formatter, get_text
from whoosh.index import create_in, exists_in, open_dir
from whoosh.qparser import MultifieldParser
from whoosh.writing import AsyncWriter
from documents.models import Document
@@ -97,6 +99,17 @@ def remove_document_from_index(document):
remove_document(writer, document)
def query_page(ix, query, page):
with ix.searcher() as searcher:
query_parser = MultifieldParser(["content", "title", "correspondent"],
ix.schema).parse(query)
result_page = searcher.search_page(query_parser, page)
result_page.results.fragmenter = highlight.ContextFragmenter(
surround=50)
result_page.results.formatter = JsonFormatter()
return result_page
def autocomplete(ix, term, limit=10):
with ix.reader() as reader:
terms = []