Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass additional parameters on search method #198

Closed
marksparrish opened this issue Jun 4, 2017 · 5 comments
Closed

pass additional parameters on search method #198

marksparrish opened this issue Jun 4, 2017 · 5 comments

Comments

@marksparrish
Copy link

I would like to be able to pass an additional parameter on search method.

Currently you only pass the string you want to search for -
$orders = App\Order::search('Star Trek')->get();
However it would be nice to pass an additional parameter after the string -

$params = [
    '_source' => ['person_id', 'physical_address'],
    'body' => [
        'query' => [
            'multi_match' => [
                'query' => $query,
                'type' => 'cross_fields',
                'operator' => 'and',
                'fields' => ['physical_address'],
    
            ],
        ]
    ]
];

$orders = App\Order::search('Star Trek', $params)->get();
@marksparrish
Copy link
Author

Looks like this may work better - https://stackoverflow.com/questions/39541603/how-can-you-set-boosts-and-filters-with-laravel-scout-and-elasticsearch.

Create your own by forking/extending the current driver.

@trideout
Copy link

trideout commented Aug 4, 2017

+1 here. Can't use Scout because of the very limited where system, I'd love to be able to set a much greater number of filters.

@julienbourdeau
Copy link
Contributor

You can achieve this with the callback. I have checked for Elastic, but it should be similar to what we do with Algolia:

$moreOptions = [....];

Model::search($query, function ($algolia, $query, $options) use ($moreOptions) {

    $options = array_merge($options, $moreOptions);

    return $algolia->search($query, $options);
})

If your Scout is up to date, you can create a macro to keep it simple. You can find an example here.

Although, I agree it would be great to have a with method to do it easily.

Model::search($q)->with($extra)->get();

@trideout
Copy link

trideout commented Aug 8, 2017

@julienbourdeau that will work great for the time being, but I would love to see the filters get more functionality like the query statements in Eloquent. Mapping an array to $key.'='.$value seems lazy.

@driesvints
Copy link
Member

You could now use https://github.com/algolia/scout-extended which has this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants