getIdsBySearch: AND and OR logic

This commit is contained in:
Alex Gleason 2025-02-02 22:00:28 -06:00
parent 116b675664
commit 41e974c31c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 17 additions and 10 deletions

View file

@ -45,7 +45,7 @@
"@lambdalisue/async": "jsr:@lambdalisue/async@^2.1.1",
"@negrel/webpush": "jsr:@negrel/webpush@^0.3.0",
"@noble/secp256k1": "npm:@noble/secp256k1@^2.0.0",
"@nostrify/db": "jsr:@nostrify/db@^0.37.2",
"@nostrify/db": "jsr:@nostrify/db@^0.37.3",
"@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.38.0",
"@nostrify/policies": "jsr:@nostrify/policies@^0.36.1",
"@nostrify/types": "jsr:@nostrify/types@^0.36.0",

8
deno.lock generated
View file

@ -30,7 +30,7 @@
"jsr:@lambdalisue/async@^2.1.1": "2.1.1",
"jsr:@negrel/http-ece@0.6.0": "0.6.0",
"jsr:@negrel/webpush@0.3": "0.3.0",
"jsr:@nostrify/db@~0.37.2": "0.37.2",
"jsr:@nostrify/db@~0.37.3": "0.37.3",
"jsr:@nostrify/nostrify@0.31": "0.31.0",
"jsr:@nostrify/nostrify@0.32": "0.32.0",
"jsr:@nostrify/nostrify@0.36": "0.36.2",
@ -348,8 +348,8 @@
"jsr:@std/path@0.224.0"
]
},
"@nostrify/db@0.37.2": {
"integrity": "1dba9a4664bccd504de34dbdcb792377808bd8affb2712906beb687056602ce7",
"@nostrify/db@0.37.3": {
"integrity": "fe7cacd67bb817f10fb44587e832cfb042a3a0d32db29b24a487b7d006438623",
"dependencies": [
"jsr:@nostrify/nostrify@0.38",
"jsr:@nostrify/types@0.36",
@ -2348,7 +2348,7 @@
"jsr:@hono/hono@^4.4.6",
"jsr:@lambdalisue/async@^2.1.1",
"jsr:@negrel/webpush@0.3",
"jsr:@nostrify/db@~0.37.2",
"jsr:@nostrify/db@~0.37.3",
"jsr:@nostrify/nostrify@0.38",
"jsr:@nostrify/policies@~0.36.1",
"jsr:@nostrify/types@0.36",

View file

@ -53,7 +53,7 @@ export async function getIdsBySearch(
const tokens = NIP50.parseInput(q);
const ext = tokens.filter((token) => typeof token === 'object');
const ext: Record<string, string[]> = {};
const txt = tokens.filter((token) => typeof token === 'string').join(' ');
let query = kysely
@ -72,12 +72,19 @@ export async function getIdsBySearch(
}
}
if (ext.length) {
for (const token of tokens) {
if (typeof token === 'object') {
ext[token.key] ??= [];
ext[token.key].push(token.value);
}
}
for (const [key, values] of Object.entries(ext)) {
if (key === 'domain') continue;
query = query.where((eb) =>
eb.or(
ext
.filter((token) => token.key !== 'domain')
.map(({ key, value }) => eb('search_ext', '@>', { [key]: value })),
values.map((value) => eb('nostr_events.search_ext', '@>', { [key]: value })),
)
);
}