2017 © Pedro Peláez
 

library elastic-laravel

Elastic Search Indexer for Laravel 5

image

mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  • Thursday, August 24, 2017
  • by mabadir
  • Repository
  • 1 Watchers
  • 2 Stars
  • 17 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

elastic-laravel

Latest Version on Packagist ![Software License][ico-license] Quality Score ![Total Downloads][ico-downloads], (*1)

Elastic Search Indexer for Laravel 5., (*2)

Structure

If any of the following are applicable to your project, then the directory structure should follow industry best practises by being named the following., (*3)

config/
src/
tests/
vendor/

Install

Via Composer, (*4)

``` bash $ composer require mabadir/elastic-laravel, (*5)


## Usage Add the `ElasticLaravelServiceProvider` to your `config/app.php`. ``` php 'providers' => [ //Other providers MAbadir\ElasticLaravel\ElasticLaravelServiceProvider::class, ],

Publish the elastic.php to your configuration. ``` bash $ php artisan vendor:publish, (*6)

Add the ElasticEloquent trait to your Eloquent model to have it indexed.

``` php
namespace App;

use MAbadir\ElasticLaravel\ElasticEloquent;

class User extends Authenticatable
{
    use ElasticEloquent;

}

For searching the index, you can run search with different approaches. The first step is to add the Facade to your config/app.php:, (*7)

``` php 'aliases' => [ //Other Facades 'ElasticSearcher' => MAbadir\ElasticLaravel\ElasticSearcher::class, ],, (*8)


1. Simple term search: ```php ElasticSearcher::search('simple term');
  1. Simple term search on specific model type:
$user = App\User::first();
ElasticSearcher::search('Simple Term', $user);

This will search the Elastic Search index for the simple term with type=users., (*9)

  1. Search index on specific parameter:
ElasticSearcher::search(['name' => 'First Name']);

This will search the complete Search Index for the parameter name with value First Name, (*10)

  1. Search index on specific parameter and specific model type:
$user = App\User::first();
ElasticSearcher::search(['name' => 'First Name'], $user);

This will search the Search Index for the parameter name with value First Name on type=users., (*11)

  1. Advanced Search:
$params = [
            'body' => [
                'query' => [
                    'match' => [
                        '_all' => 'Simple Term'
                    ]
                ]
            ]
        ];
ElasticSearcher::advanced($params);

This exposes the complete Elastic Search powerful query DSL interface, this will accept any acceptable Elastic Search DSL query., (*12)

  1. Advanced Search:
$user = User::first();
$params = [
            'body' => [
                'query' => [
                    'match' => [
                        '_all' => 'Simple Term'
                    ]
                ]
            ]
        ];
ElasticSearcher::advanced($params, $user);

This will search the index using the advanced query for type=users., (*13)

For the different functions, the class name can be used instead of the object itself, the object or the class should be extending Eloquent Model class \Illuminate\Database\Eloquent\Model. For example:, (*14)

ElasticSearcher::search(['name' => 'First Name'], User::class);

ElasticSearch Indexing Console Command

By default the package provides a default index initialization command:, (*15)

$ php artisan es:init

The default command will initialize the index with very basic settings. If it is required to initialize the index with more advanced settings and custom mappings: Create a new Console Command in your application:, (*16)

$ php artisan make:command IndexIntializationCommand

Import the IndexInitializationTrait class, and overload the $params attribute:, (*17)

namespace App\Console\Commands;

use Illuminate\Console\Command;
use MAbadir\ElasticLaravel\Console\IndexInitializationTrait;

class IndexIntializationCommand extends Command
{
    use IndexInitializationTrait;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'es:initialize';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Initialize ElasticSearch Index';

    /**
     * Parameters array
     * 
     * @var array
     */
    protected $params = [
        //Custom Settings
    ];
}

For more details on the configuration parameters, check the official ElasticSearch documentation., (*18)

Change log

Please see CHANGELOG for more information on what has changed recently., (*19)

Testing

bash $ composer test, (*20)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*21)

Security

If you discover any security related issues, please email mina@abadir.email instead of using the issue tracker., (*22)

Credits

License

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

The Versions

24/08 2017

dev-master

9999999-dev https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

24/08 2017

1.1.4

1.1.4.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

27/03 2017

1.1.3

1.1.3.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

27/03 2017

1.1.1

1.1.1.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

27/03 2017

1.1.2

1.1.2.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

27/03 2017

1.1.0

1.1.0.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

21/03 2017

1.0.1

1.0.1.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

21/03 2017

0.1.0

0.1.0.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel

21/03 2017

1.0.0

1.0.0.0 https://github.com/mabadir/elastic-laravel

Elastic Search Indexer for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

mabadir elastic-laravel