### Install and Run Search with Extraction Source: https://github.com/karust/openserp/blob/main/examples/content/js-search-with-extract/README.md Install the necessary dependencies and run the JavaScript example to perform a search with content extraction. ```bash npm install node index.js ``` -------------------------------- ### Install Dependencies and Run Source: https://github.com/karust/openserp/blob/main/examples/ai/python-agent-tool/README.md Install the necessary packages using `requirements.txt` and then run the main script. Ensure you have the `requirements.txt` file in your project directory. ```bash pip install -r requirements.txt python main.py ``` -------------------------------- ### Install OpenSERP and Perform a Search Source: https://github.com/karust/openserp/blob/main/README.md Install the OpenSERP CLI tool using 'go install' and then use it to perform a search query, outputting the results in Markdown format. ```sh go install github.com/karust/openserp@latest openserp search duckduckgo "open source serp api" --format markdown ``` -------------------------------- ### Install Dependencies Source: https://github.com/karust/openserp/blob/main/examples/quickstart/python-basic-search/README.md Install the necessary Python packages using pip. ```bash pip install -r requirements.txt ``` -------------------------------- ### Clone, Build, and Run OpenSERP Source: https://github.com/karust/openserp/blob/main/docs/CONTRIBUTING.md Commands to clone the repository, build the project, and run the application. Ensure you have Go 1.24+ installed. ```bash git clone https://github.com/karust/openserp.git cd openserp make build make run ``` -------------------------------- ### Start OpenSERP Server from Source Source: https://github.com/karust/openserp/blob/main/examples/README.md Build and run the OpenSERP server from its source code. This is an alternative to using Docker for local development. ```bash # Or from source go build -o openserp . && ./openserp serve ``` -------------------------------- ### Build and Run OpenSERP from Source Source: https://github.com/karust/openserp/blob/main/README.md Clone the OpenSERP repository, build the executable from source, and then run the serve command to start the API server. ```sh git clone https://github.com/karust/openserp.git cd openserp go build -o openserp . ./openserp serve ``` -------------------------------- ### Runtime Configuration for Domain Enrichment Source: https://github.com/karust/openserp/blob/main/docs/ARCHITECTURE.md Demonstrates how to specify a custom path for the domain enrichment configuration file when starting the OpenSerp server. ```bash OPENSERP_ENRICHMENT_DOMAINS_FILE=/path/to/enrichment_domains.yaml ./openserp serve ``` -------------------------------- ### Fetch API GET Request with Async/Await Source: https://github.com/karust/openserp/blob/main/google/testdata/search_results.html Shows how to perform a GET request using the Fetch API with the modern async/await syntax. This approach simplifies asynchronous code handling. ```javascript async function fetchData(url) { const response = await fetch(url); const data = await response.json(); return data; } ``` -------------------------------- ### Start OpenSERP Server with Docker Source: https://github.com/karust/openserp/blob/main/examples/README.md Run the OpenSERP server using Docker. This command maps port 7000 from the host to the container and serves on all interfaces within the container. ```bash # Docker docker run -p 127.0.0.1:7000:7000 -it karust/openserp serve -a 0.0.0.0 -p 7000 ``` -------------------------------- ### Basic Fetch API GET Request Source: https://github.com/karust/openserp/blob/main/google/testdata/search_results.html Demonstrates a simple GET request using the Fetch API to retrieve data from a specified URL. It then parses the response as JSON. ```javascript fetch('http://test.test').then(response => response.json()) ``` -------------------------------- ### Run OpenSERP API Server with Docker Source: https://github.com/karust/openserp/blob/main/README.md Use this command to run the OpenSERP API server using a prebuilt Docker image. Ensure Docker is installed and running. ```sh # Run the API server via prebuilt image docker run --rm -p 127.0.0.1:7000:7000 karust/openserp:latest serve -a 0.0.0.0 -p 7000 # Or docker compose up ``` -------------------------------- ### Example JSON Response from OpenSERP API Source: https://github.com/karust/openserp/blob/main/README.md This is an example of the JSON response structure you can expect from the OpenSERP API when requesting search results with content extraction enabled. ```json { "query": { "text": "golang vs rust", "engines_requested": ["bing", "google"] }, "meta": { "request_id": "019ecdc0-a66d-79a4-9d2b-9e9b480d495e", "requested_at": "2026-06-16T00:06:55Z", "took_ms": 720, "engines_responded": ["bing"], "engines_failed": [], "version": "2.1" }, "results": [ { "id": "s_5a8273f16b19ab64", "rank": 1, "type": "organic", "title": "The Go Programming Language", "url": "https://go.dev/", "display_url": "go.dev", "snippet": "Get Started Playground Tour Stack Overflow Help Packages Standard Library About Go Packages About Download Blog Issue Tracker Release Notes Brand Guidelines Code of Conduct Connect …", "domain": "go.dev", "favicon": "https://go.dev/favicon.ico", "position": { "absolute": 1 }, "engine": "bing", "domain_info": { "tld": "dev", "sld": "go", "category": "" }, "extracted": { "title": "Build simple, secure, scalable systems with Go", "format": "markdown", "content": "## Build simple, secure, scalable systems with Go\n\n![Go Gopher climbing a ladder.](https://go.dev/images/gophers/ladder.svg)\n\n- \"At the time, no single team member knew Go, but **within a month, everyone was writing in Go** and we were building out the endpoints. It was the flexibility, how easy it was to use, and the really cool concept behind Go (how Go handles native concurrency, garbage collection, and of course safety+speed.) that helped engage us during the build. Also, who can beat that cute mascot!\n ........", "mode_used": "fast", "fetched_at": "2026-06-16T00:06:56Z" } }, { "id": "s_1a364ebcb3035539", "rank": 2, "type": "organic", "title": "Go (programming language) - Wikipedia", "url": "https://en.wikipedia.org/wiki/Go_(programming_language)", "display_url": "en.wikipedia.org \u003e wiki \u003e Go_(programming_language)", "snippet": "In Go's package system, each package has a path (e.g., \"compress/bzip2\" or \"golang.org/x/net/html\") and a name (e.g., bzip2 or html). By default other packages' definitions must always be prefixed with …", "domain": "en.wikipedia.org", "favicon": "https://en.wikipedia.org/favicon.ico", "position": { "absolute": 2 }, "engine": "bing", "domain_info": { "tld": "org", "sld": "wikipedia", "category": "" }, "classification": { "content_type": "article", "source_hint": "encyclopedia" } }, ... ], "serp_features": [], "pagination": { "page": 1, "has_more": false, "next_start": 10 }, "clusters": [ { "id": "c_f20b23a020101dce", "canonical_url": "https://go.dev/", "domain": "go.dev", "title": "The Go Programming Language", "occurrences": [ { "engine": "bing", "rank": 1, "result_id": "s_5a8273f16b19ab64" } ], "engines_count": 1, "best_rank": 1, "score": 0.5 }, ... ] } ``` -------------------------------- ### Read Local Text Files in JavaScript Source: https://github.com/karust/openserp/blob/main/bing/testdata/search_results.html This example shows how to read local text files using JavaScript. It relies on user interaction to select the file, ensuring security and privacy. ```javascript const fileInput = document.getElementById('fileInput'); fileInput.addEventListener('change', (event) => { const file = event.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { const textContent = e.target.result; console.log('File content:', textContent); }; reader.readAsText(file); } }); ``` -------------------------------- ### Cluster Example Source: https://github.com/karust/openserp/blob/main/README.md This JSON object illustrates a cluster response, which is returned by the `/mega/search` endpoint. It aggregates search results from different engines for a canonical URL. ```json { "id": "c_a1b2c3d4e5f6a1b2", "canonical_url": "https://go.dev/", "domain": "go.dev", "title": "The Go Programming Language", "occurrences": [ { "engine": "google", "rank": 1, "result_id": "s_78341aa47c336101" }, { "engine": "bing", "rank": 2, "result_id": "s_20f9f15f0c3d9f6d" } ], "engines_count": 2, "best_rank": 1, "score": 0.75 } ``` -------------------------------- ### Configure Didomi Consent Languages Source: https://github.com/karust/openserp/blob/main/ecosia/testdata/images_results.html Sets up the enabled and default languages for Didomi consent management. This configuration is part of the initial Didomi setup. ```javascript window.didomiConfig = { languages: { enabled: ["en"], default: "en", }, } ``` -------------------------------- ### Search Response Example Source: https://github.com/karust/openserp/blob/main/README.md This JSON object represents a typical search response from the OpenSERP API, including query details, metadata, search results, and pagination information. ```json { "query": { "text": "golang", "engines_requested": ["google"] }, "meta": { "request_id": "019dc6c1-da45-706e-a57c-d671fa2862ee", "requested_at": "2026-04-25T22:27:52Z", "took_ms": 6410, "engines_failed": [], "version": "2.1" }, "results": [ { "id": "s_78341aa47c336101", "rank": 1, "type": "organic", "title": "Documentation - The Go Programming Language", "url": "https://go.dev/doc/", "display_url": "go.dev > doc", "snippet": "Official Go documentation, tutorials, references, and release notes.", "domain": "go.dev", "favicon": "https://go.dev/favicon.ico", "position": { "absolute": 1 }, "engine": "google", "domain_info": { "tld": "dev", "sld": "go", "category": "" } } ], "pagination": { "page": 1, "has_more": true, "next_start": 25 } } ``` -------------------------------- ### Didomi Configuration and TCF API Setup Source: https://github.com/karust/openserp/blob/main/ecosia/testdata/images_no_results.html Configures Didomi consent management and sets up the TCF (Transparency and Consent Framework) API. This script is essential for managing user consent and privacy preferences. ```javascript window.didomiConfig = { languages: { enabled: ["en"], default: "en", }, } (function(){function i(e){if(!window.frames[e]){if(document.body&&document.body.firstChild){var t=document.body;var n=document.createElement("iframe");n.style.display="none";n.name=e;n.title=e;t.insertBefore(n,t.firstChild)}else{setTimeout(function(){i(e)},5)}}}function e(n,o,r,f,s){function e(e,t,n,i){if(typeof n!=="function"){return} if(!window[o]){window[o]=[]}var a=false;if(s){a=s(e,i,n)}if(!a){window[o].push({command:e,version:t,callback:n,parameter:i})}}e.stub=true;e.stubVersion=2;function t(i){if(!window[n]||window[n].stub!==true){return} if(!i.data){return} var a=typeof i.data==="string";var e;try{e=a?JSON.parse(i.data):i.data}catch(t){return} if(e[r]){var o=e[r];window[n](o.command,o.version,function(e,t){var n={};n[f]={returnValue:e,success:t,callId:o.callId};if(i.source){i.source.postMessage(a?JSON.stringify(n):n,"*")}},o.parameter)}}if(typeof window[n]!=="function"){window[n]=e;if(window.addEventListener){window.addEventListener("message",t,false)}else{window.attachEvent("onmessage",t)}}}e("__tcfapi","__tcfapiBuffer","__tcfapiCall","__tcfapiReturn");i("__tcfapiLocator")})(); ``` -------------------------------- ### Image Search Result Example Source: https://github.com/karust/openserp/blob/main/README.md This JSON structure represents a successful image search result from the OpenSERP API. ```json { "id": "i_a1b2c3d4e5f6a1b2", "rank": 1, "type": "image", "title": "Go Gopher Logo", "image": { "url": "https://example.com/images/go-logo.png", "thumbnail": "https://example.com/images/go-logo-thumb.png", "width": 1200, "height": 800 }, "source": { "page_url": "https://go.dev/brand/", "domain": "go.dev" }, "engine": "bing" } ``` -------------------------------- ### Make a Search Request to OpenSERP API Source: https://github.com/karust/openserp/blob/main/README.md Example cURL command to make a request to the OpenSERP API for searching across multiple engines. The 'extract=1' parameter enables content extraction. ```sh curl "http://127.0.0.1:7000/mega/search?engines=bing,google&text=golang+vs+rust&extract=1&mode=any" ``` -------------------------------- ### Bad Request Error Response Example Source: https://github.com/karust/openserp/blob/main/README.md This JSON structure indicates a 400 Bad Request error, typically due to an invalid or empty query. ```json { "error": "bad_request", "code": 400, "message": "EMPTY_QUERY: query cannot be empty: provide text, site, or file parameter", "reason": "EMPTY_QUERY" } ``` -------------------------------- ### Cache Statistics Endpoint Source: https://github.com/karust/openserp/blob/main/README.md Get detailed statistics about the OpenSERP service's cache performance, including hit rates and memory usage, via the /stats/cache endpoint. ```bash curl "http://127.0.0.1:7000/stats/cache" ``` -------------------------------- ### Perform a Single Engine Search via cURL Source: https://github.com/karust/openserp/blob/main/examples/README.md Execute a search query against a single search engine (Google) using cURL. This demonstrates a basic HTTP GET request to the local OpenSERP server. ```bash # One engine curl "http://localhost:7000/google/search?text=open+source+search+api&limit=10" ``` -------------------------------- ### Service Unavailable Error Response Example Source: https://github.com/karust/openserp/blob/main/README.md This JSON structure indicates a 503 Service Unavailable error, often due to CAPTCHA detection requiring a temporary pause in requests. ```json { "error": "service_unavailable", "code": 503, "message": "captcha found, please stop sending requests for a while: captcha detected" } ``` -------------------------------- ### Initialize OpenSERP Client (JavaScript) Source: https://github.com/karust/openserp/blob/main/README.md Instantiate the OpenSERP client for use with a self-hosted server. Ensure the baseUrl points to your running OpenSERP instance. ```javascript import { OpenSERP } from "@openserp/sdk"; // Use your self-hosted server const client = new OpenSERP({ baseUrl: "http://localhost:7000" }); const { results } = await client.search({ engine: "google", text: "openserp", limit: 5 }); ``` -------------------------------- ### Initialize OpenSERP Client with API Key (Python) Source: https://github.com/karust/openserp/blob/main/examples/README.md Instantiate the OpenSERP client in Python using an API key for the hosted service. This is the primary method for authenticating with the managed API. ```python client = OpenSERP(api_key="") ``` -------------------------------- ### Initialize OpenSERP Client with API Key (JavaScript) Source: https://github.com/karust/openserp/blob/main/examples/README.md Instantiate the OpenSERP client in JavaScript using an API key for the hosted service. This is the primary method for authenticating with the managed API. ```javascript const client = new OpenSERP({ apiKey: "" }); ``` -------------------------------- ### Health Check Endpoint Source: https://github.com/karust/openserp/blob/main/README.md Check the health status of the OpenSERP service by sending a GET request to the /health endpoint. This is useful for monitoring. ```bash curl -i "http://127.0.0.1:7000/health" ``` -------------------------------- ### HTML Structure for File Input and Display Source: https://github.com/karust/openserp/blob/main/bing/testdata/search_results.html Sets up an HTML file input element and a preformatted text area to display file content. Includes basic styling for readability. ```html Read File in JavaScript

