onstage2426 / fuzor
Full-text search for PHP in a single SQLite file: BM25 ranking with typo tolerance and search-as-you-type, filters, facets, sorting, highlighting, and CJK and Thai n-grams. No search server and no package dependencies.
Requires
- php: >=8.5
- ext-mbstring: *
- ext-pdo: *
- ext-pdo_sqlite: *
Requires (Dev)
- infection/infection: ^0.32.6 || ^0.33.0 || ^0.34.0 || ^0.35.0
- phpbench/phpbench: ^1.5
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.1
- rector/rector: ^2.4
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Full-text search for PHP in a single SQLite file.
Typo-tolerant ranking, filters, facets and sorting, with no search server to run.
Fuzor indexes your documents into one SQLite file and searches them from PHP: BM25 ranking with typo
tolerance and search-as-you-type, filters and facet counts for shop pages, sorting, highlighting and
excerpts. It needs no service, no daemon and no package dependencies, only PHP's SQLite and mbstring
extensions. Its options use the names and behaviour of Meilisearch (filterableAttributes,
matchingStrategy, typoTolerance, facetDistribution, _formatted, …), so the concepts carry over.
Quick start
composer require onstage2426/fuzor
use Fuzor\FacetRange; use Fuzor\Index; use Fuzor\SchemaConfig; use Fuzor\SearchOptions; use Fuzor\Sort; $index = new Index('products.db', schema: new SchemaConfig( filterableAttributes: ['brand', 'price'], sortableAttributes: ['price'], )); $index->insert([ ['id' => 1, 'title' => 'Waterproof hiking boots', 'brand' => 'Northpeak', 'price' => 129], ['id' => 2, 'title' => 'Trail running shoes', 'brand' => 'Fellwalk', 'price' => 89], ['id' => 3, 'title' => 'Leather hiking boots', 'brand' => 'Northpeak', 'price' => 159], ['id' => 4, 'title' => 'Lightweight hiking boots', 'brand' => 'Fellwalk', 'price' => 99], ]); $result = $index->search('boots', new SearchOptions( filter: ['price' => FacetRange::max(150)], facets: ['brand'], sort: [Sort::asc('price')], )); $result->hits; // Lightweight hiking boots (99), Waterproof hiking boots (129) $result->totalHits; // 2 $result->facetDistribution; // ['brand' => ['Fellwalk' => 1, 'Northpeak' => 1]] $index->search('waterprof boots'); // a typo still finds "Waterproof hiking boots"
Getting started walks through a complete search page from here.
Why Fuzor
- Results you can trust. Totals are exact up to
totalHits(1,000 by default), and facet counts are exact over up to 50,000 matching documents. Where a limit makes a result approximate, the result says so (exhaustive,approximateFacets,warnings) instead of quietly showing a smaller number. The ranking is tested against a brute-force reference implementation, and CI runs the tests on the oldest supported SQLite (3.46.0) and the latest release. - Fast where a shop spends its time. On a catalog of tens of thousands of products, shop pages with facets and sorted listings take a few milliseconds and searches tens of milliseconds, and an update or delete of a few hundred products well under a second. What each option costs is in Performance.
- Grows with you. On over a million products, searches and filtered category pages with facets stay within tens of milliseconds, in one PHP process.
- Nothing to operate. One file per index, read by any number of PHP workers. Rebuilds, snapshots and installing an index built on another server publish the new file atomically, so readers never see a half-written index.
Features
- Search: BM25 ranking with proximity, typo tolerance, search-as-you-type prefixes, quoted phrases,
-wordand-"phrase"exclusions, matching strategies, synonyms, boolean queries with AND / OR / NOT (Searching) - Filters and facets: value, list and range filters, exclusions, nested
Filter::all()/any()/not(), facet counts and stats, counts that stay visible while a value is selected, facet value search (Filtering and facets) - Sorting on any number of fields, and
distinctto show one hit per product group (Sorting) - Highlighting and excerpts, with HTML-safe output when you ask for it (Formatting)
- Languages: Chinese, Japanese, Korean and Thai split into n-grams automatically; optional stemming with a stemmer class of your own, and stop words (Language)
- Indexing: insert, update, upsert, delete and delete by filter; HTML stripped at index time; bulk loads in bounded memory; an optional document store (Indexing)
- Operations: atomic rebuilds, snapshots, installing a prebuilt file, reader/writer setups (Operations)
- Debugging:
inspectQuery()and per-hit ranking details show why a document matched and where it ranked (Debugging)
When to use something else
Fuzor runs inside your PHP process on one machine. Pick a search server instead when you need search spread over several machines, vector or semantic search, or the lowest latency on catalogs of millions of products with heavy traffic. Up to that point, a single file you can copy, snapshot and ship with your application is usually the simpler choice.
Requirements
- PHP 8.5+ (64-bit) with the
pdo_sqliteandmbstringextensions - SQLite 3.46.0+, the library PHP's
pdo_sqliteis linked against. An older library or a 32-bit PHP is refused with aFuzorExceptionwhen an index is opened.
Documentation
Start with Getting started and Concepts; every page is listed in the documentation index. The API reference lists every class and option.
Upgrading from 1.x: see UPGRADE-2.0.md and the changelog. Indexes written by 1.x have to be rebuilt.
Contributing
Bug reports and pull requests are welcome; see CONTRIBUTING.md. Report security issues as described in SECURITY.md.
License
MIT, see LICENSE.