PHP code example of thomasjsn / laravel-scout-elastic

1. Go to this page and download the library: Download thomasjsn/laravel-scout-elastic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thomasjsn / laravel-scout-elastic example snippets


// config/app.php
'providers' => [
    ...
    Laravel\Scout\ScoutServiceProvider::class,
    ...
    ScoutEngines\Elasticsearch\ElasticsearchProvider::class,
],

// config/scout.php
// Set your driver to elasticsearch
    'driver' => env('SCOUT_DRIVER', 'elasticsearch'),

class Article extends Model
{
    // ...
    public static function mapping() {
        return [
            'location' => [
                'type' => 'geo_point'
            ],
        ];
    }
    // ...
}

 'indices' => [

    'realestate' => [
        'settings' => [
            "number_of_shards" => 1,
            "number_of_replicas" => 0,
        ],
        'mappings' => [
            'articles' => \App\Article::mapping(),
        ],
    ],
 ]

$articles = Article::search($keywords)
            ->orderBy('id', 'desc')
            ->get();

class Article extends Model
{
    // use Searchable;
    use ElasticSearchable;
    // ...
}

$articles = Article::elasticSearch('multi_match', $q, [
    'fields' => ['title', 'content', 'tags'],
    'fuzziness' => 'auto',
    'prefix_length' => 2,
    'operator' => 'AND'
])->get();

public function searchableWithin()
{
    return 'foobar';
}

php artisan vendor:publish --provider="ScoutEngines\Elasticsearch\ElasticsearchProvider"

php artisan elastic:make-indices

php artisan elastic:indices