How to ignore case in an NDB/DB query

2019-05-14 23:34发布

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条回答
时光不老,我们不散
2楼-- · 2019-05-15 00:05

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.

查看更多
登录 后发表回答