SearXNG User Guide

Overview

SearXNG is a privacy-focused metasearch engine that aggregates results from multiple search engines without tracking you. This guide covers both web interface usage and API access for AI agents.

Web Interface

Accessing SearXNG

Open your browser and navigate to:

https://search.haiven.local
  1. Enter your search query in the search box
  2. Press Enter or click the search icon
  3. Results are aggregated from multiple engines

Search Categories

Click the tabs to switch between categories:

Category Description
General Web pages from Google, Bing, DuckDuckGo, etc.
Images Image search results
Videos Video content from YouTube, etc.
News Recent news articles
IT Technical content from GitHub, Stack Overflow
Files File downloads and archives
Science Academic papers from arXiv, PubMed
Maps Geographic information

Search Syntax

Syntax Example Description
!bang !g python Search Google only
site: site:github.com docker Limit to specific site
"quotes" "exact phrase" Exact phrase match
-exclude python -snake Exclude term

Preferences

Click the gear icon to customize:
- Default language
- Safe search level
- Result display options
- Theme (light/dark/auto)
- Enabled search engines

JSON API

API Endpoint

POST https://search.haiven.local/search
POST http://searxng:8080/search (internal)

Parameters

Parameter Required Description Example
q Yes Search query docker networking
format No Output format json, csv, rss
categories No Categories to search general,it
engines No Specific engines google,github
language No Language code en-US
pageno No Page number 1, 2, 3
time_range No Time filter day, week, month, year
safesearch No Safety level 0 (off), 1 (moderate), 2 (strict)

Example Requests

Basic Search

curl -X POST "https://search.haiven.local/search" \
  -d "q=docker best practices&format=json"
# Search news from last 24 hours
curl -X POST "https://search.haiven.local/search" \
  -d "q=artificial intelligence&format=json&categories=news&time_range=day"
# Search only GitHub and Stack Overflow
curl -X POST "https://search.haiven.local/search" \
  -d "q=python async await&format=json&engines=github,stackoverflow"

Response Format

{
  "query": "docker networking",
  "number_of_results": 127,
  "results": [
    {
      "title": "Docker Networking Overview",
      "url": "https://docs.docker.com/network/",
      "content": "Docker's networking subsystem is pluggable...",
      "engine": "google",
      "score": 1.0,
      "category": "general"
    }
  ],
  "suggestions": ["docker network types", "docker bridge network"],
  "answers": [],
  "infoboxes": []
}

Python Integration

Basic Usage

import requests

def search(query, categories="general"):
    response = requests.post(
        "http://searxng:8080/search",
        data={
            "q": query,
            "format": "json",
            "categories": categories
        },
        timeout=10
    )
    return response.json()

# Example usage
results = search("python web scraping")
for r in results.get("results", [])[:5]:
    print(f"{r['title']}: {r['url']}")

With Error Handling

import requests
from functools import lru_cache

@lru_cache(maxsize=100)
def cached_search(query: str, categories: str = "general"):
    """Search with caching to reduce API calls."""
    try:
        response = requests.post(
            "http://searxng:8080/search",
            data={
                "q": query,
                "format": "json",
                "categories": categories,
                "safesearch": "1"
            },
            timeout=15
        )
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        return {"error": str(e), "results": []}

LLM Tool Integration

def web_search_tool(query: str, max_results: int = 5) -> list:
    """
    Web search tool for LLM function calling.

    Args:
        query: Search query string
        max_results: Maximum results to return

    Returns:
        List of search results with title, url, and snippet
    """
    response = requests.post(
        "http://searxng:8080/search",
        data={"q": query, "format": "json"},
        timeout=10
    )

    results = response.json().get("results", [])

    return [
        {
            "title": r.get("title", ""),
            "url": r.get("url", ""),
            "snippet": r.get("content", "")[:200]
        }
        for r in results[:max_results]
    ]

Shell Usage

# Search and format with jq
curl -s -X POST "https://search.haiven.local/search" \
  -d "q=kubernetes deployment&format=json" | \
  jq '.results[:3] | .[] | {title, url}'

News Headlines

# Get today's tech news
curl -s -X POST "https://search.haiven.local/search" \
  -d "q=technology&format=json&categories=news&time_range=day" | \
  jq '.results[:5] | .[] | .title'

Image URLs

# Get image URLs
curl -s -X POST "https://search.haiven.local/search" \
  -d "q=mountain landscape&format=json&categories=images" | \
  jq '.results[:5] | .[] | .img_src'

Available Search Engines

General Web

Images

Videos

News

IT/Development

Science

Reference

Troubleshooting

No Results

  1. Check if upstream engines are accessible:
docker compose logs searxng | grep -i "error"
  1. Try a different search category or engine

  2. Check network connectivity:

docker exec searxng ping -c 3 google.com

Slow Searches

  1. Verify Redis is working:
docker exec searxng-redis redis-cli ping
  1. Reduce concurrent connections in settings.yml

Rate Limited (429 Error)

The limiter is disabled for private instances. If you see 429 errors:

  1. Check if accessing from trusted network
  2. Restart the container:
docker compose restart searxng

Privacy Notes

Additional Resources