Fix: Fitter 'OR' Error
This commit is contained in:
+30
-18
@@ -24,34 +24,45 @@ impl FilterExt for Filter {
|
||||
if let Some(ids) = &self.ids {
|
||||
if !ids.is_empty() {
|
||||
sql.push(" AND (");
|
||||
let mut separated = sql.separated(" OR ");
|
||||
let mut first = true;
|
||||
for id_prefix in ids {
|
||||
if id_prefix.len() < 64 {
|
||||
// 如果是 ID 前缀,使用 LIKE
|
||||
separated
|
||||
.push("id LIKE ")
|
||||
.push_bind(format!("{}%", id_prefix));
|
||||
} else {
|
||||
// 否则进行精确匹配
|
||||
separated.push("id = ").push_bind(id_prefix);
|
||||
if !first {
|
||||
sql.push(" OR ");
|
||||
}
|
||||
if id_prefix.len() == 64 {
|
||||
sql.push("id = ");
|
||||
sql.push_bind(id_prefix);
|
||||
} else {
|
||||
sql.push("id LIKE ");
|
||||
sql.push_bind(format!("{}%", id_prefix));
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
separated.push_unseparated(")");
|
||||
sql.push(")");
|
||||
}
|
||||
}
|
||||
|
||||
// 作者过滤 (NIP-01 支持前缀匹配)
|
||||
if let Some(authors) = &self.authors {
|
||||
if !authors.is_empty() {
|
||||
sql.push(" AND pubkey IN (");
|
||||
let mut separated = sql.separated(",");
|
||||
sql.push(" AND (");
|
||||
let mut first = true;
|
||||
for author in authors {
|
||||
separated.push_bind(author);
|
||||
if !first {
|
||||
sql.push(" OR ");
|
||||
}
|
||||
if author.len() == 64 {
|
||||
sql.push("pubkey = ");
|
||||
sql.push_bind(author);
|
||||
} else {
|
||||
sql.push("pubkey LIKE ");
|
||||
sql.push_bind(format!("{}%", author));
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
separated.push_unseparated(")");
|
||||
sql.push(")");
|
||||
}
|
||||
}
|
||||
|
||||
// 类型过滤
|
||||
if let Some(kinds) = &self.kinds {
|
||||
if !kinds.is_empty() {
|
||||
@@ -66,12 +77,13 @@ impl FilterExt for Filter {
|
||||
|
||||
// 时间过滤 (since)
|
||||
if let Some(since) = self.since {
|
||||
sql.push(" AND created_at >= ").push_bind(since as i64);
|
||||
sql.push(" AND created_at >= ");
|
||||
sql.push_bind(since as i64);
|
||||
}
|
||||
|
||||
// 时间过滤 (until)
|
||||
if let Some(until) = self.until {
|
||||
sql.push(" AND created_at <= ").push_bind(until as i64);
|
||||
sql.push(" AND created_at <= ");
|
||||
sql.push_bind(until as i64);
|
||||
}
|
||||
|
||||
// 标签过滤 (NIP-12 Generic Tag Queries)
|
||||
|
||||
Reference in New Issue
Block a user