Select a text file to read:


    


```

--------------------------------

### Run Basic Search

Source: https://github.com/karust/openserp/blob/main/examples/quickstart/python-basic-search/README.md

Execute the main Python script to perform a search and display results.

```bash
python main.py
```

--------------------------------

### Fetch API POST Request with Async/Await

Source: https://github.com/karust/openserp/blob/main/google/testdata/search_results.html

Illustrates how to send data using a POST request with the Fetch API and async/await. It includes setting the method, headers, and body.

```javascript
async function postData(url, data) {
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
  });
  return response.json();
}
```

--------------------------------

### Serve with Global Proxy

Source: https://github.com/karust/openserp/blob/main/README.md

Configure the OpenSERP server to use a SOCKS5 proxy globally. Ensure the proxy is running and accessible.

```bash
./openserp serve --proxy socks5://127.0.0.1:1080
```

--------------------------------

### List Available Engines

Source: https://github.com/karust/openserp/blob/main/README.md

Retrieve a list of all available search engines that can be used with OpenSERP.

```bash
curl "http://127.0.0.1:7000/mega/engines"
```

--------------------------------

### Run Unit Tests

Source: https://github.com/karust/openserp/blob/main/docs/CONTRIBUTING.md

Execute unit tests for the project. These tests do not rely on browser or network access.

```bash
make test
```

--------------------------------

### Fetch API PUT Request with Async/Await

Source: https://github.com/karust/openserp/blob/main/google/testdata/search_results.html

Demonstrates how to update existing resources using a PUT request with the Fetch API and async/await. It specifies the method, headers, and the data to be updated.

```javascript
async function updateData(url, data) {
  const response = await fetch(url, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
  });
  return response.json();
}
```

--------------------------------

### Readiness Check Endpoint

Source: https://github.com/karust/openserp/blob/main/README.md

Verify if the OpenSERP service is ready to accept requests by querying the /ready endpoint. This is typically used in orchestration systems.

```bash
curl "http://127.0.0.1:7000/ready"
```

--------------------------------

### CLI Search with JSON Output

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a search using the CLI with JSON as the default output format. The `--limit` flag restricts the number of results.

```sh
openserp search google "golang generics" --limit 20
```

--------------------------------

### OpenSERP Project Directory Structure

Source: https://github.com/karust/openserp/blob/main/docs/ARCHITECTURE.md

This snippet displays the directory structure of the OpenSERP project, outlining the organization of its Go source files, configuration, and documentation.

```text
openserp/
├── main.go
├── README.md
├── config.yaml
├── docs/
│   ├── ARCHITECTURE.md
│   ├── CONTRIBUTING.md
│   ├── openapi.yaml
│   └── embed.go
├── cmd/
│   ├── root.go
│   ├── serve.go
│   ├── search.go
│   └── proxy_policy.go
├── core/
│   ├── common.go
│   ├── server.go
│   ├── response.go
│   ├── result.go
│   ├── response_builder.go
│   ├── clusters.go
│   ├── format_markdown.go
│   ├── format_text.go
│   ├── enrichment_domain.go
│   ├── enrichment_domains.yaml
│   ├── middleware.go
│   ├── browser.go
│   ├── http_client.go
│   ├── resilient.go
│   ├── retry.go
│   ├── circuit_breaker.go
│   ├── cache.go
│   ├── proxy.go
│   ├── logger.go
│   └── captcha.go
├── google/
├── yandex/
├── baidu/
├── bing/
├── duckduckgo/
├── ecosia/
└── testutil/

