我是新手,我正在尝试理解如何去做一个不区分大小写的查询。
例如:
[:find (pull ?u [:user/email])
:where [?u :user/email "user1@example.net"]]返回:
{:user/email "user1@example.net"}我希望这个查询为一个指定为"USER1@example.net“的电子邮件返回相同的值,但Datomic正在对电子邮件进行区分大小写的比较,如下所示。
[:find (pull ?u [:user/email])
:where [?u :user/email "USER1@example.net"]]返回:
Nothing有什么建议是构造查询的最佳方式,以便它进行区分大小写的比较?
发布于 2015-06-17 03:50:44
为了执行不区分大小写的查询,我使用Clojure re-find函数构造了查询,以便对传递的电子邮件执行不区分大小写的正则表达式匹配,如下所示:
[:find (pull ?u [:user/email])
:where
[?u :user/email ?email]
[(re-find #"(?i)USER1@example.net" ?email)]
] db)现在返回:
{:user/email "user1@example.net"}发布于 2015-12-06 18:35:45
只需将查询字符串和数据库项转换为小写即可。
(defn case-insensitive-get-email
[email]
(d/q '[:find ?lowercaseEmail .
:in $ ?email
:where
[?e :user/email ?originalEmail]
[(.toLowerCase ^String ?originalEmail) ?lowercaseEmail]
[(= ?lowercaseEmail ?email)]]
db (.toLowerCase email)
)
)然后
(case-insensitive-get-email "USER1@example.net")
将会返回
"user1@example.net"https://stackoverflow.com/questions/30876463
复制相似问题