Realm.io - How to use wildcard% LIKE% for request

I am trying to do:

mRealm .where(Contact.class) .equalTo(Contact.NAME, text, Case.INSENSITIVE) .findAllSortedAsync(Contact.NAME, Sort.ASCENDING); 

Result: The expected result is not fulfilled.

 mRealm .where(Contact.class) .contains(Contact.NAME, text, Case.INSENSITIVE) .findAllSortedAsync(Contact.NAME, Sort.ASCENDING); 

Result: The expected result is not fulfilled.

Expected Result:

 mRealm .where(Contact.class) .like(Contact.NAME, text, Case.INSENSITIVE) .findAllSortedAsync(Contact.NAME, Sort.ASCENDING); 
+5
source share
2 answers

NEW RESPONSE:

Realm 2.3.0 +:

 public RealmQuery<E> like(String fieldName, String value, Case casing) 

The condition that the field value matches the specified substring, with wildcards:

  • '*' matches [0, n] unicode characters

  • '?' matches one unicode char.

Options:

  • fieldName - field to compare.

  • value is a wildcard.

  • casing - how to handle the case. Setting this parameter to Case.INSENSITIVE only works for Latin-1 characters.

Returns: request object.

Throws: IllegalArgumentException - if one or more arguments do not match the type of the class or field.


OLD RESPONSE:

 mRealm .where(Contact.class) .contains(Contact.NAME, text, Case.INSENSITIVE) .findAllSortedAsync(Contact.NAME, Sort.ASCENDING); 

This should work, but you will get a callback from the added RealmChangeListener when the actual asynchronous request completes.

A RealmRecyclerViewAdapter does this automatically from https://github.com/realm/realm-android-adapters .

+3
source
 mRealm .where(Contact.class) .like(Contact.NAME, text, Case.INSENSITIVE) .findAllSortedAsync(Contact.NAME, Sort.ASCENDING); 
+3
source

Source: https://habr.com/ru/post/1259328/


All Articles