DEV Community

Zane
Zane

Posted on

Discover the Magic of SearXNG Service and Empower Your Search Engine API

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.

Why Choose SearXNG Service?

SearXNG Service is more than just a tool; it's your search companion, making your development work more efficient and enjoyable.

  1. Unlimited Customization: Adjust search parameters according to your needs. Choose from various categories, engines, and locales to get precise search results.
  2. Ease of Use: From installation to usage, the entire process is straightforward and hassle-free, allowing you to get started quickly.
  3. Multi-Format Support: Retrieve search results in JSON, CSV, and RSS formats, making your application versatile and adaptable to different scenarios.

Installation and Configuration

One-Click Installation

Install the SearXNG Service with a single command:

npm install searxng
Enter fullscreen mode Exit fullscreen mode

Configuration Setup

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);
Enter fullscreen mode Exit fullscreen mode

Types and Parameters

Categories

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
  ;
Enter fullscreen mode Exit fullscreen mode

Engines and Locales

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
  ;
Enter fullscreen mode Exit fullscreen mode

Methods

Use the search method to start your exploration journey:

async search(
  input: string,
  params?: Partial<SearxngSearchParameters>,
): Promise<SearxngSearchResults>
Enter fullscreen mode Exit fullscreen mode

Example: Basic Search

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();
Enter fullscreen mode Exit fullscreen mode

Example: Search with Parameters

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();
Enter fullscreen mode Exit fullscreen mode

Conclusion

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!

Top comments (0)