I'm using java with app engine. SQL query:
select * from Person where name LIKE "a%"
How to write it on Google App Engine?
I'm using java with app engine. SQL query:
select * from Person where name LIKE "a%"
How to write it on Google App Engine?
Assuming you're querying against an entity in the App Engine datastore, in Java you'd rewrite LIKE "a%"
into something like
Query query = new Query("Person")
.addFilter("name", QueryFilterOperater.GREATER_THAN_OR_EQUAL, "a")
.addFilter("name", QueryFilterOperator.LESS_THAN, "b");
The rest is left as an exercise. See https://developers.google.com/appengine/docs/java/datastore/queries
There's no support for the LIKE operator in Appengine's datastore.
Two solutions :
To perform such query you have to use Google Cloud SQL.
If you're using Datastore, so it doesn't support fulltext search. You have to manually create all possible variations of name and use them to query entities. You can store them in special entity's multivalued field (it can be expensive) or use special Search API that perfectly fit this purpose (Search doesn't support substring matching so you have to use variations all the same).
It two words working with Search API is:
List item Create Person entity in Datastore with some name
Create corresponding Document in search Index named Persons
, with fields possible_names
and entity_id
(also you can use Document.doc_id to store entity's id). In possible_names
you store all useful variations of name divided by space.
Query Persons
index to find all documents where field possible_names
matches your search string.
Use field entity_id
form result's Documents to retrieve entity from Datastore by id.
Here is little example.