Show HN: Multiple web search providers via one TypeScript package
1 month ago
5
A unified TypeScript SDK for integrating with multiple web search providers through a single, consistent interface.
The Search SDK provides a standardized way to interact with various search APIs, allowing developers to easily switch between providers or use multiple providers simultaneously without changing application code.
npm install @plust/search-sdk
import{google,webSearch}from'@plust/search-sdk';// Configure the Google search provider with your API key and Search Engine IDconstconfiguredGoogle=google.configure({apiKey: 'YOUR_GOOGLE_API_KEY',cx: 'YOUR_SEARCH_ENGINE_ID'});// Search using the configured providerasyncfunctionsearch(){constresults=awaitwebSearch({query: 'TypeScript SDK',maxResults: 5,provider: configuredGoogle});console.log(results);}search();
Unified API for working with multiple search providers
import{exa,webSearch}from'@plust/search-sdk';constexaProvider=exa.configure({apiKey: 'YOUR_EXA_API_KEY',model: 'keyword',// Optional, defaults to 'keyword'includeContents: true// Optional, defaults to false});constresults=awaitwebSearch({query: 'machine learning papers',provider: exaProvider});
import{tavily,webSearch}from'@plust/search-sdk';consttavilyProvider=tavily.configure({apiKey: 'YOUR_TAVILY_API_KEY',searchDepth: 'comprehensive',// Optional, defaults to 'basic'includeAnswer: true// Optional, defaults to false});constresults=awaitwebSearch({query: 'climate change evidence',maxResults: 15,provider: tavilyProvider});
import{searxng,webSearch}from'@plust/search-sdk';constsearxngProvider=searxng.configure({baseUrl: 'http://127.0.0.1:8080/search',additionalParams: {// Optional additional parameters for SearXNGcategories: 'general',engines: 'google,brave,duckduckgo'},apiKey: ''// Not needed for most SearXNG instances});constresults=awaitwebSearch({query: 'open source software',provider: searxngProvider});
import{duckduckgo,webSearch}from'@plust/search-sdk';// DuckDuckGo doesn't require an API key, but you can configure other optionsconstduckduckgoProvider=duckduckgo.configure({searchType: 'text',// Optional: 'text', 'images', or 'news'useLite: false,// Optional: use lite version for lower bandwidthregion: 'wt-wt'// Optional: region code});// Text searchconsttextResults=awaitwebSearch({query: 'privacy focused search',maxResults: 10,provider: duckduckgoProvider});// Image searchconstimageProvider=duckduckgo.configure({searchType: 'images'});constimageResults=awaitwebSearch({query: 'landscape photography',maxResults: 10,provider: imageProvider});// News searchconstnewsProvider=duckduckgo.configure({searchType: 'news'});constnewsResults=awaitwebSearch({query: 'latest technology',maxResults: 10,provider: newsProvider});
Arxiv is a repository of electronic preprints of scientific papers. It does not require an API key for its public API.
import{arxiv,webSearch}from'@plust/search-sdk';// Arxiv doesn't require an API key, but you can configure other options.constarxivProvider=arxiv.configure({sortBy: 'relevance',// Optional: 'relevance', 'lastUpdatedDate', 'submittedDate'sortOrder: 'descending'// Optional: 'ascending', 'descending'});constresults=awaitwebSearch({query: 'cat:cs.AI AND ti:transformer',// Example: Search for "transformer" in title within Computer Science AI category// Alternatively, search by ID list:// idList: '2305.12345v1,2203.01234v2', provider: arxivProvider,maxResults: 5});
The webSearch function accepts these standard options across all providers:
Option
Type
Description
query
string
The search query text. For Arxiv, this can be a complex query using field prefixes (e.g., au:del_maestro AND ti:checkerboard).
idList
string
(Arxiv specific) A comma-delimited list of Arxiv IDs to fetch.
maxResults
number
Maximum number of results to return.
language
string
Language code for results (e.g., 'en')
region
string
Country/region code (e.g., 'US'). For DuckDuckGo, use format like 'wt-wt', 'us-en'.
safeSearch
'off' | 'moderate' | 'strict'
Content filtering level (Not applicable to Arxiv). For DuckDuckGo, 'moderate' is default.
page
number
Result page number (for pagination). Arxiv uses start (offset) instead.
start
number
(Arxiv specific) The starting index for results (pagination offset).
sortBy
'relevance' | 'lastUpdatedDate' | 'submittedDate'
(Arxiv specific) Sort order for results.
sortOrder
'ascending' | 'descending'
(Arxiv specific) Sort direction.
searchType
'text' | 'images' | 'news'
(DuckDuckGo specific) The type of search to perform.
timeout
number
Request timeout in milliseconds.
All providers return results in this standardized format:
interfaceSearchResult{url: string;// The URL of the search resulttitle: string;// Title of the web pagesnippet?: string;// Brief description or excerptdomain?: string;// The source website domainpublishedDate?: string;// When the content was publishedprovider?: string;// The search provider that returned this resultraw?: unknown;// Raw provider-specific data}
The SDK includes built-in debugging capabilities to help diagnose issues:
The SDK provides detailed error messages with troubleshooting suggestions:
Search with provider 'google' failed: Google search failed: Request failed with status: 400 Bad Request - Invalid Value
Troubleshooting: This is likely due to invalid request parameters. Check your query and other search options. Make sure your Google API key is valid and has the Custom Search API enabled. Also check if your Search Engine ID (cx) is correct.