Feature: Show the AA search result stats (#1362)

When doing a direct search for a book, show the stats of the AA results.
For example if we search for "The Great Gatsby", AA reports it has 240
hits and shows the first page of 50. Provide this stats info in the
shelfmark webUI via ResultsSection.tsx and ReleaseModal.tsx. This table
shows what should be displayed based on the total number of hits found:

|Total	|Display|
|-------|-------|
|1	|"Result 1 (1 Total)"|
|6	|"Results 1-6 (6 Total)"|
|144	|"Results 1-50 (144 Total)"|
|500+	|"Results 1-50 (500+ Total)"|

Currently, shelfmark also only shows us the first 50 search hits even if
there were more available from AA. This could be added later if
considered desirable.

As usual, a picture is worth a 1000 words:

<img width="1012" height="610" alt="direct-results-stat"
src="https://github.com/user-attachments/assets/8c0c688f-444e-482a-a9a3-2dee5a5563b8"
/>

<img width="1013" height="741" alt="universal-results-info"
src="https://github.com/user-attachments/assets/399bbb79-87f2-4432-a3d0-64937795f5f1"
/>

Coded with llama.cpp, opencode and 🤖
This commit is contained in:
Paul Rimmer
2026-09-20 13:03:32 -04:00
committed by GitHub
parent c1315a2b23
commit d4619be69a
14 changed files with 181 additions and 56 deletions
+3 -3
View File
@@ -99,7 +99,7 @@ def test_title_variants_stop_once_the_budget_is_spent(monkeypatch):
deadline = search_deadline.current()
if deadline is not None:
deadline.event.set()
return []
return ([], None)
monkeypatch.setattr(aa, "search_books", fake_search_books)
monkeypatch.setattr(aa, "ensure_available", lambda: None)
@@ -114,7 +114,7 @@ def test_title_variants_stop_once_the_budget_is_spent(monkeypatch):
def test_all_title_variants_run_within_budget(monkeypatch):
queries: list[str] = []
monkeypatch.setattr(aa, "search_books", lambda q, _f: queries.append(q) or [])
monkeypatch.setattr(aa, "search_books", lambda q, _f: queries.append(q) or ([], None))
monkeypatch.setattr(aa, "ensure_available", lambda: None)
source = dd.DirectDownloadSource()
@@ -135,7 +135,7 @@ def test_language_filter_retry_is_skipped_on_a_spent_budget(monkeypatch):
deadline = search_deadline.current()
if deadline is not None:
deadline.event.set()
return []
return ([], None)
monkeypatch.setattr(aa, "search_books", fake_search_books)
monkeypatch.setattr(aa, "ensure_available", lambda: None)
+8 -8
View File
@@ -33,7 +33,7 @@ class TestDirectDownloadSearchQueries:
def fake_search_books(query: str, filters):
captured.append(query)
return []
return ([], None)
_enable_direct_download(monkeypatch)
@@ -75,7 +75,7 @@ class TestDirectDownloadSearchQueries:
def fake_search_books(query: str, filters):
captured.append((query, filters.lang))
return records_by_query[query]
return (records_by_query[query], None)
_enable_direct_download(monkeypatch)
@@ -118,8 +118,8 @@ class TestDirectDownloadSearchQueries:
def fake_search_books(query: str, filters):
captured.append((query, filters.lang))
if filters.lang:
return []
return fallback_results[query]
return ([], None)
return (fallback_results[query], None)
_enable_direct_download(monkeypatch)
@@ -156,8 +156,8 @@ class TestDirectDownloadSearchQueries:
def fake_search_books(query: str, filters):
captured.append((query, filters.lang, filters.format))
if filters.lang:
return []
return [_browse_record("manual-1", "Manual result")]
return ([], None)
return ([_browse_record("manual-1", "Manual result")], None)
_enable_direct_download(monkeypatch)
@@ -336,7 +336,7 @@ def test_search_books_filters_locally_when_path_language_enabled(monkeypatch):
monkeypatch.setattr(aa.downloader, "html_get_page", _fake_html_get_page)
records = aa.search_books("demo", SearchFilters(lang=["fr"], format=["pdf"]))
records, _ = aa.search_books("demo", SearchFilters(lang=["fr"], format=["pdf"]))
assert "&lang=" not in captured_url["url"]
assert len(records) == 1
@@ -380,7 +380,7 @@ def test_search_books_keeps_server_language_matches_when_path_language_disabled(
monkeypatch.setattr(aa.downloader, "html_get_page", _fake_html_get_page)
records = aa.search_books("demo", SearchFilters(lang=["en"], format=["pdf"]))
records, _ = aa.search_books("demo", SearchFilters(lang=["en"], format=["pdf"]))
# AA already narrowed by &lang=; its free-text language cells must not be re-matched.
assert "&lang=en" in captured_url["url"]
+1 -1
View File
@@ -22,7 +22,7 @@ def test_warmup_runs_when_nobody_has_searched(monkeypatch):
searched: list[str] = []
monkeypatch.setattr(
"shelfmark.release_sources.direct_download.search_books",
lambda query, _filters: searched.append(query) or ["a result"],
lambda query, _filters: (searched.append(query), ["a result"], None)[1:],
)
assert warmup.run_warmup() is True