Realm是否在Android上支持模糊查询

xxc*_*qzm 3 database android realm realm-mobile-platform

我的团队决定将领域用作数据库,但是我有一个问题要问,领域是否支持像SQLite这样的模糊查询,使用关键字“ like”或“%”。有时我们需要使用模糊查询

Epi*_*rce 5

从2.3.0开始支持LIKE查询。

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

Condition that the value of field matches with the specified substring, with wildcards:
    '*' matches [0, n] unicode chars
    '?' matches a single unicode char.

Parameters:
    fieldName - the field to compare.
    value - the wildcard string.
    casing - how to handle casing. Setting this to Case.INSENSITIVE only works for Latin-1 characters.
Run Code Online (Sandbox Code Playgroud)

例子:

realm.where(Person.class).like("name", "*").findAll();
realm.where(Person.class).like("name", "?ohn*", Case.SENSITIVE).findAll();
Run Code Online (Sandbox Code Playgroud)