teamtnt / laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch
MIT License
1.1k stars 144 forks source link

Issue with take() clause #158

Closed ADRDev closed 5 years ago

ADRDev commented 6 years ago

If I do: MyModel::search('term')->get()->take(10); I get a collection with 10 results as expected.

But if I do: MyModel::search('term')->take(10)->get(); I get an empty collection.

Digging into the issue it appears that the issue is with the indexing of the collection.

In the first example: MyModel::search('term')->get()->take(10);

I get 10 elements, but the indexing is not 0-9, it has (seemingly to me) random index numbers.

[ 45 => MyModel (object) ],
[ 72 => MyModel (object) ],
[ 124 => MyModel (object) ],
etc...

Instead of 0, 1, 2, etc..

So it looks like somehow take(10) is trying to get array index 0-9 which are not set and thus returning an empty collection.

Any thoughts on this?

nasirkhan commented 6 years ago

The following works for me as expected.

MyModel::search('term')->take(10)->get();

thoresuenert commented 6 years ago

@ADRDev without any research it feels like expected behaviour.

it can be a result of with relevance ordering by search engine. https://github.com/teamtnt/laravel-scout-tntsearch-driver/issues/168

But MyModel::search('term')->get() shouldnt return a collection of that structure.