Home > Backend Development > Golang > How to Perform Prefix String Searches in Google App Engine Datastore?

How to Perform Prefix String Searches in Google App Engine Datastore?

DDD
Release: 2024-10-24 06:45:02
Original
288 people have browsed it

How to Perform Prefix String Searches in Google App Engine Datastore?

Prefix String Search in Google App Engine Datastore

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:

  • A filter to select entities greater than or equal to the prefix.
  • A filter to select entities less than the next string in lexicographical order after the prefix.

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>
Copy after login

This query will return Places with names such as:

liam
lisotto
lizst
Copy after login

But it will exclude names like:

abc
ljoi
lj
qwerty
Copy after login

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!

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