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

How to get a sorted RealmResult based on the query string position in index fields string? #6501

Closed
razon30 opened this issue Apr 26, 2019 · 2 comments

Comments

@razon30
Copy link

razon30 commented Apr 26, 2019

When performing query, I want to get a RealmResult where the search field starts with query text will be added first, then the strings that contains the query string somewhere in the search field except start and end. And at last there will be objects whose search fields ends with search query.

For example, I have data = {"razon", "zebra", "fixar", "razib", "furan"} . Now, if I query with "ra", I want the realm result to return data in this order, result = {"razon", "razib" , "furan", "zebra"}

In the example, "razon" and "razib" starts with "ra", so they are in the front, then comes "furan" as ra is in somewhere in the string except start and end. And at the last "zebra" is added cause it ends with "ra".
How can I do it with a single query or in a efficient way?

@Zhuinden
Copy link
Contributor

Realm sort by string is lexicographical, so that would mean you'd need to do this transformation yourself on detached instances.

@cmelchior
Copy link
Contributor

Yes, this unfortunately not something you can express directly in our sorting logic.
Being able to do it is a duplicate of #2744

For now, you would need to use copyFromRealm and do custom sorting.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants