Elasticquent icon indicating copy to clipboard operation
Elasticquent copied to clipboard

Search Collection, not only Model

Open ilikourou opened this issue 9 years ago • 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?

ilikourou avatar Jul 18 '15 15:07 ilikourou

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

timgws avatar Jul 19 '15 10:07 timgws

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.

ilikourou avatar Jul 20 '15 05:07 ilikourou