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

Search Collection, not only Model #36

Open
ilikourou opened this issue Jul 18, 2015 · 2 comments
Open

Search Collection, not only Model #36

ilikourou opened this issue Jul 18, 2015 · 2 comments

Comments

@ilikourou
Copy link

Hello.

From what I understand, a search can be applied to an Eloquent Model.

What about searching a collection of models?

Instead of doing, for example, only this: Article::search('my post');
I would also need to do this: Article::where('category','news')->search('my post');

Is there any chance that we can see this in the near future?

@timgws
Copy link

timgws commented Jul 19, 2015

Not at the moment, not the way that you are suggesting.

Elastiquent does not yet have an Eloquent-like interface for building search queries, although, one is planed in the near future.

At the moment, you would have to do something like this:

<?php

$articles = Article::searchByQuery([
    'match' => [
        'contents' => 'my post',
        'category' => 'news'
    ]
]);

@ilikourou
Copy link
Author

Thanks.

I ended up doing it using searchByQuery, as you mentioned:

$results_articles = Article::searchByQuery([
    'filtered' => [
        'filter' => [
            'term' => [ 'article_cat_id' => Input::get('articles') ]
        ],
        'query' => [
            'match' => [
                '_all' => $query
            ],
        ],
    ],
]);

It would be nice, though, to see such functionality (Eloquent-like interface) in the near future.

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

2 participants