```

--------------------------------

### Basic CLI Search

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a basic search using the CLI, specifying the engine and query. Markdown is used as the output format.

```sh
openserp search duckduckgo "free open source serp" --format markdown
```

--------------------------------

### Search with HTTP Proxy

Source: https://github.com/karust/openserp/blob/main/README.md

Execute a search query using the OpenSERP CLI with an HTTP proxy, including authentication. The proxy must be running and accessible.

```bash
./openserp search bing "query" --proxy http://user:pass@127.0.0.1:8080
```

--------------------------------

### Code Style and Quality Checks

Source: https://github.com/karust/openserp/blob/main/docs/CONTRIBUTING.md

Commands to format code, run linters, and execute tests before submitting a Pull Request. These checks ensure code quality and consistency.

```bash
make fmt
make lint
make test
```

--------------------------------

### Accessing a file using FileSystemDirectoryEntry.getFile()

Source: https://github.com/karust/openserp/blob/main/bing/testdata/search_results.html

This method allows programmatic access to files within a directory entry. It requires obtaining a FileSystemDirectoryEntry object first and then calling getFile() with the filename.

```javascript
function successCallback(fileEntry) {
  fileEntry.file(function(file) {
    const reader = new FileReader();
    reader.onload = function(e) {
      console.log(e.target.result);
    };
    reader.readAsText(file);
  });
}

