PHP code example of woodfish / laravel-scout-elastic
1. Go to this page and download the library: Download woodfish/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/ */
woodfish / laravel-scout-elastic example snippets
// config/app.php
'providers' => [
...
Laravel\Scout\ScoutServiceProvider::class,
...
Woodfish\Elasticsearch\ElasticsearchProvider::class,
],
// config/scout.php
// Set your driver to elasticsearch
'driver' => env('SCOUT_DRIVER', 'elasticsearch'),
class Product extends Model
{
// ...
public static function mapping() {
return [
'title' => [
'type' => 'text'
],
];
}
// ...
}
'indices' => [
'realestate' => [
'settings' => [
"number_of_shards" => 1,
"number_of_replicas" => 0,
],
'mappings' => [
'product' => \App\Product::mapping(),
],
],
]
$products = Product::search($keywords)
->orderBy('price', 'desc')
->get();
class Product extends Model
{
// use Searchable;
use ElasticSearchable;
// ...
}
$products = Product::elasticSearch('multi_match', $q, [
'fields' => ['title', 'image', 'price'],
'fuzziness' => 'auto',
'prefix_length' => 2,
'operator' => 'AND'
])->get();
public function searchableWithin()
{
return 'foobar';
}
// lumen bootstrap/app.php
$app->register(Laravel\Scout\ScoutServiceProvider::class);
$app->register(Woodfish\Elasticsearch\ElasticsearchProvider::class);
php artisan vendor:publish --provider="Woodfish\Elasticsearch\ElasticsearchProvider"
php artisan elastic:make-indices
php artisan elastic:indices