2017 © Pedro PelĂĄez
 

library laravel-search

Laravel Eloquent models with Elasticsearch 2

image

websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

  • Wednesday, June 21, 2017
  • by websecret
  • Repository
  • 2 Watchers
  • 4 Stars
  • 251 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

Laravel-Searchable

Laravel Eloquent models with Elasticsearch 2, (*1)

Installation and Requirements

First, you'll need to require the package with Composer:, (*2)

composer require websecret/laravel-search

Aftwards, run composer update from your command line., (*3)

Then, update config/app.php by adding an entry for the service provider., (*4)

'providers' => [
    // ...
    Websecret\LaravelSearchable\SearchableServiceProvider::class,
];

Finally, from the command line again, run php artisan vendor:publish --provider=Websecret\LaravelSearchable\SearchableServiceProvider to publish the default configuration file., (*5)

Updating your Eloquent Models

Your models should implement Searchable's interface and use it's trait. You should also define a protected property $searchable with any model-specific configurations (see Configuration below for details):, (*6)

use Websecret\LaravelSearchable\SearchableTrait;
use Websecret\LaravelSearchable\SearchableInterface;

class Article extends Model implements SearchableInterface
{
    use SearchableTrait;

    protected $searchable = [
        //'index' => 'domain_name',
        //'type' => 'articles',
        'fields' => [
            'title' => [
                'weight' => 3,
            ],
            'content',
            'category.title' => [
                'title' => 'category',
                'weight' => 1,
            ],
        ],
        //"fuzziness" => "AUTO",
        //"prefix_length"=> 2,
        //"max_expansions"=> 100,
    ];

}

Searching

Use search scope to find models. Result collection will be sorted by score., (*7)

    $articles = Article::where('is_active', 1)->search('apple')->get();

Indexing

Models auto indexing on updated, created and deleted events. You can use $article->searchIndex(); and $article->searchDelete(); to manually index or delete from index. Use Article::searchDeleteAll() to clear all index by specified model., (*8)

Config

fuzziness

Fuzzy matching treats two words that are “fuzzily” similar as if they were the same word., (*9)

Of course, the impact that a single edit has on a string depends on the length of the string. Two edits to the word hat can produce mad, so allowing two edits on a string of length 3 is overkill. The fuzziness parameter can be set to AUTO, which results in the following maximum edit distances:, (*10)

  • 0 for strings of one or two characters
  • 1 for strings of three, four, or five characters
  • 2 for strings of more than five characters

Of course, you may find that an edit distance of 2 is still overkill, and returns results that don’t appear to be related. You may get better results, and better performance, with a maximum fuzziness of 1., (*11)

prefix_length

The number of initial characters which will not be “fuzzified”. This helps to reduce the number of terms which must be examined., (*12)

max_expansions

The maximum number of terms that the fuzzy query will expand to., (*13)

The Versions

21/06 2017

v2.x-dev

2.9999999.9999999.9999999-dev https://github.com/websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

  Sources   Download

MIT

The Requires

 

by Avatar websecret

laravel eloquent search elasticsearch

21/06 2017

v2.1

2.1.0.0 https://github.com/websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

  Sources   Download

MIT

The Requires

 

by Avatar websecret

laravel eloquent search elasticsearch

22/05 2017

dev-master

9999999-dev https://github.com/websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

  Sources   Download

MIT

The Requires

 

by Avatar websecret

laravel eloquent search elasticsearch

22/05 2017

v2.0

2.0.0.0 https://github.com/websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

  Sources   Download

MIT

The Requires

 

by Avatar websecret

laravel eloquent search elasticsearch

07/07 2016

v1.0

1.0.0.0 https://github.com/websecret/laravel-search

Laravel Eloquent models with Elasticsearch 2

  Sources   Download

MIT

The Requires

 

by Avatar websecret

laravel eloquent search elasticsearch