function errorCallback(error) {
  console.error('Error getting file:', error);
}

// Assuming 'rootDirEntry' is a FileSystemDirectoryEntry object for the root directory
// rootDirEntry.getFile('filename.txt', {}, successCallback, errorCallback);

```

--------------------------------

### Megasearch in Any Mode

Source: https://github.com/karust/openserp/blob/main/README.md

Use the 'any' mode for megasearch, which tries engines sequentially until one responds, suitable for fallback-style availability checking. Specify the engines to try.

```bash
curl "http://127.0.0.1:7000/mega/search?text=golang&mode=any&engines=google,yandex,bing"
```

--------------------------------

### Run Integration Tests

Source: https://github.com/karust/openserp/blob/main/docs/CONTRIBUTING.md

Execute integration tests, which may require browser or network access. These tests are explicitly enabled.

```bash
make test-integration
```

--------------------------------

### CLI Search in Browserless Mode with Proxy

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a search using the CLI in browserless mode, routing traffic through a specified HTTP proxy.

```sh
openserp search duckduckgo "free open source serp" --raw --proxy http://user:pass@127.0.0.1:8080
```

--------------------------------

### CLI Search with Site Restriction and NDJSON Output

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a search using the CLI, restricting results to a specific site and using the NDJSON format for output.

```sh
openserp search bing "release notes" --site github.com --format ndjson
```

--------------------------------

### Basic JavaScript Fetch Request with JSON Parsing and Error Handling

Source: https://github.com/karust/openserp/blob/main/duckduckgo/testdata/search_results.html

This snippet demonstrates how to use the fetch() API to make a request to a URL, parse the JSON response, and handle potential errors. It's suitable for most common data fetching scenarios.

```javascript
fetch('http://test.test').then(response=>response.json()).then(data=>console.log(data)).catch(error=>console.error('Error:', error));
```

--------------------------------

### FileReader Reading Methods Overview

Source: https://github.com/karust/openserp/blob/main/bing/testdata/search_results.html

Lists the different methods available on the FileReader interface for reading file content in various formats.

```javascript
FileReader.readAsText(file, encoding)
FileReader.readAsDataURL(file)
FileReader.readAsArrayBuffer(file)
FileReader.readAsBinaryString(file)
```

--------------------------------

### Load Privacy Center SDK

Source: https://github.com/karust/openserp/blob/main/ecosia/testdata/search_no_results.html

This script loads the Ecosia Privacy Center SDK, which is responsible for managing user consent and privacy settings. It dynamically creates link elements for preconnecting and DNS prefetching to the SDK domain.

```javascript
(function(){(function(e,r){var t=document.createElement("link");t.rel="preconnect";t.as="script";var n=document.createElement("link");n.rel="dns-prefetch";n.as="script";var i=document.createElement("script");i.nonce="OZg2JfgFk1puE1nBC/jcrQ==";i.id="spcloader";i.type="text/javascript";i["async"]=true;i.charset="utf-8";var o="https://sdk.privacy-center.org/"+e+"/loader.js?target_type=notice&target="+r;if(window.didomiConfig&&window.didomiConfig.user){var a=window.didomiConfig.user;var c=a.country;var d=a.region;if(c){o=o+"&country="+c;if(d){o=o+"®ion="+d}}}t.href="https://sdk.privacy-center.org/";n.href="https://sdk.privacy-center.org/";i.src=o;var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s);s.parentNode.insertBefore(n,s);s.parentNode.insertBefore(i,s)})("44c99d3a-c3b4-496d-a3a1-9153b3ce5b9d","EJzmP2BE")})();
```

--------------------------------

### CLI Search with Plain Text Output and Language/Region Filters

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a search using the CLI, requesting plain text output and filtering results by language and region.

```sh
openserp search yandex "wetter berlin" --format text --lang DE --region DE
```

--------------------------------

### CLI Search with Content Extraction

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a search using the CLI and extract clean page content from the top results, outputting in markdown format.

```sh
openserp search google "llm observability" --extract 2 --format markdown
```

--------------------------------

### Extract URL Content as Markdown

Source: https://github.com/karust/openserp/blob/main/README.md

Extract content from a URL and format the output as clean page markdown.

```bash
curl "http://127.0.0.1:7000/extract?url=https://example.com&format=markdown"
```

--------------------------------

### OpenSERP HTTP Request Flow

Source: https://github.com/karust/openserp/blob/main/docs/ARCHITECTURE.md

Illustrates the sequence of middleware and handlers processing an HTTP request, from initial receipt to final response serialization.

```text
HTTP request
  -> Fiber middleware
     -> RequestContextMiddleware
     -> CORS
     -> RequestLoggerMiddleware
  -> handleDedicatedEndpoint / handleMegaEndpoint
  -> Query.InitFromContext
  -> resolveFormat
  -> cache lookup for JSON responses only
  -> ResilientSearcher
     -> circuit breaker
     -> rate limiter
     -> proxy policy resolution
     -> retry loop
     -> engine.Search / engine.SearchImage
        -> browser path: Browser.Navigate -> DOM parse -> []SearchResult
        -> raw path: HTTP client -> goquery parse -> []SearchResult
  -> response enrichment
     -> stable IDs
     -> normalized URL/display URL
     -> pagination position
     -> domain_info/classification
     -> image metadata extraction
  -> mega-only normalized URL dedupe + clusters
  -> cache write for eligible JSON responses
  -> output serializer: JSON, Markdown, text, or NDJSON
