Cloudant Query 和 CouchDB Mango:如何设置 $regex 标志?
Cloudant Query & CouchDB Mango: How to set $regex flags?
是否可以使用 Cloudant Query/CouchDB 2.0 Find 设置 $regex 标志?
具体来说,我想要一个不区分大小写的搜索,全局搜索也很有用。
在JavaScript我会做:
db.find({
selector: {
_id: {$gt: null},
series: {$regex: /mario/i}
}
});
但我不知道如何将其编码为 Erlang 字符串。
来自 Cloudant 支持:
我了解到您希望在 Cloudant 查询中使用 $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
https://docs.cloudant.com/cloudant_query.html#creating-selector-expressions 处的 Cloudant API 参考提到了 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.
并且在 http://erlang.org/doc/man/re.html 引用的 Erlang 正则表达式信息中说
在选项列表中: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.
希望对您有所帮助。
使用 Erlang 正则表达式进行 couchdb 字符串匹配
例子 :
{"selector":{"_id":{"$regex":"sre+"},"doctype":"user"},"fields":["_id"], "sort": [{"_id":"asc"}]}
是否可以使用 Cloudant Query/CouchDB 2.0 Find 设置 $regex 标志?
具体来说,我想要一个不区分大小写的搜索,全局搜索也很有用。
在JavaScript我会做:
db.find({
selector: {
_id: {$gt: null},
series: {$regex: /mario/i}
}
});
但我不知道如何将其编码为 Erlang 字符串。
来自 Cloudant 支持:
我了解到您希望在 Cloudant 查询中使用 $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
https://docs.cloudant.com/cloudant_query.html#creating-selector-expressions 处的 Cloudant API 参考提到了 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.
并且在 http://erlang.org/doc/man/re.html 引用的 Erlang 正则表达式信息中说 在选项列表中: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.
希望对您有所帮助。
使用 Erlang 正则表达式进行 couchdb 字符串匹配 例子 : {"selector":{"_id":{"$regex":"sre+"},"doctype":"user"},"fields":["_id"], "sort": [{"_id":"asc"}]}