API: extraction/alternative

better-web-search-mcp


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#

PropertyTypeDescriptionDefined in
aggregateSearch?(query, opts) => Promise<SearchResult[]>Search aggregator used for snippet fallback.src/extraction/alternative.ts:34
cache?CachePage 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#

const MAX_SNIPPET_CHARS: 200 = 200

Defined in: src/extraction/alternative.ts:27

Maximum snippet length for page-variant evidence.


MAX_SNIPPETS#

const MAX_SNIPPETS: 3 = 3

Defined in: src/extraction/alternative.ts:24

Maximum number of search snippets kept as evidence.


SNIPPET_CONFIDENCE#

const SNIPPET_CONFIDENCE: 0.6 = 0.6

Defined in: src/extraction/alternative.ts:18

Confidence assigned to search-snippet evidence.


VARIANT_CONFIDENCE#

const VARIANT_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#

ParameterType
urlstring

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#

ParameterType
urlstring
titlestring | 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.

  1. Tries URL variants (?output=1, /amp, ?amp) via fetchPage, cache-aware, returning the first usable variant as page evidence.
  2. If every variant is blocked, runs aggregateSearch with the quoted title, a site:-restricted query, and title + domain keywords.
  3. Treats the top MAX_SNIPPETS search results as search_snippet evidence at confidence SNIPPET_CONFIDENCE.

Never throws on empty or failing searches — it returns [].

Parameters#

ParameterType
urlstring
titlestring | null
depsAlternativeDeps

Returns#

Promise<Evidence[]>