Hyperledger Fabric 中不区分大小写的正则表达式

Case insensitive regex in Hyperledger Fabric

我正在尝试在用 node.js 编写的 hyperledger fabric 链代码中使用 $regex 进行不区分大小写的搜索。我的查询如下所示:

    const title = RegExp('Simple Title', 'i')

    const query = { selector: {  
          docType: DocType.someType, 
          title: { $regex: title }} 
     }

我还有许多其他查询,例如使用 erlang 语法:

    const title = 'Simple Title'

    const query = { selector: {
          docType: DocType.someType, 
          title: { $regex: `(?i)${title}` }} 
        }

...或提供选项道具:

    const title = 'Simple Title'

    const query = { selector: {
          docType: DocType.someType, 
          title: { $regex: title, $options: 'i' }} 
        }

但是,似乎没有任何效果。它要么是 return 所有记录,要么是一个错误。是我做错了什么还是 fabric 不支持这样的查询?

我知道织物文档建议不要使用正则表达式。

CouchDB documentation可以看出$regex运算符支持:

A regular expression pattern to match against the document field. Only matches when the field is a string value and matches the supplied regular expression. The matching algorithms are based on the Perl Compatible Regular Expression (PCRE) library. For more information about what is implemented, see the see the Erlang Regular Expression

Erlang Regular Expressionlink中,我们看到:

caseless
Letters in the pattern match both uppercase and lowercase letters. It is equivalent to Perl option /i and 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.

所以总而言之,Simple Title 的无大小写版本将是 (?i)Simple Title

如果您执行此操作并遇到错误,请使用您正在尝试的确切查询更新您的问题,并返回确切的错误。

我做了更多测试,发现这个问题只发生在使用 '@theledger/fabric-mock-stub' npm 包的测试中。即使测试失败,已部署的链代码仍按预期工作。我假设这不是 hyperledger 的问题,而是 '@theledger/fabric-mock-stub' 包中的某种错误。