```

--------------------------------

### Handle File Input and Read Content

Source: https://github.com/karust/openserp/blob/main/bing/testdata/search_results.html

Attaches an event listener to a file input element to read the content of the selected text file and display it. Includes basic validation for file selection and type.

```javascript
document.getElementById('fileInput').addEventListener('change', function(event) {
  const file = event.target.files[0]; // Get the first selected file
  const message = document.getElementById('message');
  const output = document.getElementById('fileContent');

  // Clear previous content
  message.textContent = '';
  output.textContent = '';

  // Validate file selection
  if (!file) {
    message.textContent = 'No file selected.';
    message.style.color = 'red';
    return;
  }

  // Optional: Check file type
  if (!file.type.startsWith('text')) {
    message.textContent = 'Please select a text file.';
    message.style.color = 'red';
    return;
  }

  // Read file content
  const reader = new FileReader();
  reader.onload = function(e) {
    output.textContent = e.target.result; // Display file content
  };
  reader.onerror = function() {
    message.textContent = 'Error reading file.';
    message.style.color = 'red';
  };
  reader.readAsText(file); // Read file as text
});
```

--------------------------------

### Initialize TCF API and Consent Management

Source: https://github.com/karust/openserp/blob/main/ecosia/testdata/search_no_results.html

This JavaScript code initializes the Transparency and Consent Framework (TCF) API and sets up a message listener for consent-related events. It's used for managing user privacy preferences.

```javascript
(function(){function i(e){if(!window.frames[e]){if(document.body&&document.body.firstChild){var t=document.body;var n=document.createElement("iframe");n.style.display="none";n.name=e;n.title=e;t.insertBefore(n,t.firstChild)}else{setTimeout(function(){i(e)},5)}}}function e(n,o,r,f,s){function e(e,t,n,i){if(typeof n!=="function"){return}if(!window[o]){window[o]=[]}var a=false;if(s){a=s(e,i,n)}if(!a){window[o].push({command:e,version:t,callback:n,parameter:i})}}e.stub=true;e.stubVersion=2;function t(i){if(!window[n]||window[n].stub!==true){return}if(!i.data){return}var a=typeof i.data==="string";var e;try{e=a?JSON.parse(i.data):i.data}catch(t){return}if(e[r]){var o=e[r];window[n](o.command,o.version,function(e,t){var n={};n[f]={returnValue:e,success:t,callId:o.callId};if(i.source){i.source.postMessage(a?JSON.stringify(n):n,"*")}}),o.parameter)}}if(typeof window[n]!=="function"){window[n]=e;if(window.addEventListener){window.addEventListener("message",t,false)}else{window.attachEvent("onmessage",t)}}}e("__tcfapi","__tcfapiBuffer","__tcfapiCall","__tcfapiReturn");i("__tcfapiLocator")})();
```

--------------------------------

### List Engines

Source: https://github.com/karust/openserp/blob/main/README.md

Retrieves a list of available engines.

```APIDOC
## GET /mega/engines

