matchish / laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout
MIT License
702 stars 113 forks source link

[Feature] Utilize custom "options" of a builder #252

Open robertbrowncc opened 1 year ago

robertbrowncc commented 1 year ago

When I make a search call like this:

$results = Statement::search('automated_detection:true')->options([
   'size' => 100
])->keys();

I always get 10 results.

When I look at this function:

\Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine::search
public function search(BaseBuilder $builder)
{
    return $this->performSearch($builder, []);
}

the [] is always sending blank options.

When I change it to bring in the options.

public function search(BaseBuilder $builder)
{
    return $this->performSearch($builder, $builder->options);
}

Then I get a result with 100 results in it.

Am I calling the options and search correctly? Is this a bug?

robertbrowncc commented 1 year ago

I was able to get it to work like this too albeit a little funky:

$results = Statement::search('automated_detection:true',
    function (Client $client, Search $search) {
            $search->setSize(100);
            return $client->search(['index' => 'statements', 'body' => $search->toArray()]);
    })->keys();
matchish commented 1 year ago

Didn't notice options api. Make sense to integrate. Could be useful for simple cases