开发者

setFilter() with a string wildcard?

I see an example of doing a partial string search on the GAE google group (this thread):

String term1 = "cow";
String term2 = "horse";

Query q;
q.setFilter("name.matches('" + term1 + "%')");

so this works like:

开发者_StackOverflow社区

"Find all objects of the class where property 'name' starts with term1"

so that would match stuff like:

cowfoo
cowgrok
cowetc

right? I could then replace term1 with term2, and find all instances that begin with 'horse'. Is there a doc that explains this anymore? I just want to check this is how it really works before I make a decision on how to store some strings for my data model,

Thanks


I can't find the docs which present the prefix matching syntax you presented, but your logic is sound. And it looks like the syntax is supported based on the google group message you cited.

For the Python runtime, I would perform a prefix match by using an inequality filter. You can also do this on the Java runtime like this (and this is probably how the % syntax is implemented):

// prefix is some string object
q.setFilter("my_string_field >= :1 && my_string_field < :2");
q.execute(prefix, (prefix + "\ufffd"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