An open source, non-profit web search engine
Super Search v2: add recipe smoke validator + first 5 generated recipes
Daoud Clarkefc29bb91c995
diff --git a/mwmbl/tinysearchengine/super_search_sources/recipes/99percentinvisible_org.yaml b/mwmbl/tinysearchengine/super_search_sources/recipes/99percentinvisible_org.yamlnew file mode 100644index 0000000..33cb0b9--- /dev/null+++ b/mwmbl/tinysearchengine/super_search_sources/recipes/99percentinvisible_org.yaml@@ -0,0 +1,18 @@+# 99% Invisible via the WordPress REST API search endpoint.+name: 99percentinvisible_org+domain: 99percentinvisible.org+field: art-design+request:+ url: https://99percentinvisible.org/wp-json/wp/v2/search+ params:+ search: "{query}"+ per_page: "{limit}"+response:+ format: json+ results: ""+ fields:+ title: title+ url: url+smoke:+ query: design+ expect_title_contains: designdiff --git a/mwmbl/tinysearchengine/super_search_sources/recipes/acoup_blog.yaml b/mwmbl/tinysearchengine/super_search_sources/recipes/acoup_blog.yamlnew file mode 100644index 0000000..0477514--- /dev/null+++ b/mwmbl/tinysearchengine/super_search_sources/recipes/acoup_blog.yaml@@ -0,0 +1,23 @@+# ACOUP (A Collection of Unmitigated Pedantry) - popular history blog via HTML scraping.+name: acoup_blog+domain: acoup.blog+field: history+request:+ url: https://acoup.blog/+ params:+ s: "{query}"+response:+ format: html+ results: "article.post"+ base_url: https://acoup.blog+ fields:+ title:+ selector: "h1.entry-title a"+ extract:+ selector: "p"+ url:+ selector: "h1.entry-title a"+ attr: href+smoke:+ query: history+ expect_title_contains: historydiff --git a/mwmbl/tinysearchengine/super_search_sources/recipes/help_archive_org.yaml b/mwmbl/tinysearchengine/super_search_sources/recipes/help_archive_org.yamlnew file mode 100644index 0000000..a3d0751--- /dev/null+++ b/mwmbl/tinysearchengine/super_search_sources/recipes/help_archive_org.yaml@@ -0,0 +1,17 @@+name: help_archive_org+domain: help.archive.org+field: other+request:+ url: https://help.archive.org/wp-json/wp/v2/search+ params:+ search: "{query}"+ per_page: "{limit}"+response:+ format: json+ results: ""+ fields:+ title: title+ url: url+smoke:+ query: wayback+ expect_title_contains: Waybackdiff --git a/mwmbl/tinysearchengine/super_search_sources/recipes/pluralistic_net.yaml b/mwmbl/tinysearchengine/super_search_sources/recipes/pluralistic_net.yamlnew file mode 100644index 0000000..88f1d45--- /dev/null+++ b/mwmbl/tinysearchengine/super_search_sources/recipes/pluralistic_net.yaml@@ -0,0 +1,17 @@+name: pluralistic_net+domain: pluralistic.net+field: news-politics+request:+ url: https://pluralistic.net/wp-json/wp/v2/search+ params:+ search: "{query}"+ per_page: "{limit}"+response:+ format: json+ results: ""+ fields:+ title: title+ url: url+smoke:+ query: surveillance+ expect_title_contains: Surveillancediff --git a/mwmbl/tinysearchengine/super_search_sources/recipes/stratechery_com.yaml b/mwmbl/tinysearchengine/super_search_sources/recipes/stratechery_com.yamlnew file mode 100644index 0000000..8ef1d00--- /dev/null+++ b/mwmbl/tinysearchengine/super_search_sources/recipes/stratechery_com.yaml@@ -0,0 +1,21 @@+# Stratechery via the WordPress REST API posts endpoint.+name: stratechery_com+domain: stratechery.com+field: business-finance+request:+ url: https://stratechery.com/wp-json/wp/v2/posts+ params:+ search: "{query}"+ per_page: "{limit}"+response:+ format: json+ results: ""+ fields:+ title: title.rendered+ extract: excerpt.rendered+ url: link+ strip_html:+ - extract+smoke:+ query: strategy+ expect_title_contains: strategydiff --git a/scripts/smoke_recipe.py b/scripts/smoke_recipe.pynew file mode 100644index 0000000..ca6db30--- /dev/null+++ b/scripts/smoke_recipe.py@@ -0,0 +1,70 @@+#!/usr/bin/env python3+"""Live smoke-test a single Super Search recipe YAML file.++Loads the recipe, runs it against the real site with its `smoke.query`, and+checks that some result's title contains `smoke.expect_title_contains`.++Usage:+ uv run python scripts/smoke_recipe.py path/to/recipe.yaml++Prints "PASS <name>" or "FAIL <name>: <reason>" and exits 0/1 accordingly.+"""+import asyncio+import os+import sys+from pathlib import Path++REPO_ROOT = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(REPO_ROOT))+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mwmbl.settings_dev")++import django # noqa: E402++django.setup()++import httpx # noqa: E402++from mwmbl.tinysearchengine.super_search_sources.recipe import ( # noqa: E402+ load_recipe,+ search_with_recipe,+)+++async def _run(path: str) -> int:+ recipe = load_recipe(path)+ name = recipe.name+ smoke = recipe.smoke or {}+ query = smoke.get("query")+ expect = (smoke.get("expect_title_contains") or "").lower()+ if not query or not expect:+ print(f"FAIL {name}: missing smoke.query / expect_title_contains")+ return 1+ try:+ async with httpx.AsyncClient(+ follow_redirects=True, timeout=15.0,+ headers={"User-Agent": "mwmbl-super-search-smoke/0.1 (+https://mwmbl.org)"},+ ) as client:+ docs = await search_with_recipe(client, recipe, query, 10)+ except Exception as e: # noqa: BLE001+ print(f"FAIL {name}: request error {e!r}")+ return 1+ if not docs:+ print(f"FAIL {name}: no results for {query!r}")+ return 1+ if not any(expect in (d.title or "").lower() for d in docs):+ titles = ", ".join((d.title or "")[:40] for d in docs[:3])+ print(f"FAIL {name}: no title contains {expect!r} (got: {titles})")+ return 1+ print(f"PASS {name}: {len(docs)} results")+ return 0+++def main() -> int:+ if len(sys.argv) != 2:+ print("usage: smoke_recipe.py <recipe.yaml>", file=sys.stderr)+ return 2+ return asyncio.run(_run(sys.argv[1]))+++if __name__ == "__main__":+ sys.exit(main())