### Description
Retrieves a list of all available search engines.

### Method
GET

### Endpoint
`http://127.0.0.1:7000/mega/engines`
```

--------------------------------

### Load Privacy Center SDK

Source: https://github.com/karust/openserp/blob/main/ecosia/testdata/images_results.html

Loads the Ecosia privacy center SDK script. It configures the script source based on provided IDs and user location data if available.

```javascript
(function(){(function(e,r){var t=document.createElement("link");t.rel="preconnect";t.as="script";var n=document.createElement("link");n.rel="dns-prefetch";n.as="script";var i=document.createElement("script");i.nonce="m3qR7s0kCkm9uMbFTUFYUg==";i.id="spcloader";i.type="text/javascript";i["async"]=true;i.charset="utf-8";var o="https://sdk.privacy-center.org/"+e+"/loader.js?target_type=notice&target="+r;if(window.didomiConfig&&window.didomiConfig.user){var a=window.didomiConfig.user;var c=a.country;var d=a.region;if(c){o=o+"&country="+c;if(d){o=o+"®ion="+d}}}t.href="https://sdk.privacy-center.org/";n.href="https://sdk.privacy-center.org/";i.src=o;var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s);s.parentNode.insertBefore(n,s);s.parentNode.insertBefore(i,s)})("44c99d3a-c3b4-496d-a3a1-9153b3ce5b9d","EJzmP2BE")})();
```

--------------------------------

### Megasearch in Fast Mode

Source: https://github.com/karust/openserp/blob/main/README.md

Utilize the 'fast' mode for megasearch to achieve the lowest latency by querying only the fastest available engine. Specify the desired engines.

```bash
curl "http://127.0.0.1:7000/mega/search?text=golang&mode=fast&engines=google,bing,yandex"
```

--------------------------------

### Load File from Path in JavaScript

Source: https://github.com/karust/openserp/blob/main/bing/testdata/search_results.html

This snippet demonstrates how to load a file from a specified path in JavaScript. Note that direct file path access from JavaScript in a browser is restricted for security reasons; this typically applies to server-side Node.js environments or specific browser APIs.

```javascript
// In Node.js environment:
const fs = require('fs');

