Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to pass an array of options to full-text search. #606

Merged
merged 3 commits into from
Mar 22, 2022
Merged

Conversation

den1n
Copy link
Contributor

@den1n den1n commented Mar 18, 2022

Extended example from Scout docs.

use Laravel\Scout\Attributes\SearchUsingFullText;
use Laravel\Scout\Attributes\SearchUsingPrefix;
 
/**
 * Get the indexable data array for the model.
 *
 * @return array
 */
#[SearchUsingPrefix(['id', 'email'])]
#[SearchUsingFullText(['bio'])]
#[SearchUsingOptions(['mode' => 'websearch', 'language' => 'german'])]
public function toSearchableArray()
{
    return [
        'id' => $this->id,
        'name' => $this->name,
        'email' => $this->email,
        'bio' => $this->bio,
    ];
}

@driesvints
Copy link
Member

I'm also wondering how we can make this more dynamic. For example, I can imagine the language needing to be dynamic based on the user's preference? Maybe a dedicated method is better instead? @taylorotwell wdyt?

@taylorotwell
Copy link
Member

Could we just pass the options as a second argument to the SearchUsingFullText attribute? Mark as ready for review when you are ready for me to take a look again.

@taylorotwell taylorotwell marked this pull request as draft March 18, 2022 20:13
…ingFullText attribute.

Removed the SearchUsingOptions attribute.
@den1n
Copy link
Contributor Author

den1n commented Mar 21, 2022

Could we just pass the options as a second argument to the SearchUsingFullText attribute?

Done.

@den1n den1n marked this pull request as ready for review March 21, 2022 03:54
@taylorotwell taylorotwell merged commit dd84557 into laravel:9.x Mar 22, 2022
@phuclh
Copy link

phuclh commented Apr 5, 2022

I got this error after updating to this version
CleanShot 2022-04-04 at 23 56 59@2x

The element with key index 1 doesn't exist
CleanShot 2022-04-04 at 23 59 47@2x

This is how I defined the SearchUsingFullText attribute:

CleanShot 2022-04-05 at 00 00 20@2x

It works fine when I roll back to v9.4.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants