{
    "slug": "meilisearch_typesense",
    "term": "Meilisearch & Typesense",
    "category": "search",
    "difficulty": "intermediate",
    "short": "Open-source, self-hosted search engines with PHP SDKs — fast BM25 search, typo-tolerance, and faceting without the operational complexity of Elasticsearch.",
    "long": "Meilisearch (Rust, MIT license) and Typesense (C++, open core) are modern search servers optimised for developer experience. Both provide: BM25 relevance ranking, typo-tolerance, faceting and filtering, geosearch, and sub-50ms response times. Meilisearch has a simpler API and easier setup; Typesense has stronger multi-tenancy support. Both have official PHP SDKs. For most PHP applications needing search, either is a better choice than Elasticsearch due to lower operational overhead and simpler configuration.",
    "aliases": [
        "Meilisearch",
        "Typesense",
        "self-hosted search",
        "open-source search"
    ],
    "tags": [
        "search",
        "php",
        "performance",
        "devops"
    ],
    "misconception": "Elasticsearch is required for production search — Elasticsearch is powerful but operationally complex; Meilisearch handles most search needs with 10x less operational overhead and a simpler PHP integration.",
    "why_it_matters": "A PHP glossary with LIKE search returns misspelled terms as 'not found' — Meilisearch's typo-tolerance matches 'php arry' to 'php array' automatically, with no extra code.",
    "common_mistakes": [
        "Indexing data in real-time on every write — batch index updates in a queue worker to avoid blocking requests.",
        "Not configuring filterable and sortable attributes before indexing — adding them later requires re-indexing.",
        "Storing all document fields in the search index — only index searchable fields; store others in your DB.",
        "Not setting searchable attributes priority — title should rank higher than body text."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "search_relevance",
        "search_indexing_pipeline",
        "elasticsearch_basics"
    ],
    "prerequisites": [
        "full_text_search",
        "elasticsearch_basics",
        "database_indexing"
    ],
    "refs": [
        "https://www.meilisearch.com/docs/reference/api/overview"
    ],
    "bad_code": "// LIKE search — slow, no relevance, no typo tolerance:\n$results = $pdo->query(\n    \"SELECT * FROM glossary WHERE term LIKE '%\" . $db->escape($q) . \"%'\n     OR body LIKE '%\" . $db->escape($q) . \"%'\"\n)->fetchAll();\n// Issues: no ranking, O(n) scan, no typos, injection risk",
    "good_code": "// Meilisearch PHP SDK:\n$client = new \\Meilisearch\\Client('http://localhost:7700');\n$index  = $client->index('glossary');\n\n// Index a term:\n$index->addDocuments([[\n    'id'       => $term['slug'],\n    'term'     => $term['term'],\n    'short'    => $term['short'],\n    'category' => $term['category'],\n]]);\n\n// Search:\n$results = $index->search($query, [\n    'limit'   => 20,\n    'filter'  => 'category = security',\n    'sort'    => ['term:asc'],\n]);\n// Typo-tolerant, ranked, facetable — 5ms response",
    "quick_fix": "Use Meilisearch for self-hosted search (zero config, excellent defaults) or Typesense for a simpler managed option — both are dramatically simpler than Elasticsearch for typical PHP app search",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/meilisearch_typesense",
        "html_url": "https://codeclaritylab.com/glossary/meilisearch_typesense",
        "json_url": "https://codeclaritylab.com/glossary/meilisearch_typesense.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Meilisearch & Typesense](https://codeclaritylab.com/glossary/meilisearch_typesense) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/meilisearch_typesense"
            }
        }
    }
}