Search: drop stopwords from unquoted terms, as Postgres did (#1085)

Postgres' english websearch_to_tsquery dropped stopwords; FTS5 indexes them.
A stopword matches most of the library, so a search containing one read its
whole doclist (slow on a cold HDD) and only found files that happened to
contain it.  translate_websearch now drops Postgres' english stopword list
from unquoted terms; quoted phrases keep them.

A search with nothing left to search (stopwords or punctuation only) now
matches nothing in archive, video and doc search too, as files search, the
search estimates and Postgres already did, instead of listing everything.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-12-03 17:16:36 -07:00 • committed by GitHub
parent a61d528832
commit 45b52a698e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 107 additions and 11 deletions

View file

@ -385,6 +385,9 @@ def _search_docs(session: Session, search_str=None, author=None, subject=None, l
# Deep search matches all FTS columns (including d_text, the document contents); the default matches only
# the much smaller a/b/c columns.
match = fts.translate_websearch(search_str, None if deep else fts.ABC_COLUMNS) if search_str else None
if search_str and match is None:
# Nothing to search (punctuation or stopwords only); match nothing, like an empty websearch_to_tsquery.
return [], 0
query = session.query(FileGroup).options(*FileGroup.json_options()).join(Doc, Doc.file_group_id == FileGroup.id)