mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
EventsDB: fix plaintext search queries
This commit is contained in:
parent
a7bca0bdff
commit
feec343d5a
2 changed files with 24 additions and 1 deletions
|
|
@ -221,3 +221,26 @@ Deno.test("throws a RelayError when querying an event with a large 'kind'", asyn
|
|||
'kind filter too far into the future',
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test('NPostgres.query with search', async (t) => {
|
||||
await using db = await createTestDB({ pure: true });
|
||||
const { store } = db;
|
||||
|
||||
const eventA = genEvent({ kind: 1, content: 'Fediverse is vegan' });
|
||||
const eventB = genEvent({ kind: 1, content: 'Im vegan btw' });
|
||||
|
||||
await store.event(eventA);
|
||||
await store.event(eventB);
|
||||
|
||||
await t.step('match single event', async () => {
|
||||
assertEquals(await store.query([{ search: 'Fediverse' }]), [eventA]);
|
||||
});
|
||||
|
||||
await t.step('match multiple events', async () => {
|
||||
assertEquals(await store.query([{ search: 'vegan' }]), [eventA, eventB]);
|
||||
});
|
||||
|
||||
await t.step("don't match nonsense queries", async () => {
|
||||
assertEquals(await store.query([{ search: "this shouldn't match" }]), []);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ class EventsDB extends NPostgres {
|
|||
|
||||
// Re-serialize the search string without the domain key. :facepalm:
|
||||
filter.search = tokens
|
||||
.filter((t) => typeof t === 'object' && t.key !== 'domain')
|
||||
.filter((t) => typeof t === 'string' || typeof t === 'object' && t.key !== 'domain')
|
||||
.map((t) => typeof t === 'object' ? `${t.key}:${t.value}` : t)
|
||||
.join(' ');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue