Realm是否支持Android上的模糊查询?

3

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


1
自2.3.0版本开始支持类似查询,请参见https://github.com/realm/realm-java/issues/3752 - EpicPandaForce
1个回答

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.

示例:

realm.where(Person.class).like("name", "*").findAll();
realm.where(Person.class).like("name", "?ohn*", Case.SENSITIVE).findAll();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接