How to ignore case in an NDB/DB query

久未见 提交于 2019-12-22 10:44:02

问题


This seems like a simple question, but I don't see anything in the class definition.

If I have the query

Video.query(Video.tags.IN(topics))

topics are coming in as lowercase unicode strings, but Video.tags are mostly capitalized. I can loop through topics and capitalize them before querying with them, but is there a way to ignore case altogether?


回答1:


It's not possible to ignore case in a query.

Typically if you know you want to do a case insensitive search, you may store a "denormalized" duplicate of the data in lower case. Whenever you want to query, you would lowercase the text before querying.

To reduce write costs, you probably only want to index the lowercased version, and you probably wouldn't need to index the actual case-sensitive data.



来源:https://stackoverflow.com/questions/15374185/how-to-ignore-case-in-an-ndb-db-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!