mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-15 16:34:55 +00:00
refactor: promote sort_field_map to class-level constant on TantivyBackend
Single source of truth for sort field mapping. The viewset now references TantivyBackend.SORTABLE_FIELDS instead of maintaining a duplicate set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
d998d3fbaf
commit
288740ea62
+3
-13
@@ -2059,6 +2059,7 @@ class UnifiedSearchViewSet(DocumentViewSet):
|
||||
return super().list(request)
|
||||
|
||||
from documents.search import SearchMode
|
||||
from documents.search import TantivyBackend
|
||||
from documents.search import TantivyRelevanceList
|
||||
from documents.search import get_backend
|
||||
|
||||
@@ -2083,20 +2084,9 @@ class UnifiedSearchViewSet(DocumentViewSet):
|
||||
sort_reverse = ordering_param.startswith("-")
|
||||
sort_field_name = ordering_param.lstrip("-") if ordering_param else None
|
||||
|
||||
# Fields Tantivy can sort natively — only numeric/date fast fields.
|
||||
# Text-based sorts (title, correspondent__name, document_type__name)
|
||||
# use a tokenized fast field whose ordering may differ from the ORM,
|
||||
# so they fall back to the ORM sort path.
|
||||
tantivy_sortable = {
|
||||
"created",
|
||||
"added",
|
||||
"modified",
|
||||
"archive_serial_number",
|
||||
"page_count",
|
||||
"num_notes",
|
||||
}
|
||||
use_tantivy_sort = (
|
||||
sort_field_name in tantivy_sortable or sort_field_name is None
|
||||
sort_field_name in TantivyBackend.SORTABLE_FIELDS
|
||||
or sort_field_name is None
|
||||
)
|
||||
|
||||
# Compute the DRF page so we can tell Tantivy which slice to highlight
|
||||
|
||||
Reference in New Issue
Block a user