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

Missing orderByDesc() function #892

Closed
jdavidbakr opened this issue Dec 5, 2024 · 0 comments · Fixed by #893
Closed

Missing orderByDesc() function #892

jdavidbakr opened this issue Dec 5, 2024 · 0 comments · Fixed by #893

Comments

@jdavidbakr
Copy link
Contributor

jdavidbakr commented Dec 5, 2024

Scout Version

10.11.8

Scout Driver

Database

Laravel Version

11.34

PHP Version

8.4.1

Database Driver & Version

MySQL 9.0.1 for macOS 14.6.1 on arm64 (Homebrew)

SDK Version

No response

Meilisearch CLI Version

No response

Description

For feature parity, the function orderByDesc should be included. In my case I'm adding a relevance column to by database query, and sorting it descending. I'll include the code snippet how I have to do it and what would be good for feature parity in the 'Steps to reproduce' section.

Steps To Reproduce

This is how it has to be written now:

        $articles = KnowledgeBaseArticle::search($request->search)
            ->query(function ($query) use ($request) {
                $query->selectRaw('
                    knowledge_base_articles.*,
                    MATCH(title) against(? IN NATURAL LANGUAGE MODE) * ? +
                    MATCH(content) against(? IN NATURAL LANGUAGE MODE) * ? +
                    MATCH(keywords) against(? IN NATURAL LANGUAGE MODE)* ? as relevance
                ', [
                    $request->search,
                    KnowledgeBaseArticle::$title_weight,
                    $request->search,
                    KnowledgeBaseArticle::$content_weight,
                    $request->search,
                    KnowledgeBaseArticle::$keyword_weight,
                ]);
            })
            ->orderBy('relevance', 'desc')
            ->paginate();

This is how I would like to write it to match other Eloquent usage:

        $articles = KnowledgeBaseArticle::search($request->search)
            ->query(function ($query) use ($request) {
                $query->selectRaw('
                    knowledge_base_articles.*,
                    MATCH(title) against(? IN NATURAL LANGUAGE MODE) * ? +
                    MATCH(content) against(? IN NATURAL LANGUAGE MODE) * ? +
                    MATCH(keywords) against(? IN NATURAL LANGUAGE MODE)* ? as relevance
                ', [
                    $request->search,
                    KnowledgeBaseArticle::$title_weight,
                    $request->search,
                    KnowledgeBaseArticle::$content_weight,
                    $request->search,
                    KnowledgeBaseArticle::$keyword_weight,
                ]);
            })
            ->orderByDesc('relevance')
            ->paginate();
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 a pull request may close this issue.

1 participant