Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard search on Appengine in python

I'm just starting with Python on Google App Engine building a contact database. What is the best way to implement wildcard search?

For example can I do query('name=', %ewman%)?

like image 662
Peter Newman Avatar asked Sep 10 '09 00:09

Peter Newman


2 Answers

Unfortunately, Google app engine can't do partial text matches

From the docs:

Tip: Query filters do not have an explicit way to match just part of a string value, but you can fake a prefix match using inequality filters:

db.GqlQuery("SELECT * FROM MyModel WHERE prop >= :1 AND prop < :2", "abc", u"abc" + u"\ufffd")

This matches every MyModel entity with a string property prop that begins with the characters abc. The unicode string u"\ufffd" represents the largest possible Unicode character. When the property values are sorted in an index, the values that fall in this range are all of the values that begin with the given prefix.

like image 192
seth Avatar answered Oct 18 '22 18:10

seth


App Engine can't do 'like' queries, because it can't do them efficiently. Nor can your SQL database, though: A 'foo LIKE "%bar%"' query can only be executed by doing a sequential scan over the entire table.

What you need is an inverted index. Basic fulltext search is available in App Engine with SearchableModel. Bill Katz has written an enhanced version here, and there's a commercial solution for App Engine (with a free version) available here.

like image 3
Nick Johnson Avatar answered Oct 18 '22 18:10

Nick Johnson