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/searchlightRegister 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 searchlightSetup 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:rebuildThis 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.