laravel / scout

Laravel Scout provides a driver based solution to searching your Eloquent models.
https://laravel.com/docs/scout
MIT License
1.54k stars 327 forks source link

[10.x] Implement scopeSearch #804

Closed sjcobb2022 closed 7 months ago

sjcobb2022 commented 7 months ago

Implementation

Implements the changes proposed in #803.

This adds a scopeSearch to rely on laravel's query scopes. I think that this is a really powerful feature, as it allows really flexible queries.

For example:

// Query on Has/BelongsTo Relationships

// finds todos that belong to a user and searches through them.
User::first()->todos()->search('buy eggs'); 

// gets a user's managers and searches through them.
User::managers()->search('John'); 

// Allow more semantically "nice" queries.
User::where('id', '>' , '10')->search('John');

Sorry about all the annoying file changes, my linter is pretty aggressive. Can be removed if necessary.

driesvints commented 7 months ago

Can you please indeed undo all unrelated style changes? Thanks!

sjcobb2022 commented 7 months ago

Can you please indeed undo all unrelated style changes? Thanks!

Sure sorry about that

sjcobb2022 commented 7 months ago

@driesvints reverted changes!

sjcobb2022 commented 7 months ago

As a note: I have also tested this on a large repo that I have been working on. We use the database driver, and it works perfectly.

Everything works as expected and all my tests for that project also pass.

taylorotwell commented 7 months ago

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.