adamfairholm/Elasticquent

Search Collection, not only Model

Opened this issue · 2 comments

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?

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'
    ]
]);

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.