gpt4 book ai didi

couchdb - Cloudant 查询和 CouchDB 芒果 : How to set $regex flags?

转载 作者:行者123 更新时间:2023-12-02 20:36:58 32 4
gpt4 key购买 nike

是否可以使用 Cloudant Query/CouchDB 2.0 Find 设置 $regex 标志?

具体来说,我想要一个不区分大小写的搜索,全局也很有用。

在 JavaScript 中我会这样做:

db.find({
selector: {
_id: {$gt: null},
series: {$regex: /mario/i}
}
});

但我不知道如何将其编码为 Erlang 字符串。

最佳答案

来自 Cloudant 支持:

我了解到您希望在 Cloudant Query 中使用 $regex 运算符进行不区分大小写匹配。

作为示例,您可以使用此 Cloudant 查询选择器来获取“series”字段具有与字符串“mario”不区分大小写的匹配的字符串值的所有文档:

{
"selector": {
"_id": {
"$gt": null
},
"series": {
"$regex": "(?i)mario"
}
}
}

在名为 query.txt 的文件中使用该选择器,并为 $ACCOUNTNAME、$DATABASE、$USERNAME 和 $PASSWORD 设置适当的值,您可以运行此查询以获得正确的结果:

curl -X POST http://$ACCOUNTNAME.cloudant.com/$DATABASE/_find -H 
"Content-Type: application/json" -d @query.txt -u $USERNAME:$PASSWORD

Cloudant API 引用:https://docs.cloudant.com/cloudant_query.html#creating-selector-expressions Cloudant 查询选择器中的 $regex 运算符说道:

Most selector expressions work exactly as you would expect for the given operator. The matching algorithms used by the $regex operator are currently based on the Perl Compatible Regular Expression (PCRE) library. However, not all of the PCRE library is implemented, and some parts of the $regex operator go beyond what PCRE offers. For more information about what is implemented, see the Erlang Regular Expression information http://erlang.org/doc/man/re.html.

并且在它引用的 Erlang 正则表达式信息中 http://erlang.org/doc/man/re.html它说在选项列表中:compile(Regexp, Options) -> {ok, MP} | {错误,ErrSpec}

Caseless

  • Letters in the pattern match both upper and lower case letters.

  • It is equivalent to Perl's /i option, and it can be changed within a pattern by a (?i) option setting.

  • Uppercase and lowercase letters are defined as in the ISO-8859-1 character set.

我希望这会有所帮助。

关于couchdb - Cloudant 查询和 CouchDB 芒果 : How to set $regex flags?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37157723/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com