searching Strings

33 views
Skip to first unread message

medecau

unread,
May 9, 2008, 7:23:17 AM5/9/08
to Google App Engine
Hi,

i was attempting to solve the search users that match some given
criteria problem and found this solution:

given:

class userprofile(db.Model):
user=db.UserProperty()
nickname=db.StringProperty()

this:

q=self.request.get('q')
results=userprofile.all().filter('nickname >', q).filter('nickname <',
q+'z').fetch(50)

will return a list of userprofile objects that match 50 users witch
have a nickname that begins with the string passed in "q"

this works ok for me but i was wondering if there is a prettier or
more extesible way of doing it.
i am wondering if it is possible to do near regular expression
matching, haven't seen anything on documentation.

Barry Hunter

unread,
May 9, 2008, 11:44:55 AM5/9/08
to google-a...@googlegroups.com

No the Datastore doesnt have more flexible string matching, this sort
of prefix search is the closest approximation.

For more advanced searching you need to implement some sort of query
index (eg see the SearchableModel)


> >
>

--
Barry

- www.nearby.org.uk - www.geograph.org.uk -

Reply all
Reply to author
Forward
0 new messages