feat(google_search): fall back to SearXNG when Google walls every IP - #1643
Conversation
|
@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
fetch_serp_htmlreturns nothing and the scraper drops that page and stops paging. This adds a bundled SearXNG instance as a last-resort provider so a walled run returns organic results instead of an empty one.platforms/google_search/searxng.pyqueries the instance's JSON API and builds aSerpItemdirectly, translating only what SearXNG actually honors:site:, exact-match quoting,languageCode→language, and plainquickDateRangeunits →time_range. Compound codes likem6are dropped rather than approximated, and results are capped at 10 so a fallback page never looks anomalously large to a caller that is paging._serp_page_flow, the single seam every caller shares, so REST, MCP, the playground, and the chat subagent all get the fallback without surface-specific code.focusOnPaidAds(aggregators serve no ads), a URL whoseqcould not be read, or noSEARXNG_URLconfigured — in which case behavior is exactly as before.resultsProvider: "searxng", and_search_query_stampgained adomainoverride sosearchQuery.domainreadssearxnginstead of claiminggoogle.com. The label is the provider name, not the configured host, which is usually a private address that should not reach API output.billable_unitsnow skips items carryingresultsProvider. A fallback page costs no proxy render and no captcha solve, so it is not charged at the Google SERP rate; the pre-flight gate still reserves worst case, since a fallback cannot be predicted before trying.google_searchsubagent prompt now requires disclosing fallback provenance and forbids describing those items as Google rankings or positions.searxngservice to the prod, dev, and deps-only stacks on a pinned image with a healthcheck, and injectsSEARXNG_URL(defaulthttp://searxng:8080) intobackendandcelery_worker. Deliberately nodepends_on, so an unhealthy SearXNG can never block backend startup — it is a fallback, not a dependency.docker/searxng/settings.ymlandlimiter.toml. Two entries there are load-bearing:jsoninsearch.formats, without which every fallback request 403s, and thegoogleengine explicitly disabled, since this instance only runs after Google walled us and would query it from the same address.install.shandinstall.ps1create thesearxng/directory and fetch both config files, so a fresh self-hosted install is complete..env.examplefiles documentSEARXNG_URLandSEARXNG_TIMEOUT_Swith how to point at an external instance or disable the fallback, plusSEARXNG_PORTfor the port the dev and deps-only stacks expose.web-search.mdxdocuments the bundled fallback and corrects the stale note claiming SearXNG was removed entirely.settings.ymlknob to fix.resultsProviderreaching the run payload.Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR adds an optional SearXNG fallback mechanism for the Google Search scraper to provide organic search results when Google walls all proxy IPs. The fallback is controlled via environment variables (
SEARXNG_FALLBACK_URLand timeout settings) and only activates after Google's retry attempts are exhausted. Fallback results are tagged withresultsProvider: "searxng"to distinguish them from native Google results, and they are not billed at the Google SERP rate. The implementation includes Docker configuration files for running a SearXNG instance, core fallback logic that maps aggregator responses to the existingSerpItemschema (organic results and suggestions only, no ads or PAA), and comprehensive unit tests to verify the fallback wiring and edge cases.⏱️ Estimated Review Time: 30-90 minutes
💡 Review Order Suggestion
surfsense_web/content/docs/how-to/web-search.mdxdocker/searxng/settings.ymldocker/searxng/limiter.tomlsurfsense_backend/app/proprietary/platforms/google_search/searxng.pysurfsense_backend/app/proprietary/platforms/google_search/scraper.pysurfsense_backend/app/capabilities/google_search/scrape/schemas.pysurfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/google_search/system_prompt.mdsurfsense_backend/tests/unit/platforms/google_search/test_searxng_fallback.py