Laravel Scout provides a driver based solution to searching your Eloquent models.

Last update: Aug 8, 2022

Build Status Total Downloads Latest Stable Version License

Introduction

Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and configured, it will automatically sync your model changes to your search indexes. Currently, Scout supports Algolia, a blazing-fast and hosted search service.

Official Documentation

Documentation for Scout can be found on the Laravel website.

Contributing

Thank you for considering contributing to Scout! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Scout is open-sourced software licensed under the MIT license.

GitHub

https://github.com/laravel/scout
Comments
  • 1. Initial Elasticsearch support

    Reopened since squashing would include other poeples commits from the upstream sync.

    Initial Elasticsearch support, tests on the way.

    Some options may differ and I may make a custom config key for customizing the query parameter, Elastic can be really complex but this setup should cover most scenarios.

    Working right now:

    • Searching
    • Searching with where conditions
    • Pagination
    • Unit Testing :)

    TODO:

    • For future implementations, for both algolia and elastic, may the performSearch be a replaceable callback,so people can extend and customize it, gonna send a separate PR on it
    Reviewed by hernandev at 2016-08-13 20:27
  • 2. php artisan scout:import not indexing

    So basically I deployed my app to production, and I'm having an issue with Scout not importing the records. in a component I have:

    var algoliasearch = require('algoliasearch');
    var client = algoliasearch('ID', 'KEY');
    var = index = client.initIndex('prod_users'); // index i created in algolia with 0 records
    

    my production database has 1 user on my server I run

    php artisan scout:import "App\User"
    

    and it says:

    Imported [App\User] models up to ID: 1
    All [App\User] records have been imported.
    

    but when I look into my algolia dashboard in the indexes section, my prod_users index has 0 records

    Reviewed by lmxdev at 2017-04-07 13:14
  • 3. Simple delete() has no effect

    I've been trying to understand this for some time now, but cannot seem to find a fix. Adding and updating a model to Algolia works just fine. But I cannot remove/delete the user from the Algolia index.

    Example: ObjectID = 100, which is the users id. When calling User::find(100)->delete(); the user gets deleted from my app, but remains in the Algolia index. As far as I can see from the docs, this is how it should work, right?

    Even calling User::find($userid)->unsearchable(); before deleting the user has no effect on the index.

    Reviewed by MrMooky at 2018-04-22 15:16
  • 4. queueRemoveFromSearch() should optionally use a queue

    Engine delete operations, much like update operations, invoke the network and add latency. I would expect Searchable::queueRemoveFromSearch() to optionally use a queue just like Searchable::queueMakeSearchable() does. It even has queue in the name.

    A new Job called MakeUnsearchable would also need to be created.

    Reviewed by chamby at 2018-12-04 19:58
  • 5. [6.0] Allow to change the builder implementation using the container

    This Pull Request adds the possibility of changing the concrete implementation of the Builder::class. Behind the scenes, the developer can now specify is own implementation doing:

            $this->app->bind(
                \Laravel\Scout\Builder::class,
                \My\Custom\Builder::class
            );
    
    Reviewed by nunomaduro at 2018-11-20 16:15
  • 6. orderBy doesn't work

    Hi there,

    I'm using scout with algolia to index a large database of products, however when trying to sort the results, i'm not getting the desired results.

    $products = Product::search('')
                    ->orderBy('name', 'asc')
                    ->paginate();
    

    Anything i'm missing for this to return results ordered by name?

    Reviewed by calvinmuller at 2017-09-06 07:41
  • 7. "null" driver not settable via env variable

    When trying to set the scout engine to the "null" implementation (e.g. say as a fallback for when no env variable exists: 'driver' => env('SCOUT_DRIVER', 'null') or for tests) the string "null" is parsed into a php null value instead resulting in an instantiation error.

    Suggest either renaming the null driver so something else like nullsearcher unless there is a way in phpunit.xml and .env it can be set as a string.

    Reviewed by harrygr at 2016-08-22 22:10
  • 8. scout:flush command doesn't flush/remove anything?

    It seems scout:flush doesn't seem to do anything. Deleting a record from the database manually then doing scout:flush and/or scout:import doesn't remove the old record.

    Reviewed by bbashy at 2016-10-12 10:42
  • 9. Meilisearch engine pagination total broken

    • Scout Version: 9.4.6
    • Scout Driver: MeiliSearch
    • Laravel Version: 8.83.6
    • PHP Version: 8.0.16
    • Database Driver & Version: Mysql 8.0.28-0ubuntu0.20.04.3
    • SDK Version (If using a third-party service): 0.23.1

    Description:

    This issue is related with https://github.com/laravel/scout/issues/535 and map id with key name, the solution was https://github.com/laravel/scout/commit/8a7782c5ce72b9407a3cb2e29a4865cf4efc964b creating mapIdsFrom method

    The same issue is occurring with the method keys in Engine, does not take into account mapIdsFrom and call directly mapIds, which breaks the pagination count.

    A solution is create keysFrom method:

    /**
         * Get the results of the query as a Collection of primary keys.
         *
         * @param  \Laravel\Scout\Builder  $builder
         * @param  string  $key
         * @return \Illuminate\Support\Collection
         */
        public function keysFrom(Builder $builder, $key)
        {
            return $this->mapIdsFrom($this->search($builder), $key);
        }
    

    and modify the getTotalCount method:

    /**
         * Get the total number of results from the Scout engine, or fallback to query builder.
         *
         * @param  mixed  $results
         * @return int
         */
        protected function getTotalCount($results)
        {
            $engine = $this->engine();
    
            $totalCount = $engine->getTotalCount($results);
    
            if (is_null($this->queryCallback)) {
                return $totalCount;
            }
    
            $ids = $engine->mapIdsFrom(
                $results,
                $key = Str::afterLast($this->model->getScoutKeyName(), '.')
            )->all();
    
            if (count($ids) < $totalCount) {
                $ids = $engine->keysFrom(tap(clone $this, function ($builder) use ($totalCount) {
                    $builder->take(
                        is_null($this->limit) ? $totalCount : min($this->limit, $totalCount)
                    );
                }), $key)->all();
            }
    
            return $this->model->queryScoutModelsByIds(
                $this, $ids
            )->toBase()->getCountForPagination();
        }
    

    Changing $key = Str::afterLast($this->model->getScoutKeyName(), '.') and calling $engine->keysFrom reusing the $key variable

    Steps To Reproduce:

    Using query() reproduce the bug

    return Post::search($search)->query(function($query) { $query->with('image'); })->paginate(5);

    Reviewed by eliasjtg at 2022-04-06 14:59
  • 10. [9.x] Add Searchable contract to complement trait

    In a recent project using Scout I wanted to check if a class uses the Searchable trait. Currently this can only be achieved by one of the following options:

    // A. check trait usage
    if (! in_array(Searchable::class, class_uses($model)) {
        throw new Exception();
    }
    
    // B. check method existence
    if (! method_exists($model, 'searchableAs')) {
        throw new Exception();
    }
    
    • Option A will work, but static analysis will not understand that $model has a specific set of methods.
    • Option B does support static analysis, but is messy, because it doesn't really check for the trait (or specific contract).

    Therefore I've added a contract to complement the trait.

    use Laravel\Scout\Contracts\Searchable as SearchableContract;
    
    if (! $model instanceof SearchableContract::class) {
        throw new Exception();
    }
    

    This contract is not required for general use of Scout and is not a breaking change.

    Reviewed by wimski at 2021-07-02 08:57
  • 11. Use queued job for "unsearching" when Scout queue is enabled

    Description:

    Closes https://github.com/laravel/scout/issues/331

    This PR adds a RemoveFromSearch queuable job which will be dispatched when scout.queue is enabled.

    This specific queuable job has an overwritten restoreCollection() method that instantiates an Eloquent collection of the deleted models, by force-filling the model primary keys supplied by the ModelIdentifier object. This allows extended Scout engines to retrieve the ID used for indexing, so they can purge records properly.

    All credit goes to @matt-allan, as this is a slightly modified copy of his work on his forked repo πŸ™Œ


    References:

    Here are references to the most popular Scout Elasticsearch packages (they only use getScoutKey() for retrieving a unique identifier for the model):

    https://github.com/babenkoivan/elastic-scout-driver/blob/2e45a933dcc8b051b25cbf8010623e51ac457a35/src/Factories/DocumentFactory.php#L24

    https://github.com/babenkoivan/scout-elasticsearch-driver/blob/15d349a0401e2bab6f774255dc3668fd28b6d4a0/src/Indexers/BulkIndexer.php#L67

    https://github.com/babenkoivan/scout-elasticsearch-driver/blob/15d349a0401e2bab6f774255dc3668fd28b6d4a0/src/Payloads/DocumentPayload.php#L19-L29

    Reviewed by stevebauman at 2021-05-11 02:34
Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

Laravel Cross Eloquent Search This Laravel package allows you to search through multiple Eloquent models. It supports sorting, pagination, scoped quer

Aug 9, 2022
Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch
Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 8.0 This package makes it easy to add full text search support to your models with Laravel 5.3 to 8

Jul 20, 2022
A scout DB fulltext-based driver that store index data in related tables

A scout DB fulltext-based driver that store index data in related tables This package provide a Laravel/Scout Engine based on database/fulltext only,

Aug 5, 2022
Elasticsearch driver for Laravel Scout
Elasticsearch driver for Laravel Scout

Elasticsearch driver for Laravel Scout. Contents Compatibility Installation Configuration Basic Usage Advanced Search Migrations Pitfalls Compatibilit

Aug 6, 2022
Search among multiple models with ElasticSearch and Laravel Scout
Search among multiple models with ElasticSearch and Laravel Scout

For PHP8 support use php8 branch For Laravel Framework < 6.0.0 use 3.x branch The package provides the perfect starting point to integrate ElasticSear

Aug 8, 2022
Sphinx Search library provides SphinxQL indexing and searching features

Sphinx Search Sphinx Search library provides SphinxQL indexing and searching features. Introduction Installation Configuration (simple) Usage Search I

Mar 14, 2022
[Deprecated] We now recommend using Laravel Scout, see =>

[DEPRECATED] Algolia Search API Client for Laravel Algolia Search is a hosted full-text, numerical, and faceted search engine capable of delivering re

Aug 11, 2022
Unmaintained: Laravel Searchy makes user driven searching easy with fuzzy search, basic string matching and more to come!

!! UNMAINTAINED !! This package is no longer maintained Please see Issue #117 Here are some links to alternatives that you may be able to use (I do no

Jun 20, 2022
Fulltext indexing and searching for Laravel

Laravel fulltext index and search This package creates a MySQL fulltext index for models and enables you to search through those. Install Install with

Aug 6, 2022
This package offers advanced functionality for searching and filtering data in Elasticsearch.

Scout Elasticsearch Driver ?? Introducing a new Elasticsearch ecosystem for Laravel. ?? This package offers advanced functionality for searching and f

Aug 12, 2022
Maps Laravel Eloquent models to Elasticsearch types

Elasticquent Elasticsearch for Eloquent Laravel Models Elasticquent makes working with Elasticsearch and Eloquent models easier by mapping them to Ela

Aug 10, 2022
Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a fluent syntax for mapping, querying, and storing eloquent models.
Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a fluent syntax for mapping, querying, and storing eloquent models.

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a f

Aug 11, 2022
A php trait to search laravel models

Searchable, a search trait for Laravel Searchable is a trait for Laravel 4.2+ and Laravel 5.0 that adds a simple search function to Eloquent Models. S

Aug 14, 2022
Laravel 8.* Elasticsearch Eloquent
Laravel 8.* Elasticsearch Eloquent

Elasticsearch Installation composer require etsetra/elasticsearch Create config file $ php artisan vendor:publish --tag="etsetra-elasticsearch-config

Jan 14, 2022
This modules provides a Search API Backend for Elasticsearch.

Search API ElasticSearch This modules provides a Search API Backend for Elasticsearch. This module uses the official Elasticsearch PHP Client. Feature

Jan 20, 2022
Illusionist Searcher - Generates database queries based on search syntax

Illusionist Searcher Generates database queries based on search syntax. English | δΈ­ζ–‡ ✨ Features Zero configuration Compatible with laravel/scout and l

Feb 24, 2022
This script was made to aid the process of migrating PHP and MySQL based websites

This script was made to aid the process of migrating PHP and MySQL based websites. Works with most common CMSes.

Aug 7, 2022
Your personal job-search assistant

JobsToMail Your personal job-search assistant About JobsToMail is an open source web application that allows users to sign up to receive emails with j

Apr 7, 2022
A search package for Laravel 5.

Search Package for Laravel 5 This package provides a unified API across a variety of different full text search services. It currently supports driver

Jul 10, 2022