gpt4 book ai didi

java - 带有致命信号 11 (SIGSEGV) 错误的正则表达式查询

转载 作者:搜寻专家 更新时间:2023-11-01 09:21:54 24 4
gpt4 key购买 nike

我正在使用 couchbase 精简版 android-ee:2.1.2。我在本地 couchbase lite 数据库中存储了一些数据。现在,我正在尝试借助正则表达式查询从本地 couchbase lite 数据库查询数据,

Query query = QueryBuilder
.select(SelectResult.property("info"))
.from(DataSource.database(localDatabase))
.where(Expression.property("info").regex(Expression.string("^v" + "_" + "(4.6.2|1.7.7)" + "_" + "[123]" + "_" + "[12345678]")));

我的数据库看起来像,

v_1.7.7_1_3
v_1.7.5_1_3
v_4.7.1_2_8
v_4.7.1_1_8
v_4.7.2_2_8
v_4.7.2_2_8
v_4.7.1_1_8
v_4.7.1_2_8
v_4.7.5_1_8
v_4.9.3_1_1
...
...
...
and so on many entries

为了理解数据库结构,让我们以 v_1.7.7_1_3 为例,这里 v 可以定义为一个值,1.7.7是标记然后 1 是父类(这可以是类型 1,2 和 3)然后 3 是子类(这可以是类型 1,2,3 ,4,5,6,7 和 8)。

现在用户可以选择多个标签、父类和子类作为选择。然后我必须根据分别选择的参数从本地couchbase lite 查询数据。目前,正如我上面所说,我正在尝试借助正则表达式来查询数据,

例如,让用户选择标签4.6.21.7.7,那么父类是1,2和3,然后是子类1-8 .所以我的查询就像,

"^v" + "_" + "(4.6.2|1.7.7)" + "_" + "[123]" + "_" + "[12345678]"

我已经在 https://regex101.com 上尝试过这个查询,它运行良好,但不适用于 couchbase lite。

虽然应用程序只是因 fatal error 而崩溃,

A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 25543 (.mains.activity)

这里是一些日志,

V/Query: Query encoded as {"WHAT":[[".info"]],"WHERE":["regexp_like()",[".info"],"^v_(4.6.2|1.7.7)_[123]_[12345678]"]}
I/LiteCore [Query]: {Query#3}==> N8litecore11SQLiteQueryE 0x7f5a2d9098
I/LiteCore [Query]: {Query#3} Compiling JSON query: {"WHAT":[[".info"]],"WHERE":["regexp_like()",[".info"],"^v_(4.6.2|1.7.7)_[123]_[12345678]"]}
I/LiteCore [Query]: {Query#3} Compiled as SELECT fl_result(fl_value(body, 'info')) FROM kv_default WHERE (regexp_like(fl_value(body, 'info'), '^v_(4.6.2|1.7.7)_[123]_[12345678]')) AND (flags & 1) = 0
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 28308 (.mains.activity)

最佳答案

我认为,您的正则表达式查询似乎没问题。您可以使用以下单元测试用例进行验证。

@Test
public void testRegex() throws Exception {
MutableDocument doc1 = new MutableDocument("doc1");
doc1.setValue("version", "v_1.7.7_1_3");
db.save(doc1);

MutableDocument doc2 = new MutableDocument("doc2");
doc2.setValue("version", "v_1.7.5_1_3");
db.save(doc2);

MutableDocument doc3 = new MutableDocument("doc3");
doc3.setValue("version", "v_4.7.1_2_8");
db.save(doc3);

MutableDocument doc4 = new MutableDocument("doc4");
doc4.setValue("version", "v_4.7.1_1_8");
db.save(doc4);

MutableDocument doc5 = new MutableDocument("doc5");
doc5.setValue("version", "v_4.7.2_2_8");
db.save(doc5);

MutableDocument doc6 = new MutableDocument("doc6");
doc6.setValue("version", "v_4.6.2_2_8");
db.save(doc6);

Query q = QueryBuilder
.select(SelectResult.property("version"))
.from(DataSource.database(db))
.where(Expression.property("version").regex(Expression.string("^v" + "_" + "(4.6.2|1.7.7)" + "_" + "[123]" + "_" + "[12345678]")));

List<Result> results = q.execute().allResults();
// since the doc1 and doc6 passes the regex.
assertEquals(results.size(), 2);
}

关于java - 带有致命信号 11 (SIGSEGV) 错误的正则表达式查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54401694/

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