API: extraction/alternative
better-web-search-mcp / extraction/alternative
extraction/alternative#
Interfaces#
AlternativeDeps#
Defined in: src/extraction/alternative.ts:30
Injectable dependencies, defaulting to the real modules.
Properties#
| Property | Type | Description | Defined in |
|---|---|---|---|
aggregateSearch? | (query, opts) => Promise<SearchResult[]> | Search aggregator used for snippet fallback. | src/extraction/alternative.ts:34 |
cache? | Cache | Page cache consulted before fetching each variant. | src/extraction/alternative.ts:36 |
fetchPage? | (url, opts) => Promise<FetchedPage> | Page fetcher used for URL variants. | src/extraction/alternative.ts:32 |
Variables#
MAX_SNIPPET_CHARS#
constMAX_SNIPPET_CHARS:200=200
Defined in: src/extraction/alternative.ts:27
Maximum snippet length for page-variant evidence.
MAX_SNIPPETS#
constMAX_SNIPPETS:3=3
Defined in: src/extraction/alternative.ts:24
Maximum number of search snippets kept as evidence.
SNIPPET_CONFIDENCE#
constSNIPPET_CONFIDENCE:0.6=0.6
Defined in: src/extraction/alternative.ts:18
Confidence assigned to search-snippet evidence.
VARIANT_CONFIDENCE#
constVARIANT_CONFIDENCE:0.6=0.6
Defined in: src/extraction/alternative.ts:21
Confidence assigned to a successfully fetched URL variant.
Functions#
buildAlternativeUrls()#
buildAlternativeUrls(
url):string[]
Defined in: src/extraction/alternative.ts:53
Build the URL variants to try: original, ?output=1, /amp, ?amp.
Query strings are preserved and extended with & when present; the /amp
variant is inserted before the query. Returns the original URL alone when
it cannot be parsed.
Parameters#
| Parameter | Type |
|---|---|
url | string |
Returns#
string[]
buildSearchQueries()#
buildSearchQueries(
url,title):string[]
Defined in: src/extraction/alternative.ts:78
Build the search queries for snippet fallback.
With a title: quoted exact title, site-restricted quoted title, and
title + domain keywords. Without a title: a bare site: query so the
domain is still searched.
Parameters#
| Parameter | Type |
|---|---|
url | string |
title | string | null |
Returns#
string[]
findAlternativeSources()#
findAlternativeSources(
url,title,deps?):Promise<Evidence[]>
Defined in: src/extraction/alternative.ts:167
Discover alternative sources for a blocked or low-confidence page.
- Tries URL variants (
?output=1,/amp,?amp) via fetchPage, cache-aware, returning the first usable variant as page evidence. - If every variant is blocked, runs aggregateSearch with the
quoted title, a
site:-restricted query, and title + domain keywords. - Treats the top MAX_SNIPPETS search results as
search_snippetevidence at confidence SNIPPET_CONFIDENCE.
Never throws on empty or failing searches — it returns [].
Parameters#
| Parameter | Type |
|---|---|
url | string |
title | string | null |
deps | AlternativeDeps |
Returns#
Promise<Evidence[]>