Drupal Contrib Code Search

Powered by zoekt, an open-source full text search engine. Indexing 670024 files from 11928 repositories.

Query Syntax

Basic Search

Queries are regular expressions parsed by Go's regexp package. A single term like hook_form_alter searches across all file contents and filenames.

Multiple space-separated terms are conjunctive by default: class needle returns files containing both "class" and "needle". Each term is matched independently and results show lines matching any individual term, but only from files that contain all of them.

Phrases & Escaping

Boolean Logic

Case Sensitivity

By default, terms with uppercase letters are case-sensitive; all-lowercase terms are case-insensitive. Use case:yes or case:no to override.

Prefix Filters

Prefix Alias Description Example
file: f: Match filenames (regex) f:\.module$
-file: -f: Exclude filenames hook -file:test
content: c: Match file contents only (not filenames) c:README
repo: r: Filter by repository name hook_form_alter r:views
-repo: -r: Exclude repositories r:views -r:commerce
branch: b: Filter by branch name hook b:HEAD
lang: Filter by language (case-insensitive) hook_form_alter lang:php
sym: Match symbol definitions (ctags) sym:main
case: Force case sensitivity (yes / no / auto) class Needle case:yes
archived: Filter archived repos (yes / no) hook archived:no
fork: Filter forked repos (yes / no) hook fork:no
public: Filter public repos (yes / no) hook public:no

Listing Repositories

Use r: alone (without a content search term) to list matching repositories:

Regex Examples

Query Meaning
foo.*bar "foo" followed by "bar" on the same line
f:\.module$ Files ending in .module
\bfunction\b lang:php Whole-word "function" in PHP files
[[:upper:]]{3} Three consecutive uppercase letters

JSON API

Base URL: https://api.tresbien.tech/v1/search. Two GET endpoints returning JSON. Full API reference →

Important: query terms are Go regexp patterns. Escape special characters with a backslash: .\., (\(, )\). Example: to search for .once( use q=\.once\(.

Search code: GET /v1/search/code

Search file contents. Returns matching files with chunk-level matches. Content is base64-encoded.

curl 'https://api.tresbien.tech/v1/search/code?q=hook_form_alter+r:webform&num=5'
ParameterTypeDescription
qstringSearch query (required). Same syntax as web UI.
numintMaximum number of file results to return
contextintNumber of context lines around each match
maxmatchesintStop after this many total matches
chunksboolReturn ChunkMatches (default: true) or LineMatches (false)

Response structure:

{
  "Result": {
    "Files": [
      {
        "FileName": "webform.api.php",
        "Repository": "webform",
        "Branches": ["6.3.x"],
        "Language": "PHP",
        "ChunkMatches": [
          {
            "Content": "<base64-encoded content>",
            "ContentStart": {"ByteOffset": 13463, "LineNumber": 368, "Column": 1},
            "Ranges": [
              {
                "Start": {"ByteOffset": 13492, "LineNumber": 368, "Column": 30},
                "End": {"ByteOffset": 13507, "LineNumber": 368, "Column": 45}
              }
            ]
          }
        ]
      }
    ],
    "MatchCount": 47,
    "FileCount": 38
  }
}

Each file in Result.Files contains:

Repository
Module machine name (e.g. "webform")
FileName
Path relative to the repo root
Branches
Array of branches where this file matched
Language
Detected language (e.g. "PHP", "YAML")
ChunkMatches
Array of matching chunks with base64-encoded Content, ContentStart position, and Ranges array with precise Start/End positions (each with ByteOffset, LineNumber, Column)

List repositories: GET /v1/search/repo

Returns the full list of all indexed repositories with metadata including branches, core compatibility, usage stats, and security coverage. Use this to get install counts and Drupal metadata for modules.

curl 'https://api.tresbien.tech/v1/search/repo'

Response structure:

{
  "List": {
    "Repos": [
      {
        "Repository": {
          "Name": "admin_toolbar",
          "URL": "https://git.drupalcode.org/project/admin_toolbar",
          "Branches": [{"Name": "3.x", "Version": "f0a73d2..."}],
          "RawConfig": {
            "drupal-core": "3.5.x:^9.5 || ^10 || ^11;3.6.x:^9.5 || ^10 || ^11",
            "drupal-usage": "3.5.x:42092;3.6.x:167949",
            "drupal-security": "covered",
            "priority": "210041"
          },
          "HasSymbols": true,
          "LatestCommitDate": "2026-02-07T01:36:41Z"
        }
      }
    ]
  }
}

Each repository's RawConfig contains Drupal-specific metadata:

Key Format Description
drupal-core branch:constraint;... Core compatibility per branch (e.g. 6.2.x:^10 || ^11). Multiple branches separated by ;
drupal-usage branch:count;... Active installs per branch (e.g. 3.6.x:167949). Multiple branches separated by ;
drupal-security covered Present and set to "covered" if the project is covered by the Drupal Security Team. Absent otherwise.
priority integer string Total active installs across supported branches. Use this to rank modules by popularity.

Example: find the 5 most installed modules using .once(

  1. Search (escape regex: .once(\.once\():
    GET https://api.tresbien.tech/v1/search/code?q=\.once\(&num=500
  2. Collect unique repo names from Result.Files[].Repository in the response.
  3. Fetch the full repo list (no parameters):
    GET https://api.tresbien.tech/v1/search/repo
  4. Look up each repo by name in List.Repos[], read Repository.RawConfig.priority (total active installs as a string).
  5. Sort by priority descending, take top 5.