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

Add ability to perform custom query logic #2744

Open
johnryan opened this issue May 6, 2016 · 7 comments
Open

Add ability to perform custom query logic #2744

johnryan opened this issue May 6, 2016 · 7 comments

Comments

@johnryan
Copy link

johnryan commented May 6, 2016

Not sure if something like this will be possible based on how realm is designed but I have a model class that has fields: firstName and lastName and my model has a method getFullName().

I have search functionality that relies on the full name to search for results. Currently (it seems) that the only way to make this work would be to add a field fullName and keep that updated whenever the first or last name is updated.

It would be convenient if you could do something like this:

Realm realm = Realm.getDefaultInstance();
final String searchText = "John R";
realm.where(User.class).findAndFilterAsync(new Realm.Filter() {
    @Override
    public Boolean execute(User user) {

        String fullName = user.getFullName();
        if (fullName.indexOf(searchText) != -1){
            return true;
        }

        return false;

    }
});

If there's any other way of accomplishing something similar that would be great too.

Thanks!

@hay12396
Copy link

hay12396 commented May 8, 2016

For your spesific example, i think you should use Contains, it accepts (@NotNull fieldname, fieldvalue) or (@NotNull String fieldname, String fieldvalue,Case casing).
But +1 for the idea :)
👍

@johnryan
Copy link
Author

johnryan commented May 8, 2016

@hay12396 how does that solve the problem if the realm object doesn't have that field saved? In my example the full name is computed based the first and last names, so using contains wouldn't work.

@hay12396
Copy link

hay12396 commented May 8, 2016

As it is now, you will need to split the text to first&last name and use contains twice.

@johnryan
Copy link
Author

johnryan commented May 8, 2016

Ok, i still think this is a useful feature for searching a realm. For instance if the example was changed to some other type of non-text based search where the value being searched needs to be derived from fields it would be difficult to do.

@hay12396
Copy link

hay12396 commented May 8, 2016

@johnryan I think this is a great feature to have aswell 👍

@beeender
Copy link
Contributor

beeender commented May 9, 2016

Unfortunately it is not supported by our underlying storage engine (which is not open-sourced yet) right now :(
And the major pain point is since our underlying storage engine is written in C++, the query condition might need to be run as a callback from C++ to java which will be slow. (#2313 with the same problem)

But it would be a very useful feature!

@cmelchior
Copy link
Contributor

cmelchior commented May 9, 2016

Cocoa is tracking a similar feature here: realm/realm-swift#1265

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

5 participants