mehulkar
mehulkar

Reputation: 4974

How to ignore case in an NDB/DB query

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?

Upvotes: 4

Views: 2004

Answers (1)

dragonx
dragonx

Reputation: 15143

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.

Upvotes: 13

Related Questions