Reputation: 41
def post(self):
selector = self.request.get('search')
search = db.GqlQuery("SELECT * FROM Product WHERE productName = :selector", selector=selector)
products = search.fetch(10)
values = {
'products' : products
}
doRender(self, 'search.html', values)
above code is for search function from my Product category... Actually i tried to use the code "Select * From Product Where productName like %:selector%" for my search function, but i couldn't use this code.... Is there anyother GQL code which is substitution of 'SQL-LIKE query'??
Upvotes: 0
Views: 750
Reputation: 2968
There is no equivalent of SQL's LIKE in App Engine. You can however do something like
blurred_product_name = selector[:-2]
search = db.GqlQuery('SELECT * FROM Product where productName > ',
blurred_product_name)
So, if you have products with the name Product-1, Product-2, Product-3 and the search term is "Product", your blirred_product_name will be "Produc" which will return all the three possibilities in this case. Be careful with indexes however.
Alternatively you can very well use SearchableModel http://www.billkatz.com/2008/8/A-SearchableModel-for-App-Engine and get this done easily.
Upvotes: 1