define.wtf
API Reference

Search

Full-text search and autocomplete for acronyms and definitions

Search API

define.wtf provides two search endpoints: full-text search with FTS5 for comprehensive results, and autocomplete for real-time suggestions as users type.

GET /api/v1/search?q=TERM

Performs full-text search across acronyms and definitions in your workspace using FTS5 (Full-Text Search 5) with typo tolerance via Levenshtein distance.

Query Parameters

ParameterTypeRequiredDefaultDescription
qstringYesSearch query (min 1 character)
categorystringNoFilter by category slug
include_deprecatedbooleanNofalseInclude deprecated acronyms
limitnumberNo10Max results (max 50)

Response

{
  "success": true,
  "data": {
    "results": [
      {
        "id": "acr_abc123def456",
        "type": "acronym",
        "term": "API",
        "title": "Application Programming Interface",
        "text": "A set of protocols and tools for building software...",
        "matchedIn": "term",
        "isPrimary": true,
        "netVotes": 12,
        "categories": [
          {
            "id": "cat_001",
            "name": "Technology",
            "slug": "technology",
            "color": "#FF6B6B"
          }
        ]
      },
      {
        "id": "def_xyz789",
        "type": "definition",
        "acronymId": "acr_abc123def456",
        "acronymTerm": "API",
        "title": "Application Programming Interface",
        "text": "A set of protocols and tools for building software...",
        "matchedIn": "definition",
        "isPrimary": true,
        "netVotes": 12,
        "creatorName": "Alice Chen",
        "categories": [
          {
            "id": "cat_001",
            "name": "Technology",
            "slug": "technology",
            "color": "#FF6B6B"
          }
        ]
      }
    ],
    "count": 2,
    "totalAvailable": 2
  }
}

Response Fields

FieldTypeDescription
resultsarrayArray of matching acronyms and definitions
countnumberNumber of results returned
totalAvailablenumberTotal matches in database (before limit)
results[].idstringAcronym ID (for type=acronym) or definition ID (for type=definition)
results[].typestringEither "acronym" or "definition"
results[].termstringThe acronym term (acronyms only)
results[].titlestringTitle of acronym or definition
results[].textstringFirst 200 chars of description
results[].matchedInstringWhere match occurred: "term", "title", or "definition"
results[].isPrimarybooleanIs this the primary definition?
results[].netVotesnumberUpvotes - downvotes
results[].categoriesarrayAssociated categories
results[].creatorNamestringName of definition creator (definitions only)
results[].acronymTermstringParent acronym term (definitions only)
results[].acronymIdstringParent acronym ID (definitions only)

Examples

Simple search:

curl "https://engineering.define.wtf/api/v1/search?q=API" \
  -H "Cookie: next-auth.session-token=YOUR_TOKEN"

Search with category filter:

curl "https://engineering.define.wtf/api/v1/search?q=programming&category=technology" \
  -H "Cookie: next-auth.session-token=YOUR_TOKEN"

Search including deprecated acronyms:

curl "https://engineering.define.wtf/api/v1/search?q=OLD&include_deprecated=true" \
  -H "Cookie: next-auth.session-token=YOUR_TOKEN"

Search with higher limit:

curl "https://engineering.define.wtf/api/v1/search?q=framework&limit=50" \
  -H "Cookie: next-auth.session-token=YOUR_TOKEN"

Search Features

Full-text search: Searches across acronym terms, definition titles, and full text.

Typo tolerance: Uses Levenshtein distance to find similar terms (e.g., "APPI" finds "API").

Ranking: Results are ranked by:

  1. Exact matches (highest relevance)
  2. Prefix matches
  3. Levenshtein distance (closest matches)
  4. Vote score (higher votes rank higher)

GET /api/v1/search/autocomplete?q=TERM

Real-time autocomplete suggestions as users type. Results are cached for 5 minutes.

Query Parameters

ParameterTypeRequiredDefaultDescription
qstringYesSearch query (min 1 character)
limitnumberNo7Max results (max 15)

Response

{
  "success": true,
  "data": [
    {
      "id": "acr_abc123def456",
      "term": "API",
      "title": "Application Programming Interface",
      "type": "exact_match",
      "score": 100
    },
    {
      "id": "acr_def789ghi123",
      "term": "APIM",
      "title": "API Management",
      "type": "prefix_match",
      "score": 95
    },
    {
      "id": "acr_jkl456mno789",
      "term": "APPSYNC",
      "title": "Application Synchronization",
      "type": "fuzzy_match",
      "score": 75
    }
  ]
}

Response Fields

FieldTypeDescription
idstringAcronym ID
termstringAcronym term
titlestringPrimary definition title
typestringMatch type: exact_match, prefix_match, or fuzzy_match
scorenumberRelevance score (0-100)

Match Types

  • exact_match — Full query matches term (e.g., "API" → "API")
  • prefix_match — Term starts with query (e.g., "AP" → "API", "APP")
  • fuzzy_match — Similar term using Levenshtein (e.g., "API" → "APPI", "AAPI")

Examples

Simple autocomplete:

curl "https://engineering.define.wtf/api/v1/search/autocomplete?q=AP" \
  -H "Cookie: next-auth.session-token=YOUR_TOKEN"

Response (as user types):

{
  "success": true,
  "data": [
    {
      "id": "acr_abc123def456",
      "term": "API",
      "title": "Application Programming Interface",
      "type": "prefix_match",
      "score": 95
    },
    {
      "id": "acr_111222",
      "term": "APP",
      "title": "Application",
      "type": "prefix_match",
      "score": 90
    }
  ]
}

Autocomplete with higher limit:

curl "https://engineering.define.wtf/api/v1/search/autocomplete?q=OK&limit=15" \
  -H "Cookie: next-auth.session-token=YOUR_TOKEN"

Caching

Autocomplete results are cached for 5 minutes per query. This improves performance for frequently searched terms. Cache is scoped per tenant and query string.


Search Best Practices

For Applications

  1. Use autocomplete for user input fields — provide real-time suggestions as users type
  2. Debounce autocomplete requests — wait 300ms after user stops typing before requesting
  3. Use full-text search for browse/discover — when user explicitly searches
  4. Cache results client-side — avoid redundant requests for the same query
  5. Show match type — highlight exact vs. fuzzy matches for clarity

Query Tips

  • Search is case-insensitive — "api" = "API" = "Api"
  • Acronyms are uppercase — search normalizes queries to uppercase
  • Partial searches work — "OKR" finds "OKR", "OKRA", "OK"
  • Whitespace is trimmed — leading/trailing spaces are removed
  • Special characters are supported — "C++" searches for C++

Error Responses

Missing query (400):

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid search parameters",
    "details": {
      "q": ["Search query is required"]
    }
  }
}

Query too long (400):

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid search parameters",
    "details": {
      "q": ["String must contain at most 100 character(s)"]
    }
  }
}

Invalid category (400):

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid search parameters",
    "details": {
      "category": ["Category not found"]
    }
  }
}

Unauthorized (401):

{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Authentication required to search"
  }
}

Advanced: Search Algorithm

The search system combines multiple techniques:

  1. FTS5 (Full-Text Search 5) — SQLite's built-in full-text search for fast, ranked results
  2. Prefix matching — Quick term prefix search for autocomplete
  3. Levenshtein distance — Edit distance algorithm for typo tolerance (max distance: 2)
  4. Vote-based ranking — Results with higher votes rank higher

This hybrid approach provides both speed and relevance for both exact and fuzzy searches.