maize-tech/laravel-searchable

No results when many keys in scopeSearch function

theupriser opened this issue · 4 comments

Hello,

I've encountered a breaking problem when parsing more than 1000 id's trough the scopeSearch function in the HasSearch trait.
In the documentation of eloquent they are telling to use whereIntegerInRaw instead of whereIn in a query builder if there are many keys.

image

This is how I solved it. I've made a copy of the HasSearch trait and i'm using it like this now. I don't know if this is something that concerns you but it would be great if this package would be compatible with queries where many keys are used in the scopeSearch function.

With kind regards,

Rick

Hello @theupriser and thank you for reporting this!

We can easily update the package to add support to the whereIntegerInRaw method, but out of curiosity could you explain to us what's the issue you got with the actual method?
Were you having issues with the execution time?

Thank you!

Hi Riccardo,

The problem was that I was searching trough more than 1000+ records and also returning 1000+ records/models. WhereIn uses too much memory at this point and returns null. When you use whereIntegerInRaw it returns results like it should because this doesn’t use that much memory.

If you check the laravel documentation.
https://laravel.com/docs/9.x/queries#additional-where-clauses At the bottom of this chapter they explain this.

I hope this is enough information.

Hi @theupriser, I just made a minor release (tagged 3.1.0) with the enhancement you suggested!
Thank you!

Looks great! Thank you!