Package Data | |
---|---|
Maintainer Username: | Naph |
Maintainer Contact: | naph@getgood.gg (Naph) |
Package Create Date: | 2017-05-20 |
Package Last Update: | 2018-09-10 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:00:41 |
Package Statistics | |
---|---|
Total Downloads: | 1,732 |
Monthly Downloads: | 11 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
An Elasticsearch search query language for Laravel featuring multi-model search
public function search(Search $search, Comment $comments, Post $posts)
{
return $search->in($comments, $posts)
->match('Searchlight')
->get();
}
and built-in qualifier reducers.
$driver->qualifier('/#(\w+)/', function (Search $search, $fragment) {
$search->filter(['tags' => $fragment]);
});
Using composer
composer require naph/searchlight
Register the service provider
Naph\Searchlight\SearchlightServiceProvider;
Publish vendor files containing driver and host configuration. Lumen users should copy the file instead.
php artisan vendor:publish --tag searchlight
Setup models by implementing the contract/trait pair and overriding getSearchableFields
. The trait binds events to saved and deleted so indices are kept in sync with your database.
use Illuminate\Database\Eloquent\Model;
use Naph\Searchlight\Model\SearchlightContract;
use Naph\Searchlight\Model\SearchlightTrait;
class Topic extends Model implements SearchlightContract
{
use SearchlightTrait;
public function getSearchableFields(): array
{
return [
'title' => 1,
'description' => 0.5,
'content' => 0.1
];
}
}
Storing this model's fully qualified classname in searchlight.repositories
config ensures their indices are built when running:
php artisan searchlight:rebuild
This command destroys all existing indexed documents in the process.
Currently only supports PHP7 and latest versions of Laravel and Lumen.
Searchlight is an open-sourced software licensed under the MIT license.