I have an entity called lastName with value "Benjamin". Is there a way in objectify that if the user put "Ben" or "jam" or "Benja". I still be able to find this entity using query.filter(). I must use the query as there are other search criteria iam checking.
I saw something in "Obgaektify" called "starts with" operator. but it isnot working. Any suggestions would be appreciated. Thanks
There's no "LIKE" type queries for sub-string, however a case sensitive "starts with" could be simulated by taking advantage of the >
and <
operators on indexes.
// The start string
String searchStr = "Ben";
// emulate a "starts with" query
Query q = new Query("MyEntity")
q.addFilter("name", Query.FilterOperator.GREATER_THAN_OR_EQUAL, searchStr);
q.addFilter("name", Query.FilterOperator.LESS_THAN, searchStr + "\ufffd");
The query will 'search' the name
property for items that begining with "Ben", and are less than "Ben\ufffd"
, where \ufffd
is the highest possible unicode character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With