duanfeng7756 2016-09-01 19:48
浏览 45
已采纳

在Google App Engine数据存储区中搜索以前缀开头的字符串

I want to search all entities whose name starts with a specific string, is this possible in Datastore?

I've tried this:

q = datastore.NewQuery("Places").Filter("Name > ", "a")

But it doesn't work.

If this is not possible, what alternative solution can you suggest to me? BigQuery? BigTable or other services on App Engine?

  • 写回答

1条回答 默认 最新

  • dpb_4431 2016-09-01 20:10
    关注

    This is something that is possible, but with a combination of 2 inequality filters.

    Let's say you want to list Places that have the "li" prefix. This can be described with a query that lists Places that are greater than (or equal to) "li" and less than a prefix that is the next string after "li" in lexicographical order: "lj".

    This is how the GQL looks like:

    SELECT * FROM Places WHERE Name > 'li' AND Name < 'lj'
    

    Coded in Go it looks like this:

    q = datastore.NewQuery("Places").Filter("Name >", "li").Filter("Name <", "lj")
    

    This will list Places where name is for example:

    liam
    lisotto
    lizst
    

    But will exclude names like:

    abc
    ljoi
    lj
    qwerty
    

    One thing to note: small and capital letters are different in lexicographical order, so for example "List" is less than "li" (even though "list" is greater than "li")!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题