views:

40

answers:

1

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:

"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

A: 

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"));
David Underhill
Cool, I guess the Java flavor provides that syntactic sugar then.
David Underhill
Ok I'm going to give this a shot in my app, I might post to the google dev group too to see if there's an official word/doc on support for this. It would be a disaster if it's just a labs feature and it gets deprecated in the future!
More info on this: http://googlecode.blogspot.com/2010/05/google-app-engine-basic-text-search.html