In the age of information overload, having a powerful and flexible search tool is like holding a magic key to explore the web. Today, we bring you such a magical key—the SearXNG Service. This TypeScript-based service seamlessly interacts with the SearXNG search engine API, allowing you to perform searches and retrieve results in various formats. Whether you're developing a cool web application or need robust backend search support, the SearXNG Service is your ideal solution.
SearXNG Service is more than just a tool; it's your search companion, making your development work more efficient and enjoyable.
Install the SearXNG Service with a single command:
npm install searxng
Import and configure the SearXNG Service to start using it:
import { SearxngService, type SearxngServiceConfig } from 'searxng'; const config: SearxngServiceConfig = { baseURL: 'https://your-searxng-instance.com', defaultSearchParams: { format: 'json', lang: 'auto', }, defaultRequestHeaders: { 'Content-Type': 'application/json', }, }; const searxngService = new SearxngService(config);
Choose from a wide range of categories to refine your search results:
export type SearxngCategory = | 'general' | 'web' | 'images' | 'videos' | 'news' | 'music' // Add more categories as needed ;
Select your preferred search engines and locales to customize your search experience:
export type SearxngEngine = | 'google' | 'bing' | 'duckduckgo' // Add more engines ; export type SearxngLocale = | 'en' | 'es' | 'fr' // Add more locales ;
Use the search method to start your exploration journey:
async search( input: string, params?: Partial<SearxngSearchParameters>, ): Promise<SearxngSearchResults>
Perform a simple search to see the power of the magic key:
async function performSearch() { try { const results = await searxngService.search('example query'); console.log(results); } catch (error) { console.error('Search failed:', error); } } performSearch();
Perform a more refined search with additional parameters:
async function performSearchWithParams() { const searchParams = { categories: ['general', 'web'], engines: ['google', 'bing'], lang: 'en', pageno: 2, time_range: 'month', format: 'json', }; try { const results = await searxngService.search('example query', searchParams); console.log(results); } catch (error) { console.error('Search failed:', error); } } performSearchWithParams();
SearXNG Service is more than just a tool; it's your search magic wand, making complex searches simple and fun. Whether you're a developer or a tech enthusiast, SearXNG Service can help you achieve more powerful search capabilities. Install the SearXNG Service today and start your magical search journey!
The above is the detailed content of Discover the Magic of SearXNG Service and Empower Your Search Engine API. For more information, please follow other related articles on the PHP Chinese website!