Home > Backend Development > Golang > Can Google App Engine Datastore Search for Entities with a Prefix in their Name?

Can Google App Engine Datastore Search for Entities with a Prefix in their Name?

DDD
Release: 2024-10-24 07:20:17
Original
294 people have browsed it

Can Google App Engine Datastore Search for Entities with a Prefix in their Name?

Searching for Strings Prefixed with a Prefix in Google App Engine Datastore

When dealing with large datasets, finding specific data can be a challenging task. In Google App Engine's datastore, one may wish to search for all entities whose names begin with a specific string prefix.

Question:

Can entities in datastore be searched by a name that starts with a prefix?

Answer:

Yes, searching for entities with a name prefix is possible in datastore.

To achieve this, you need to create a query with a combination of two inequality filters. Let's assume we want to find Places with the prefix "li."

GQL Query:

<code class="gql">SELECT * FROM Places WHERE Name > 'li' AND Name < 'lj'
Copy after login

Go Query:

<code class="go">q := datastore.NewQuery("Places").Filter("Name >", "li").Filter("Name <", "lj")</code>
Copy after login

This query will list Places whose names are lexicographically greater than or equal to "li" and lexicographically less than "lj." Hence, results will include names like "liam," "lisotto," and "lizst" but exclude "abc," "ljoi," and "qwerty."

Note: Small and capital letters hold distinct positions in lexicographical order. As such, "List" is considered less than "li," even though "list" is greater than "li."

The above is the detailed content of Can Google App Engine Datastore Search for Entities with a Prefix in their Name?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template