mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fix: Removes the FieldParser plugin from autocomplete searches (#4934)
This commit is contained in:
parent
af0817ab74
commit
7e12bd1bef
@ -3,6 +3,7 @@ import math
|
|||||||
import os
|
import os
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from dateutil.parser import isoparse
|
from dateutil.parser import isoparse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -26,6 +27,7 @@ from whoosh.qparser import MultifieldParser
|
|||||||
from whoosh.qparser import QueryParser
|
from whoosh.qparser import QueryParser
|
||||||
from whoosh.qparser.dateparse import DateParserPlugin
|
from whoosh.qparser.dateparse import DateParserPlugin
|
||||||
from whoosh.qparser.dateparse import English
|
from whoosh.qparser.dateparse import English
|
||||||
|
from whoosh.qparser.plugins import FieldsPlugin
|
||||||
from whoosh.scoring import TF_IDF
|
from whoosh.scoring import TF_IDF
|
||||||
from whoosh.searching import ResultsPage
|
from whoosh.searching import ResultsPage
|
||||||
from whoosh.searching import Searcher
|
from whoosh.searching import Searcher
|
||||||
@ -425,7 +427,12 @@ class DelayedMoreLikeThisQuery(DelayedQuery):
|
|||||||
return q, mask
|
return q, mask
|
||||||
|
|
||||||
|
|
||||||
def autocomplete(ix: FileIndex, term: str, limit: int = 10, user: User = None):
|
def autocomplete(
|
||||||
|
ix: FileIndex,
|
||||||
|
term: str,
|
||||||
|
limit: int = 10,
|
||||||
|
user: Optional[User] = None,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Mimics whoosh.reading.IndexReader.most_distinctive_terms with permissions
|
Mimics whoosh.reading.IndexReader.most_distinctive_terms with permissions
|
||||||
and without scoring
|
and without scoring
|
||||||
@ -434,6 +441,9 @@ def autocomplete(ix: FileIndex, term: str, limit: int = 10, user: User = None):
|
|||||||
|
|
||||||
with ix.searcher(weighting=TF_IDF()) as s:
|
with ix.searcher(weighting=TF_IDF()) as s:
|
||||||
qp = QueryParser("content", schema=ix.schema)
|
qp = QueryParser("content", schema=ix.schema)
|
||||||
|
# Don't let searches with a query that happen to match a field override the
|
||||||
|
# content field query instead and return bogus, not text data
|
||||||
|
qp.remove_plugin_class(FieldsPlugin)
|
||||||
q = qp.parse(f"{term.lower()}*")
|
q = qp.parse(f"{term.lower()}*")
|
||||||
user_criterias = get_permissions_criterias(user)
|
user_criterias = get_permissions_criterias(user)
|
||||||
|
|
||||||
@ -453,7 +463,7 @@ def autocomplete(ix: FileIndex, term: str, limit: int = 10, user: User = None):
|
|||||||
return terms
|
return terms
|
||||||
|
|
||||||
|
|
||||||
def get_permissions_criterias(user: User = None):
|
def get_permissions_criterias(user: Optional[User] = None):
|
||||||
user_criterias = [query.Term("has_owner", False)]
|
user_criterias = [query.Term("has_owner", False)]
|
||||||
if user is not None:
|
if user is not None:
|
||||||
if user.is_superuser: # superusers see all docs
|
if user.is_superuser: # superusers see all docs
|
||||||
|
File diff suppressed because it is too large
Load Diff
1077
src/documents/tests/test_api_search.py
Normal file
1077
src/documents/tests/test_api_search.py
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user