Skip to content

fix(search): honor the configured locale in Bing and DuckDuckGo scrapes - #6860

Open
asto18089 wants to merge 1 commit into
codewhale-hq:mainfrom
asto18089:upstream/scrape-locale
Open

asto18089 wants to merge 1 commit into
codewhale-hq:mainfrom
asto18089:upstream/scrape-locale

Conversation

@asto18089

Copy link
Copy Markdown
Contributor

Summary

The keyless Bing and DuckDuckGo scrapes ignored the configured search locale — Bing sent only q, DDG the same — while Firecrawl/Serply/SearXNG honored the knob, so locale-scoped queries silently returned wrong-region results.

  • Bing: now receives mkt=<market> plus setlang derived from BCP 47 (explicit script subtag wins; otherwise zh-TW/HK/MO → zh-Hant, else zh-Hans, since bare zh is invalid for Bing) and a matching Accept-Language.
  • DuckDuckGo: receives kl only for verified region pairs (cn-zh, us-en, jp-jp, kr-kr, tw-tzh, hk-tzh, including script+region Chinese variants); anything else sends no kl rather than an off-list guess, and is receipted as ignored. Shared Accept-Language threading through the existing fetch helper.
  • When locale is omitted, a Han-script query falls back to zh-CN unless kana/hangul veto it; model-supplied locales are shape-checked, and malformed values keep the historical request shape.
  • The DDG→Bing fallback re-derives the ignored flag from Bing's rule on both fallback paths, preserving Web search: configured API providers lose their fallback in DuckDuckGo-unreachable networks — tail the chain with Bing instead? #6746's fallback semantics. Both backends declare locale support; both model-visible schemas state the BCP 47 format.

Tests: per-locale param derivation, the verified kl table (including script+region), the Han fallback and its kana/hangul veto, shape checks, fallback re-derivation, receipt honesty, and an exhaustive per-provider capability table.

Testing

  • cargo test -p codewhale-tui --lib web_search web::backend
  • cargo clippy -p codewhale-tui --all-targets --all-features --locked
  • cargo fmt --all -- --check

Disclosures: the in-function flag-push/prune wiring and the emitted URL params are not covered by a networked test (the existing wiremock suites run with locale unset) — the pure helpers, the receipt contract, and the capability table are. With no resolvable market on the DDG leg, Accept-Language changes from en-US,en;q=0.5 to the unified en-US,en;q=0.9 (in-code comment).

Adapted from the Pinvou fork's surface-alignment audit (Pinvou/CodeWhale 6f780290f, the scrape-locale slice), integrated with the current backend chain (Serply, #6746 fallback).

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • No CHANGELOG.md changes

@asto18089
asto18089 requested a review from Hmbown as a code owner October 5, 2026 11:52
@github-actions github-actions Bot added the contribution-gate Author not yet in .github/APPROVED_CONTRIBUTORS; a maintainer grants access with /lgtm label Oct 5, 2026
The keyless Bing and DuckDuckGo scrape backends ignored the configured
search locale: run_bing_search sent only `q` and duckduckgo_search_url
likewise, so locale-scoped queries silently returned wrong-region
results while Firecrawl, Serply, and SearXNG honored the same knob.

Bing now receives `mkt=<locale>` plus a `setlang` derived from the BCP
47 tag: an explicit script subtag wins, otherwise the script is picked
from the region (zh-TW/zh-HK/zh-MO map to zh-Hant, everything else to
zh-Hans) because a bare `zh` is invalid for Bing. Both scrapes send an
Accept-Language header matching the resolved market, without
duplicating the generic `en` range for English markets.

DuckDuckGo receives `kl` only for the verified region pairs (cn-zh,
us-en, jp-jp, kr-kr, tw-tzh, hk-tzh, including the script+region
Chinese forms); anything else sends no `kl` at all rather than an
off-list guess, and the receipt reports the missing region signal as
ignored instead of claiming the knob was honored.

When the model omits `locale`, a query containing Han ideographs falls
back to the zh-CN market - a locale-less Chinese query previously got
an English Accept-Language and unrelated Japanese results - unless the
query also carries kana or hangul, which would push Japanese or Korean
queries onto the Chinese market. A model-supplied locale is
shape-checked before it reaches URLs or headers: malformed values keep
the historical request shape and are receipted as ignored.

On the DuckDuckGo-to-Bing fallback the stale DDG-leg ignored flag is
re-derived from Bing's own rule so the receipt describes the backend
that actually produced the results, and both scrape backends now
declare locale support in their query capabilities. The model-visible
web and web_search schemas state the BCP 47 format and which backend
honors what.

Signed-off-by: asto <asto18089@126.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution-gate Author not yet in .github/APPROVED_CONTRIBUTORS; a maintainer grants access with /lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants