omure / scout-advanced-meilisearch
Laravel Scout extension that allows to use meilisearch advanced features as well as has an extended collection driver for testing purposes.
Installs: 3 869
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 1
Forks: 5
Open Issues: 1
Type:laravel-package
Requires
- php: ^8.1
- laravel/framework: ^9.0
- laravel/scout: ^9.4
- meilisearch/meilisearch-php: ^0.26
Requires (Dev)
- orchestra/testbench: 7.0
README
What this package provides
Extended scout query builder
Added next changes to the basic query builder:
where('column', '<=', $value)
- extended where, which supports 3 optional parameters for comparison. Two parameters are also allowed.where(Clusure $query)
- where can take a closure as the first parameter in order to group queries (the same fororWhere
)whereBetween('column', [$value1, $value2])
whereNotIn('column', [$value1, $value2, $value3])
- All where clauses have or variant:
orWhere
,orWhereIn
, etc
Two scout drivers
The drivers are compatible with the new scout builder.
- meilisearch_advanced
- collection_advanced
meilisearch_advanced
Uses all the advantages of meilisearch for comparison the results, searching in indexed arrays.
Also fixes an issue with the calculation of the total number of values.
(The current implementation requests the entire dataset in case scout builder has ->query()
method used)
collection_advanced
The driver imitates how meilisearch work and completely relies on collections. It should be used only for tests as the whole searchable models data is in memory. The driver allows testing filtering and sorting as well as Extended scout builder features.
Meilisearch specific are taken into account
Meilisearch requires updating indexes filterable, sortable and searchable attributes in order to save the indexing data properly.
This package provides MeiliSearch
facade that has updateIndexSettings
method that handles that automatically.
How to use?
- In
config/scout.php
set'driver'
tomeilisearch_advanced
orcollection_advanced
- Apply Searchable trait to the model (
Omure\ScoutAdvancedMeilisearch\Searchable
); - For proper handling of the model, implement
Omure\ScoutAdvancedMeilisearch\Interfaces\MeiliSearchSearchableModel
interface to the model - Describe indexed parameters for searching in
toSearchableArray()
method of the model (the same way as Scout does) - Specify searchable, filterable and sortable attributes by defining the next list of methods on the model:
getSearchableAttributes()
- for usingsearch()
statementsgetFilterableAttributes()
- for usingwhere()
, includingwhereIn
,whereNotIn
, etc. statementsgetSortableAttributes()
- for usingorderBy()
statementgetTypoToleranceSettings()
- for typo tolerance All methods should return an array of strings which are the names of the parameters specified intoSearchableArray()
.
If you change the methods getSearchableAttributes()
, getFilterableAttributes()
, or getSortableAttributes()
returned indexes, you have to let meilisearch know about the changes. For that purpose use the facade:
MeiliSearch::updateIndexSettings(new User());
The method takes a model instance to update the parameters on the meilisearch server.
Keep in mind that toSearchableArray()
doesn't have to have the same indexes as the database column names.
You can specify your own logic for searching and filtering. Use the specified parameters in your Scout Builder.