Hello, I want to use Realm in combination with a ListView using RealmBaseAdapter. In my case I also need a SearchView to filter the list. The following is a examle how I want to filter:
RealmResults
.beginGroup()
.contains("name", searchString)
.endGroup()
.findAll();
How can I perform case insensitive queries? Like this:
select * from user where lower(name) = 'fred';
Hi @petersnoopy
Thank you for trying out Realm.
In your particular case you can use:
public RealmQuery<E> contains(String fieldName, String value, boolean caseSensitive)
so it looks like this:
RealmResults r = realm.where(User.class)
.beginGroup()
.contains("name", searchString, true)
.endGroup()
.findAll();
However, you also seem to have stumbled upon a little overlapse from our side. The Query API also has two other methods .beginWith() and .endsWith() that does support case insensitive search but our equalTo() and notEqualTo() does not have this parameter currently. We will add those for the next release.
Are the beginGroup() and endGroup() leftovers from this originally being part of a larger query? Since there are no and or ors involved in the query there is really no need for grouping, so you could just do it like this instead:
RealmResults r = realm.where(User.class).contains("name", searchString, true).findAll();
Excellent, thanks! For case insensitive i have to set the false value.
It's now working properly ( Case.INSENSITVE) - when I have John it will not find it by typing lower case j when using contains or beginsWith
RealmResults
.contains("Country", strTextCountry, Case.INSENSITIVE)
//.contains("Country", strTextCountry,false)
//.containsIgnoreCase("Country", strTextCountry)
.findAll();
Most helpful comment
Hi @petersnoopy
Thank you for trying out Realm.
In your particular case you can use:
so it looks like this:
However, you also seem to have stumbled upon a little overlapse from our side. The Query API also has two other methods .beginWith() and .endsWith() that does support case insensitive search but our equalTo() and notEqualTo() does not have this parameter currently. We will add those for the next release.