Question:
Can Datastore search for entities whose names begin with a specific string?
Answer:
Yes, it is possible to perform prefix string searches in Datastore.
Details:
Datastore does not support a direct prefix search operator. However, you can achieve this functionality using a combination of inequality filters.
To list entities with names starting with a prefix, you need to specify two filters:
Example:
Suppose you want to search for Places with the "li" prefix. The corresponding query would be:
<code class="go">q = datastore.NewQuery("Places").Filter("Name >=", "li").Filter("Name <", "lj")</code>
This query will return Places with names such as:
liam lisotto lizst
But it will exclude names like:
abc ljoi lj qwerty
Note: Capital and lowercase letters are treated differently in lexicographical order. For instance, "List" is less than "li" in lexicographical order.
The above is the detailed content of How to Perform Prefix String Searches in Google App Engine Datastore?. For more information, please follow other related articles on the PHP Chinese website!