OpenSERP Documentation

repository·main·Indexed 22 days ago

https://github.com/karust/openserp

An open-source SERP (Search Engine Results Page) API and CLI providing structured search results from engines including Google, Bing, and DuckDuckGo. Designed for LLM agents, SEO tools, and RAG systems, it features multi-engine 'Megasearch', URL content extraction, and official SDKs for JavaScript/TypeScript and Python. Supports both self-hosted deployment via Docker or Go and a managed hosted API.

Tokens
11.7K
Snippets
41
Records
65
Agent score
77%

What's inside OpenSERP

  1. Understand OpenSERP execution modes

    main

    OpenSERP supports two primary execution modes for extracting search results from engines like Google, Yandex, Baidu, Bing, DuckDuckGo, and Ecosia:

    1. Browser mode (Default): Uses headless Chromium via go-rod. This is the most compatible path and is supported by all engines.
    2. Raw HTTP mode: Uses direct HTTP requests and goquery for parsing. This is currently only supported by Google, Yandex, Baidu, and Ecosia.

    Use Browser mode if you encounter parsing issues or need compatibility with engines that do not support Raw HTTP mode.

  2. Megasearch Modes

    main

    When using the /mega/search or /mega/image endpoints, you can specify a mode to control how engines are queried:

    ModeBehavior
    balancedQueries engines in parallel and merges results. Best for most multi-engine workflows.
    fastUses the fastest available engine. Best for lowest latency.
    anyTries engines sequentially until one responds. Best for fallback-style availability checking.
  3. Resilience and Error Handling

    main

    OpenSERP uses a resilience stack to protect requests in this order:

    1. Engine rate limiter
    2. Retry with backoff
    3. Circuit breaker
    4. Proxy policy and proxy health
    5. Response cache

    Critical Error Behavior:

    • ErrCaptcha: This error is non-retryable. If a captcha is encountered, the request will fail immediately.
    • Fallback: Dedicated endpoints are engine-pure by default. Fallback to other engines is only enabled if resilience.allow_endpoint_fallback is configured. Fallback responses are not cached on dedicated endpoints.
  4. Structure of an engine package

    main

    A complete OpenSERP engine package typically follows this structure:

    • url.go: Pure URL builders (should reject empty queries).
    • selectors.go: Stable selectors used by browser mode, raw mode, and parser tests. Tip: Prefer stable data attributes over generated CSS classes. If a selector is fragile, provide 2-3 explicit fallbacks here.
    • parse_html.go: Implementation of ParseHTML(io.Reader) using goquery.
    • search.go: Browser-mode implementation using core.Browser.
    • search_raw.go: (Optional) Raw HTTP implementation.
    • features.go: (Optional) Extraction of specific SERP features.
    • *_test.go and testdata/: URL and parser fixtures for testing.
  5. How Mega Search works

    main

    The /mega/search and /mega/image endpoints execute multiple engines in parallel to provide a unified view of search results.

    Key behaviors:

    • Engine Selection: Uses the engines query parameter if provided; otherwise, it queries all configured engines.
    • Partial Success: If some engines fail, the request still succeeds. Failed engines are listed in meta.engines_failed.
    • Deduplication: Results are deduplicated based on their normalized URL.
    • Clustering: It builds clusters from enriched results before performing flat deduplication. Clusters are sorted by score (descending) and then by best rank (ascending).

    Cluster Score Calculation: sum(1 / rank for each occurrence) / engines_queried (capped at 1.0 and rounded to two decimals).

    GET /mega/search?engines=google,bing&text=query
  6. Install and run OpenSERP via Docker

    main

    You can run the OpenSERP API server using prebuilt Docker images from Docker Hub (karust/openserp).

    To run the server via a single command:

    docker run --rm -p 127.0.0.1:7000:7000 karust/openserp:latest serve -a 0.0.0.0 -p 7000

    Alternatively, use Docker Compose if you have a configuration file ready:

    docker compose up
    docker run --rm -p 127.0.0.1:7000:7000 karust/openserp:latest serve -a 0.0.0.0 -p 7000
  7. Start an OpenSERP server via Docker or Source

    main

    To use the OpenSERP examples locally, you must run a server. By default, examples expect the server to be running on http://localhost:7000. You can start the server using Docker or by building from the Go source code.

    Using Docker

    Run the prebuilt image and map port 7000:

    docker run -p 127.0.0.1:7000:7000 -it karust/openserp serve -a 0.0.0.0 -p 7000

    Using Go Source

    Build and run the binary directly:

    go build -o openserp . && ./openserp serve
  8. Run the Image Gallery example

    main

    This example performs an image search and generates a self-contained gallery.html file that can be opened directly in a web browser to view the results.

    To run the example:

    1. Install dependencies using npm install.
    2. Execute the script with node index.js.
    3. Open the generated gallery.html in your browser.

    To search for different images, edit the query variable inside index.js before running the script.

    npm install
    node index.js
  9. Run the Basic Search Python example

    main

    This example demonstrates how to perform a single Google search using the openserp Python SDK and print the resulting titles and URLs.

    To run the example, install the required dependencies and execute the main script:

    pip install -r requirements.txt
    python main.py

    You can modify the search behavior by editing the following variables in main.py:

    • text: The search query string.
    • engine: The search engine to use (e.g., google).
    • limit: The maximum number of results to return.

    Using the hosted API

    By default, the example is configured to connect to a local server. To switch to the hosted OpenSERP API, uncomment the relevant configuration line at the top of main.py.

  10. Test a new search engine

    main

    New engines require several layers of testing to ensure stability.

    Required Tests for Initial PR

    • URL Builder Tests: Table-driven tests for your url.go logic.
    • Parser Tests: Tests using small, sanitized HTML fixtures to verify ParseHTML logic.
    • Integration Tests: Only include these if necessary, and ensure they are gated with testutil.RequireIntegration(t).

    Running Tests

    To run default tests (which must pass without browser or network access):

    make test

    To run live/browser-based integration checks:

    make test-integration

    Pre-PR Checklist

    Before submitting a Pull Request, run the following to ensure code quality:

    make fmt
    make lint
    make test
  11. Install OpenSERP SDKs and Integrations

    main

    OpenSERP provides official SDKs and integrations for various environments:

    ToolPackageInstall Command
    JavaScript / TypeScript@openserp/sdknpm install @openserp/sdk
    Pythonopenserppip install openserp
    MCP server (AI agents)@openserp/mcpnpx @openserp/mcp
    n8n community node@openserp/n8n-nodes-openserpInstall via n8n community nodes