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

@ -685,7 +685,7 @@ async def test_search_videos_default_page_pagination(test_session, video_factory
await assert_video_search(order_by='-published_datetime', assert_total=6)
assert fast_path.called, 'the unfiltered date-ordered page should take the fast path'
fast_path.reset_mock()
await assert_video_search(order_by='-published_datetime', search_str='a', assert_total=1)
await assert_video_search(order_by='-published_datetime', search_str='b', assert_total=1)
await assert_video_search(order_by='-size', assert_total=6)
assert not fast_path.called, 'searches and other orders use the generic query'
@ -786,3 +786,14 @@ async def test_video_json_does_not_read_info_json(async_client, test_session, vi
request, response = await async_client.get(f'/api/videos/{video.file_group_id}')
assert response.status_code == HTTPStatus.OK
assert 'description' not in response.json['file_group']['video']
@pytest.mark.asyncio
async def test_search_videos_stopwords(test_session, video_factory, assert_video_search):
"""Stopwords are dropped from a search; a search of only stopwords matches nothing (as Postgres did)."""
solar = video_factory(title='the solar panel', with_video_file=True)
video_factory(title='the garden', with_video_file=True)
test_session.commit()
await assert_video_search(search_str='the', assert_ids=[])
await assert_video_search(search_str='the solar', assert_ids=[solar.id])