fs.readFile('/path/to/your/file.txt', 'utf8', (err, data) => {
  if (err) {
    console.error('Error reading file:', err);
    return;
  }
  console.log(data);
});
```

--------------------------------

### Fetch API DELETE Request with Async/Await

Source: https://github.com/karust/openserp/blob/main/google/testdata/search_results.html

Shows how to remove a resource using a DELETE request with the Fetch API and async/await. It sets the HTTP method to DELETE.

```javascript
async function deleteData(url) {
  const response = await fetch(url, {
    method: 'DELETE'
  });
  return response.json();
}
```

--------------------------------

### Deriving Responded Engines from API Response

Source: https://github.com/karust/openserp/blob/main/docs/ARCHITECTURE.md

Shows how to calculate the number of engines that successfully responded by subtracting failed engines from the total requested engines.

```text
query.engines_requested - meta.engines_failed
```

--------------------------------

### Search a Dedicated Engine

Source: https://github.com/karust/openserp/blob/main/README.md

Perform a search query against a specific search engine like Google. Specify the engine name, search text, and an optional limit for results.

```bash
curl "http://127.0.0.1:7000/google/search?text=golang&limit=10"
```

--------------------------------

### Color Mode Preference Script

Source: https://github.com/karust/openserp/blob/main/ecosia/testdata/images_no_results.html

Manages the user's color mode preference (system, light, or dark) by checking system settings and local storage. It applies the chosen mode to the document's root element.

```javascript
(()=>{var n="system",e="light",s="dark";var m="color-mode",r=n,d=e,l=[s,e],c=t=>window.matchMedia(`(prefers-color-scheme${t})`),T=()=>{if(window.matchMedia&&c("").media!=="not all"){for(let t of l)if(c(`:${t}`).matches)return t}return d},o=window.localStorage.getItem(m)||r,a=o===r?T():o;document.documentElement.classList.add(a);window.__COLOR_MODE__={preference:o,value:a};})();
```

--------------------------------

### Search Images on a Dedicated Engine

Source: https://github.com/karust/openserp/blob/main/README.md

Conduct an image search on a specific engine, such as Bing. Provide the engine name, search text for images, and an optional limit.

```bash
curl "http://127.0.0.1:7000/bing/image?text=golang+logo&limit=10"
```

--------------------------------

### Megasearch in Balanced Mode with Aggregation

Source: https://github.com/karust/openserp/blob/main/README.md

Employ the 'balanced' mode for megasearch, which queries engines in parallel and merges results. Enable deduplication and merging for aggregated output.

```bash
curl "http://127.0.0.1:7000/mega/search?text=golang&mode=balanced&dedupe=true&merge=true"
```

--------------------------------

### Perform a Multi-Engine Search via cURL

Source: https://github.com/karust/openserp/blob/main/examples/README.md

Execute a search query across multiple search engines (e.g., Bing, DuckDuckGo) simultaneously using cURL. This showcases the 'mega search' functionality.

```bash
# Several engines at once
curl "http://localhost:7000/mega/search?text=open+source+search+api&engines=bing,duckduckgo&limit=10"
```

--------------------------------

### Extract One URL as JSON

Source: https://github.com/karust/openserp/blob/main/README.md

Extract content from a given URL and return it in JSON format. Use 'auto' mode for automatic format detection.

```bash
curl "http://127.0.0.1:7000/extract?url=https://example.com&mode=auto"
```

--------------------------------

### Perform a Megasearch

Source: https://github.com/karust/openserp/blob/main/README.md

Execute a megasearch query across multiple engines. Specify the search text and an optional limit for the aggregated results.

```bash
curl "http://127.0.0.1:7000/mega/search?text=golang&limit=10"
```

--------------------------------

### Domain Enrichment Configuration File

Source: https://github.com/karust/openserp/blob/main/docs/ARCHITECTURE.md

Mutable domain category data is stored in a YAML file. This file can be replaced at runtime by setting the OPENSERP_ENRICHMENT_DOMAINS_FILE environment variable.

```yaml
core/enrichment_domains.yaml
```