- Notifications
You must be signed in to change notification settings - Fork46
MeiliSearch integration for Laravel Scout
License
meilisearch/meilisearch-laravel-scout
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
⚡ The MeiliSearch driver for Laravel Scout
MeiliSearch Laravel Scout is aMeiliSearch driver for Laravel.
MeiliSearch is an open-source search engine.Discover what MeiliSearch is!
- 📖 Documentation
- 🔧 Installation
- 🚀 Getting Started
- 🤖 Compatibility with MeiliSearch
- 💡 Learn More
- Development Workflow and Contributing
See ourDocumentation or ourAPI References.
Also, take a look at theWiki of this repository!
composer require meilisearch/meilisearch-laravel-scout
You could use anyPSR-18 compatible client to use with this SDK. No additional configurations are required.
A list of compatible HTTP clients and client adapters can be found atphp-http.org.
If you useLaravel 8 you can skip this section as laravel pre-install Guzzle 7 by default.
Guzzle 7:
composer require guzzlehttp/guzzle
If you already have guzzle installed with a version < 7, don't forget to update the version inside your composer.json
"require": {"guzzlehttp/guzzle":"^7.0"}
Guzzle 6:
composer require php-http/guzzle6-adapter
Symfony Http Client:
composer require symfony/http-client nyholm/psr7
Curl:
composer require php-http/curl-client nyholm/psr7
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"php artisan vendor:publish --provider="Meilisearch\Scout\MeilisearchServiceProvider" --tag="config"
SCOUT_DRIVER=meilisearchMEILISEARCH_HOST=http://127.0.0.1:7700MEILISEARCH_KEY=masterKey
There are many easy ways todownload and run a MeiliSearch instance.
For example, if you use Docker:
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
NB: you can also download MeiliSearch fromHomebrew orAPT.
// Create an indexphp artisan scout:index books// Create an index and give the primary-keyphp artisan scout:index books --key book_id
<?phpuseLaravel\Scout\Searchable;class Bookextends Model{use Searchable;}
<?phpclass BookControllerextends Controller{publicfunctionstore() {$book =newBook();$book->title ='Pride and Prejudice';...$book->save(); }}
You can also import all your table to meilisearch by using the artisan command:
php artisan scout:import"App\Book"class BookControllerextends Controller{publicfunctionsearch() {// MeiliSearch is typo-tolerant: Book::search('harry pottre')->get();// Or if you want to get the result from meilisearch: Book::search('harry pottre')->raw(); }}
class BookControllerextends Controller{publicfunctiondestroy($id) {// Delete one document Book::find($id)->delete();// Delete several documents Book::destroy([1,42]);// Delete all documents /!\ Book::query()->delete(); }}
or you can use the artisan command to delete all documents from an index:
php artisan scout:flush"App\Book"php artisan scout:index -d books
All the supported options are described in thesearch parameters section of the documentation.
useMeiliSearch\Endpoints\Indexes;class BookControllerextends Controller{publicfunctioncustomSearch() { Book::search('prince',function (Indexes$meilisearch,$query,$options) {$options['filters'] ='author="Antoine de Saint-Exupéry"';return$meilisearch->search($query,$options); })->take(3)->get(); }}
class BookControllerextends Controller{publicfunctionsearch() { Book::search('mustang')->paginate();// with a limit of items per page: Book::search('mustang')->paginate(5);// using meilisearch response: Book::search('mustang')->paginateRaw(); }}
This package only guarantees the compatibility with theversion v0.20.0 of MeiliSearch.
If you're not familiar with MeiliSerach yet, the following sections may interest you:
- Manipulate documents: see theAPI references or read more aboutdocuments.
- Search: see theAPI references or follow our guide onsearch parameters.
- Manage the indexes: see theAPI references or read more aboutindexes.
- Configure the index settings: see theAPI references or follow our guide onsettings parameters. Also, theWiki of this repository will guide you through the configuration!
💡 You can use more advance function by reading the documentation ofMeiliSearch PHP Client.
👍 This package is a custom engine ofLaravel Scout.
Any new contribution is more than welcome in this project!
If you want to know more about the development workflow or want to contribute, please visit ourcontributing guidelines for detailed instructions!
MeiliSearch provides and maintains manySDKs and Integration tools like this one. We want to provide everyone with anamazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in theintegration-guides repository.
About
MeiliSearch integration for Laravel Scout
Topics
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.