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!
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 :)
:+1:
@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.
As it is now, you will need to split the text to first&last name and use contains twice.
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.
@johnryan I think this is a great feature to have aswell :+1:
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!
Cocoa is tracking a similar feature here: https://github.com/realm/realm-cocoa/issues/1265
Most helpful comment
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!