Using the DatastoreService how can I do queries for String containing some string similar to Java String:
- contains
- startsWith
- endsWith
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When querying against a String property, exact matches are the easiest, since that behavior works “out of the box”.
“startsWith” queries can be done fairly easily by turning
property startsWith: abcintoproperty >= 'abc' and property < 'abd', where you calculate the end of the range.“endsWith” can be done by storing a reversed copy of the String, and creating a query as above, but with the target reversed. I.e.,
property endsWith: 'abc'becomes `propertyReversed >= ‘cba’ and propertyReversed < ‘cbb’.“contains” is a large challenge. There are several approaches, and the right one for your situation depends on your situation. If the string is relatively short (e.g., a name of an address), you could store list of trailing substrings, matching against them with a range query as above.