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

Implement a new sort method for FindOptions that accepts a Meta and a Sort args #2342

Closed
josephcaroe opened this issue Apr 13, 2023 · 0 comments
Milestone

Comments

@josephcaroe
Copy link

josephcaroe commented Apr 13, 2023

So my problem is related to a query that performs a text search. After the text search is done, I want to sort the results by the Meta score "textScore", so I use the sort method of the FindOptions class that accepts a Meta argument. But in native mongo, it's possible to also sort by another field, in case scores have the same values. The problem is you can't add another sort field if you use the sort method that accepts the Meta parameter.

I'd like to have a way to specify both sorting options: sort by textScore, and the sort by another field.

I can sort after the query is done, using java Comparators, but it's a pity something you can actually do in native mongo can't be replicated in morphia.

Mongo query that works, with sort options (one is the Meta score, the other is another field:

   db.phenotypes
      .find(
         { $text: {$search: "abnormal"} },
         { score:{$meta: "textScore"} })
      .sort(
         { score:{$meta:"textScore"} },
         { name:1 })
      .limit(10)
@evanchooly evanchooly added this to the 2.4.0 milestone Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants