adamfairholm / Elasticquent

Map Larvel Eloquent models to Elasticsearch types
MIT License
201 stars 38 forks source link

Search Collection, not only Model #36

Open ilikourou opened 9 years ago

ilikourou commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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.