browner12/larasearch

Search package for Laravel

v2.1.0 2020-03-09 02:30 UTC

This package is auto-updated.

Last update: 2022-01-09 06:25:41 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

This is a search package built to easily integrate with Laravel. It uses a driver based system to abstract the internals of each specific search provider away from you. Currently only Elasticsearch is supported.

Why Not Use Scout?

There are 2 major differences between Scout and LaraSearch. First, Scout currently only has native support for Algolia, which is a service you pay for. They do have a free option, but this version has limits that will definitely be an issue for some. While Elasticsearch was originally supported, it was dropped due to complexity. There is a community effort to bring it back in as a native driver, but the road map on that is uncertain.

The second, and more important difference is that LaraSearch allows for 'site wide' searching, while Scout does not. In Scout, the searching is done on the models.

User::search('Andrew');

While this may be okay for some users, the far more common requirement is to be able to search an entire site. If a query is submitted for 'Andrew', I want to find the User Andrew, the Department he belongs to, and all of the Blog posts he has written. Additionally with LaraSearch, you are still able to restrict your search to a specific model if so desired.

Install

$ composer require browner12/larasearch

If you are using the Elasticsearch driver, you must also install their package

$ composer require elasticsearch/elasticsearch

Setup

Add the service provider to the providers array in config/app.php.

'providers' => [
    browner12\larasearch\LarasearchServiceProvider::class,
];

If you are using Laravel's auto-discovery, there is no need to complete this step.

Publishing

You can publish everything at once

php artisan vendor:publish --provider="browner12\larasearch\LarasearchServiceProvider"

or you can publish groups individually.

php artisan vendor:publish --provider="browner12\larasearch\LarasearchServiceProvider" --tag="config"

Usage

Your desired driver is bound to a Searcher interface, so anyplace you wish to use LaraSearch that supports automatic dependency resolution, you can simply type hint the interface.

class SearchController
{
    public function index(Searcher $searcher)
    {
        $results = $searcher->search('Andrew');
    }
}

Please see the DOCUMENTATION for more in-depth explanations.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email browner12@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.