使用不区分大小写的条件查询 DynamoDB [英] Query DynamoDB with case-insensitive condition

查看:26
本文介绍了使用不区分大小写的条件查询 DynamoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将组织名称存储在 AWS 上的 DynamoDB 表中,并希望保留这些企业名称的官方大写,例如TNT"和FedEx".

We're storing organization names in a DynamoDB table on AWS, and would like to maintain official capitalization in those business names, for example in "TNT" and "FedEx".

我们的用例是应用程序的用户可以按名称搜索组织,但我们希望对他们的查询进行不区分大小写的解释.因此,对FedEx"、Fedex"或fedex"的查询都应该在表中返回正确的项目.

Our use case is that users of the application can search for organizations by name, but we'd like that their queries are interpreted case-insensitively. So, queries for "FedEx", "Fedex" or "fedex" should all return the correct item in the table.

其他数据库有方法执行忽略大小写的查询(例如通过 PostgreSQL 中的 ILIKE 关键字),通过正则表达式表达查询,或通过在条件中应用函数(例如 LOWER() 函数).

Other databases have ways to perform queries ignoring case (for example by the ILIKE key word in PostgreSQL), by expressing queries via regular expressions, or by applying functions in the condition (for example the LOWER() function).

如何在 DynamoDB 中做到这一点?有关 Amazon DynamoDB 查询的文档 没有提供答案.

How can this be done in DynamoDB? The documentation on Amazon DynamoDB's Query does not provide an answer.

(最好的解决方法似乎是将名称存储两次:一次使用官方大写,一次在另一个字段中,名称转换为小写.然后应该在后一个字段上进行搜索,使用查询搜索词也转换为小写.是的,我知道它会为表格增加冗余.这是一种变通方法,而不是最佳解决方案.)

(The best work-around seems to be storing the name twice: once with the official capitalization in effect, and once in another field with the name converted to lowercase. Searching should then be done on the latter field, with the query search term also converted to lowercase. Yes, I know it adds redundancy to the table. It's a work-around, not an optimal solution.)

推荐答案

是的,没错,当你添加新的项目/行时,还要添加一个新的字段searchName,即小写(甚至更多,可能只有字母/数字/spaces) 您的姓名字段.然后按该 searchName 字段搜索

yes, exactly, when you add the new item/row, add also a new field searchName, that is the lowercase (even more, maybe only letters/numbers/spaces) of the your name field. and then search by that searchName field

这篇关于使用不区分大小写的条件查询 DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