I'm still interested if there is an official way to do this, but this is what I have come up with in the meantime.
In my query, I use the filter method.
private Query<InventoryItem> query = mBox
.query()
.greater(InventoryItem_.id, 0) //this will return all results
.filter(new QueryFilter<InventoryItem>()
{
@Override
public boolean keep(@NonNull InventoryItem entity)
{
if (like(entity.getDescription(), mSearchString + "%"))
{
return true;
}
return false;
}
})
.order(InventoryItem_.description)
.build();
And here is how I can perform the LIKE keyword via a regular expression.
private static boolean like(final String str, final String expr)
{
String safeString = (str == null) ? "" : str;
String regex = quoteMeta(expr);
regex = regex.replace("_", ".").replace("%", ".*?");
Pattern p = Pattern.compile(regex,
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
return p.matcher(safeString).matches();
}
private static String quoteMeta(String s)
{
if (s == null)
{
throw new IllegalArgumentException("String cannot be null");
}
int len = s.length();
if (len == 0)
{
return "";
}
StringBuilder sb = new StringBuilder(len * 2);
for (int i = 0; i < len; i++)
{
char c = s.charAt(i);
if ("[](){}.*+?$^|#\\".indexOf(c) != -1)
{
sb.append("\\");
}
sb.append(c);
}
return sb.toString();
}
Credit to How to implement a SQL like 'LIKE' operator in java?