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

[9.x] Remove default order by model key desc in database engine when full-text index is used #590

Merged
merged 6 commits into from
Feb 17, 2022

Conversation

smknstd
Copy link
Contributor

@smknstd smknstd commented Feb 17, 2022

following #589 (comment)

When trying to search a model on a column with fulltext index and naturale langage query with mysql:

     /**
     * Get the indexable data array for the model.
     *
     * @return array
     */
    #[SearchUsingFullText(['bio'])]
    public function toSearchableArray()
    {
        return [
            'bio' => $this->bio,
        ];
    }

I do:

User::search('word1 word2')->get()

and query executed is:

select *
from `users`
where (match (`users`.`bio`) against (? in natural language mode)) order by `id` desc

Mysql automatically order by results by relevancy based on score and we can't benefit from that. I'd like to get my users ordered something like 1, 3, 2 but always get my users ordered 3, 2, 1. So we remove default "order by" as soon as a full-text where clause is actually used.

…h relevance ordering with natural language in mysql (fulltext index)
…h relevance ordering with natural language in mysql when there is at least one fulltext index
@taylorotwell taylorotwell merged commit 6e6a255 into laravel:9.x Feb 17, 2022
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.

2 participants