PHP code example of matchish / laravel-scout-elasticsearch
1. Go to this page and download the library: Download matchish/laravel-scout-elasticsearch 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/ */
matchish / laravel-scout-elasticsearch example snippets
'providers' => [
// Other Service Providers
\Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class
],
use Matchish\ScoutElasticSearch\Searchable\ImportSourceFactory;
...
public function register(): void
{
$this->app->bind(ImportSourceFactory::class, MyImportSourceFactory::class);
namespace Matchish\ScoutElasticSearch\Searchable;
final class MyImportSourceFactory implements ImportSourceFactory
{
public static function from(string $className): ImportSource
{
//Add all * @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->with('comments');
}
}
class Product extends Model
{
use Searchable;
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$with = [
'categories',
];
$this->loadMissing($with);
return $this->toArray();
}
}
Product::search('(title:this OR description:this) AND (title:that OR description:that)')
Product::search('(title:this OR description:this) AND (title:that OR description:that)')
->where('price', 100)
->whereIn('type', ['used', 'like new'])
->whereNotIn('type', ['new', 'refurbished']);
use ONGR\ElasticsearchDSL\Query\TermLevel\RangeQuery;
Product::search('(title:this OR description:this) AND (title:that OR description:that)')
->where('price', new RangeQuery('price', [
RangeQuery::GTE => 100,
RangeQuery::LTE => 1000,
]);
use ONGR\ElasticsearchDSL\Query\TermLevel\RangeQuery;
Product::search()
->where('price', new RangeQuery('price', [
RangeQuery::GTE => 100,
]);
MixedSearch::search('title:Barcelona or to:Barcelona')
->within(implode(',', [
(new Ticket())->searchableAs(),
(new Book())->searchableAs(),
]))
->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.