Resources
Customize search rankings with Goggles to create personalized search experiences
Overview
Goggles are a powerful feature that allows you to customize how search results are ranked. Using a simple domain-specific language, you can create instructions to boost, downrank, or completely filter results based on URL patterns, domains, and other criteria. This enables you to build personalized search experiences tailored to specific use cases or audiences.
Goggles work with both Web Search and News Search APIs, giving you fine-grained control over result ranking across different content types.
Key Features
Custom Ranking
Boost, downrank, or completely discard results based on your criteria
URL Pattern Matching
Target specific domains, paths, or URL patterns with flexible matching rules
Multiple Sources
Combine multiple hosted Goggles or use inline definitions for flexibility
Open & Shareable
Host Goggles on GitLab, GitHub repositories, or Gists and share them with others
Use Cases
Goggles are perfect for:
- Specialized Search Engines: Create vertical search experiences (e.g., tech blogs, academic sources only)
- Content Curation: Boost trusted sources and demote undesired content
- Brand Monitoring: Focus on specific news outlets or exclude competitors
- Research Applications: Filter scholarly sources or specific geographic regions
- Community Tools: Build search experiences tailored to specific communities or interests
Using Goggles with the API
Both Web Search and News Search APIs accept the goggles query parameter. You can provide Goggles in three ways:
- Hosted Goggles URL: A link to a Goggles file hosted on GitHub, GitLab, or Gist
- Inline Specification: Include Goggles rules directly in the request
- Mixed: Combine multiple hosted Goggles and inline rules by passing multiple URLs and inline rules
Goggles must be submitted to Brave Search before they can be used with the API. Visit search.brave.com/goggles/create to register your Goggle.
Using a Hosted Goggles
Hosted Goggles are ideal for complex rule sets as they avoid URL length limitations. Simply pass the URL of your hosted Goggles file:
curl "https://api.search.brave.com/res/v1/web/search" \
--url-query "q=programming tutorials" \
--url-query "goggles=https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/tech_blogs.goggle" \
-H "X-Subscription-Token: YOUR_API_KEY"import requests
url = "https://api.search.brave.com/res/v1/web/search"
headers = {
"Accept": "application/json",
"Accept-Encoding": "gzip",
"X-Subscription-Token": "YOUR_API_KEY"
}
params = {
"q": "programming tutorials",
"goggles": "https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/tech_blogs.goggle"
}
response = requests.get(url, headers=headers, params=params)
results = response.json()const url = new URL("https://api.search.brave.com/res/v1/web/search");
url.searchParams.append("q", "programming tutorials");
url.searchParams.append(
"goggles",
"https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/tech_blogs.goggle"
);
const response = await fetch(url, {
headers: {
Accept: "application/json",
"Accept-Encoding": "gzip",
"X-Subscription-Token": "YOUR_API_KEY",
},
});
const results = await response.json();
console.log(results);Using Multiple Goggles
You can combine multiple hosted Goggles by passing multiple goggles parameters:
curl "https://api.search.brave.com/res/v1/web/search?q=rust+programming&goggles=https%3A%2F%2Fexample.com%2Fgoggle1.goggle&goggles=https%3A%2F%2Fexample.com%2Fgoggle2.goggle" \
-H "X-Subscription-Token: YOUR_API_KEY"import requests
url = "https://api.search.brave.com/res/v1/web/search"
headers = {
"Accept": "application/json",
"Accept-Encoding": "gzip",
"X-Subscription-Token": "YOUR_API_KEY"
}
# Pass multiple goggles as a list
params = [
("q", "rust programming"),
("goggles", "https://example.com/goggle1.goggle"),
("goggles", "https://example.com/goggle2.goggle")
]
response = requests.get(url, headers=headers, params=params)
results = response.json()const url = new URL("https://api.search.brave.com/res/v1/web/search");
url.searchParams.append("q", "rust programming");
// Append multiple goggles parameters
url.searchParams.append("goggles", "https://example.com/goggle1.goggle");
url.searchParams.append("goggles", "https://example.com/goggle2.goggle");
const response = await fetch(url, {
headers: {
Accept: "application/json",
"Accept-Encoding": "gzip",
"X-Subscription-Token": "YOUR_API_KEY",
},
});
const results = await response.json();
console.log(results);Using Inline Goggles Specifications
For simple use cases, you can pass Goggles rules directly in the query parameter. This is useful for quick experiments or simple filtering rules:
curl "https://api.search.brave.com/res/v1/web/search?q=rust+programming&goggles=https%3A%2F%2Fexample.com%2Fgoggle1.goggle&goggles=https%3A%2F%2Fexample.com%2Fgoggle2.goggle" \
-H "X-Subscription-Token: YOUR_API_KEY"import requests
from urllib.parse import quote
url = "https://api.search.brave.com/res/v1/web/search"
headers = {
"Accept": "application/json",
"Accept-Encoding": "gzip",
"X-Subscription-Token": "YOUR_API_KEY"
}
# Inline Goggles to boost dev.to results
goggle_rules = "$boost=3,site=dev.to"
params = {
"q": "web development",
"goggles": goggle_rules
}
response = requests.get(url, headers=headers, params=params)
results = response.json()const url = new URL("https://api.search.brave.com/res/v1/web/search");
url.searchParams.append("q", "web development");
// Inline Goggles to boost dev.to results
const gogglesRules = "$boost=3,site=dev.to";
url.searchParams.append("goggles", gogglesRules);
const response = await fetch(url, {
headers: {
Accept: "application/json",
"Accept-Encoding": "gzip",
"X-Subscription-Token": "YOUR_API_KEY",
},
});
const results = await response.json();
console.log(results);Delimit the rules with \n (encoded to %0A) to include multiple inline
rules in one goggles parameter.
For complex Goggles with many rules, use hosted files instead of inline specifications. URL length limits can restrict the number of rules you can include inline.
Using Goggles with News Search
Goggles work the same way with the News Search API. This allows you to customize news result rankings based on your preferred sources:
curl "https://api.search.brave.com/res/v1/news/search?q=technology&goggles=https%3A%2F%2Fexample.com%2Fmy-news-sources.goggle" \
-H "X-Subscription-Token: YOUR_API_KEY"Goggles Syntax Overview
Goggles use a simple domain-specific language (DSL) to express ranking instructions. Each instruction targets URLs and specifies how matching results should be treated.
Basic Actions
| Action | Description | Example |
|---|---|---|
$boost | Increase ranking of matching results | $boost,site=example.com |
$boost=N | Boost with specific strength (1-10) | $boost=5,site=example.com |
$downrank | Decrease ranking of matching results | $downrank,site=example.com |
$downrank=N | Downrank with specific strength (1-10) | $downrank=3,site=example.com |
$discard | Completely remove matching results | $discard,site=example.com |
URL Targeting
| Pattern | Description | Example |
|---|---|---|
site= | Match specific domain | $boost,site=dev.to |
| Path patterns | Match URL paths | /blog/$boost |
Wildcards (*) | Match any characters | */api/*$boost |
Example Goggles File
! name: Tech Blogs
! description: Boost results from popular tech blogs
! public: true
! author: Your Name
! Boost popular tech blogs
$boost=3,site=dev.to
$boost=3,site=medium.com
$boost=3,site=hashnode.dev
$boost=2,site=css-tricks.com
! Downrank content farms
$downrank=5,site=w3schools.com
! Discard specific domains entirely
$discard,site=spam-example.comConflict Resolution
When multiple instructions match the same URL, Goggles follow this precedence:
$discardtakes highest priority (unless generic)$boosttakes precedence over$downrank- Higher strength values take precedence over lower ones
For example, if one rule says $downrank=3,site=example.com and another says $boost=2,site=example.com, the boost rule wins.
Creating and Hosting Goggles
To use a hosted Goggles with the API, you need to:
- Create a Goggles file — Write your rules in a plain text file (
.goggleextension recommended) - Add metadata — Include required metadata at the top of your file
- Host the file — Upload to one of the supported platforms:
- GitHub Gist (public or secret)
- GitHub (public repositories)
- GitLab (public files or snippets)
- Submit for validation — Register your Goggles at search.brave.com/goggles/create
Required Metadata
Every Goggles file must include these metadata fields at the top:
! name: My Custom Goggles
! description: Brief description of what this Goggles does
! public: false
! author: Your NameOptional Metadata
Optional metadata can be added to your Goggles file to provide additional information about the Goggles.
! homepage: https://example.com
! issues: https://github.com/user/repo/issues
! avatar: #FF5733
! license: MITGoggles must be submitted to Brave Search before they can be used with the API. Visit search.brave.com/goggles/create to register your Goggle.
Limitations
Keep these limitations in mind when creating Goggles:
- File size: Maximum 2MB per Goggles file
- Instruction count: Maximum 100,000 instructions per file
- Instruction length: Maximum 500 characters per instruction
- Wildcards: Maximum 2
*characters per instruction - Carets: Maximum 2
^characters per instruction
These limits are designed to ensure good performance while still allowing complex re-ranking logic. Most use cases fit well within these constraints.
Best Practices
Start Simple and Iterate
Begin with a few key rules and test their effect on search results. Gradually add more rules as you understand how they interact.
Use Hosted Goggles for Complex Rules
Inline Goggles specifications are convenient for simple cases, but URL length limits restrict their complexity. For production applications with many rules, always use hosted Goggles files.
Test with Diverse Queries
A Goggles that works well for one query might behave unexpectedly for others. Test your Goggles with a variety of queries to ensure consistent behavior across different use cases.
Version Control Your Goggles
Since Brave Search doesn’t maintain version history, use Git to track changes to your Goggles files. This allows you to roll back changes if needed and understand how your rules have evolved.
Example Goggles
Brave provides several example Goggles for learning purposes:
| Goggles | Description |
|---|---|
| Tech Blogs | Boosts content from popular tech blogs |
| Hacker News | Prioritizes domains popular with the HN community |
| No Pinterest | Removes Pinterest results |
| 1K Short | Removes top 1,000 most-viewed websites |
Browse more community-created Goggles on the Goggles Discovery page.
Related Resources
Goggles Quickstart Guide
Complete guide to creating Goggles with syntax reference and examples
Web Search API
Learn about the Web Search API and all available parameters
News Search API
Learn about the News Search API and filtering options
Search Operators
Combine Goggles with search operators for even more control