A full text search engine with tokenization, stemming, typo tolerance, filters and geo support based on only PHP and SQLite.
A full text search engine with tokenization, stemming, typo tolerance, filters and geo support based on only PHP and SQLite.
Read the documentation: loupe-php.github.io/loupe
Loupe…
" quotation marks- as modifierbrush finds toothbrushLIKE %...% queries with a way better search
experience but without all the hassle of an additional service to manage. SQLite is everywhere and all it needs is
your filesystem.If this is your first encounter with Loupe, you might want to read the blog post on Medium or as Markdown file that should give you more information about the reasons and what you can do with it. Note that some implementation details (e.g. libraries used) referenced in this blog post are not up-to-date anymore.
Performance depends on many factors but here are some ballpark numbers based on indexing the ~32k movies fixture provided by MeiliSearch.
Amakin Dkywalker with typo tolerance and relevance ranking takes **withPrimaryKey('uuid') // optional, by default it's 'id'
->withSearchableAttributes(['firstname', 'lastname']) // optional, by default it's ['*'] - everything is indexed
->withFilterableAttributes(['departments', 'age'])
->withSortableAttributes(['lastname'])
->withTypoTolerance(TypoTolerance::create()->withFirstCharTypoCountsDouble(false)) // can be further fine-tuned but is enabled by default
;$loupe = (new LoupeFactory())->create('path/to/my_loupe_data_dir', $configuration);
To create an in-memory search client:
```php
$loupe = (new LoupeFactory())->createInMemory($configuration);$loupe->addDocuments([
[
'uuid' => 2,
'firstname' => 'Uta',
'lastname' => 'Koertig',
'departments' => [
'Development',
'Backoffice',
],
'age' => 29,
],
[
'uuid' => 6,
'firstname' => 'Huckleberry',
'lastname' => 'Finn',
'departments' => [
'Backoffice',
],
'age' => 18,
],
]);$searchParameters = SearchParameters::create()
->withQuery('Gucleberry')
->withAttributesToRetrieve(['uuid', 'firstname'])
->withFilter("(departments = 'Backoffice' OR departments = 'Project Management') AND age > 17")
->withFacets(['departments', 'age'])
->withSort(['lastname:asc'])
;
$results = $loupe->search($searchParameters);The $results array contains a list of search hits and metadata about the query.
print_r($results->toArray());
[
'hits' => [
[
'uuid' => 6,
'firstname' => 'Huckleberry'
]
],
'query' => 'Gucleberry',
'processingTimeMs' => 4,
'hitsPerPage' => 20,
'page' => 1,
'totalPages' => 1,
'totalHits' => 1,
'facetDistribution' => [
'departments' => [
'Backoffice' => 1,
],
],
'facetStats' => [
'age' => [
'min' => 18,
'max' => 18,
],
],
]The documentation is available at loupe-php.github.io/loupe.
"Why Loupe?" you ask? "Loupe" means "magnifier" in French and I felt like this was the appropriate choice for this library after having given my PHP crawler library a French name :-)
No open issues yet, or sync has not completed.