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

Overview

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.

Comments
  • Initial Elasticsearch support

    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
    opened by hernandev 62
  • php artisan scout:import not indexing

    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

    opened by lmxdev 29
  • Simple delete() has no effect

    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.

    needs more info 
    opened by MrMooky 25
  • queueRemoveFromSearch() should optionally use a queue

    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.

    enhancement 
    opened by chamby 22
  • [6.0] Allow to change the builder implementation using the container

    [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
            );
    
    opened by nunomaduro 19
  • orderBy doesn't work

    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?

    opened by calvinmuller 18
  • "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.

    opened by harrygr 18
  • scout:flush command doesn't flush/remove anything?

    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.

    bug 
    opened by bbashy 17
  • [9.x] Use scout key when mapping keys from search results

    [9.x] Use scout key when mapping keys from search results

    Trying a fix against https://github.com/laravel/scout/issues/651

    This PR overloads the keys() method in the base Engine class providing MeilisearchEngine the exact Scout key to be used when mapping search results.

    Previously the key was determined by taking the first key of the array in the search response. However as recently discovered in the aforementioned issue - Meilisearch will return random array order depending on its index configuration.

    opened by flexchar 16
  • Meilisearch engine pagination total broken

    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);

    bug 
    opened by eliasjtg 16
  • [9.x] Add Searchable contract to complement trait

    [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.

    opened by wimski 16
  • [10.x] Meilisearch v1 preparation

    [10.x] Meilisearch v1 preparation

    wip

    TODO:

    • [ ] Migration guide
      • [ ] casing of the the client in the service container has been renamed (use the correct \Meilisearch\Client)
      • [ ] minimum required meilisearch-php library version v1
      • [ ] Usage of the new pagination implementation of meilisearch (page/hitsPerPage) which makes the search results exhausitve instead of estimated
      • [ ] No workarounds for earlier meilisearch-php library versions (filters => filter)
    opened by mmachatschek 9
Releases(v9.7.0)
Owner
The Laravel Framework
The Laravel Framework
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

Protone Media 844 Dec 25, 2022
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

TNT Studio 1k Dec 27, 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,

Ivano Matteo 10 Nov 10, 2022
Elasticsearch driver for Laravel Scout

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

Ivan Babenko 197 Dec 19, 2022
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

Sergey Shlyakhov 592 Dec 25, 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

Ripa Club 62 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

Algolia 240 Nov 25, 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

Tom Lingham 533 Nov 25, 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

SWIS 171 Jan 4, 2023
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

Ivan Babenko 1.2k Dec 20, 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

Elasticquent 1.3k Jan 4, 2023
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

Sleiman Sleiman 511 Dec 31, 2022
The official SingleStore Laravel driver.

SingleStore Driver for Laravel This repository contains a SingleStore Driver for Laravel. Install You can install the package via composer: composer r

SingleStore Labs 197 Jan 1, 2023
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

Nicolás López Jullian 2k Dec 27, 2022
Laravel 8.* Elasticsearch Eloquent

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

Etsetra 2 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

null 1 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

A doer with magic 2 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.

interconnect/it 3.9k Jan 5, 2023
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

JobApis 93 Nov 13, 2022