wrolpi/wrolpi/files/schema.py
Roland 73fafcd645
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries.  Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.

Database:
- Migration adds the generated column and a GIN index (rewrites the
  table; a few minutes on large libraries).

Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
  DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
  query (COUNT FILTER on the abc subset): `file_groups` (fast) and
  `file_groups_deep`.

UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
  list.
- The gap is reconciled by a hint offering deep search: count-aware on
  the global search ("No results in fast search. N results available in
  deep search." / "N more results available..."), generic on the module
  pages (no deep estimate there).  The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
  ?deep=true.

Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside.  Also skip flaky test_download_channel on
CircleCI.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:32:16 -06:00

115 lines
2.6 KiB
Python

from dataclasses import dataclass, field
from typing import List, Optional
from wrolpi.errors import ValidationError
@dataclass
class FilesRequest:
directories: List[str] = field(default_factory=list)
@dataclass
class FileRequest:
file: str
skip_tracking: bool = False
@dataclass
class DeleteRequest:
paths: List[str] = field(default_factory=list)
force: bool = False
@dataclass
class DeleteFileGroupsRequest:
file_group_ids: List[int] = field(default_factory=list)
force: bool = False
@dataclass
class FilesSearchRequest:
search_str: Optional[str] = None
limit: Optional[int] = 20
offset: Optional[int] = 0
mimetypes: List[str] = field(default_factory=list)
model: Optional[str] = None
tag_names: List[str] = field(default_factory=list)
headline: bool = False
months: Optional[List[int]] = None
from_year: Optional[int] = None
to_year: Optional[int] = None
any_tag: bool = False
order: Optional[str] = None
url: Optional[str] = None # Filter by URL (partial match)
suffix: Optional[str] = None # Filter by primary file suffix (e.g. ".bin"), case-insensitive exact match
path: Optional[str] = None # Filter by primary_path (case-insensitive partial match)
deep: bool = False # When True, search all text including captions/body (d_text)
def __post_init__(self):
if self.any_tag and self.tag_names:
raise ValidationError('Cannot use both tag_names and any_tag.')
@dataclass
class FilesRefreshRequest:
paths: Optional[List[str]] = None
@dataclass
class DirectoriesRequest:
search_str: Optional[str] = ''
@dataclass
class DirectoriesSearchRequest:
path: str
@dataclass
class DirectoriesResponse:
directories: List[str]
@dataclass
class TagFileGroupPost:
tag_name: Optional[str] = None
tag_id: Optional[int] = None
file_group_id: Optional[int] = None
file_group_primary_path: Optional[str] = None
@dataclass
class Directory:
path: str
@dataclass
class Move:
destination: str
paths: List[str] = field(default_factory=list)
@dataclass
class Rename:
path: str
new_name: str
@dataclass
class BulkTagPreviewRequest:
"""Request to preview bulk tagging operation."""
paths: List[str] = field(default_factory=list)
@dataclass
class BulkTagApplyRequest:
"""Request to apply bulk tagging operation."""
paths: List[str] = field(default_factory=list)
add_tag_names: List[str] = field(default_factory=list)
remove_tag_names: List[str] = field(default_factory=list)
@dataclass
class ArchiveContentsRequest:
path: str