mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor: return ordered accounts by similarity relevance in searchEvents() function
This commit is contained in:
parent
be76197e3a
commit
69c2158131
1 changed files with 19 additions and 3 deletions
|
|
@ -91,19 +91,35 @@ async function searchEvents({ q, type, limit, account_id }: SearchQuery, signal:
|
||||||
filter.authors = [account_id];
|
filter.authors = [account_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pubkeys: string[] = [];
|
||||||
if (type === 'accounts') {
|
if (type === 'accounts') {
|
||||||
const kysely = await Storages.kysely();
|
const kysely = await Storages.kysely();
|
||||||
|
|
||||||
const pubkeys = await getPubkeysBySearch(kysely, { q, limit });
|
pubkeys.push(...(await getPubkeysBySearch(kysely, { q, limit })));
|
||||||
|
|
||||||
|
if (!filter?.authors) filter.authors = pubkeys;
|
||||||
|
else filter.authors.push(...pubkeys);
|
||||||
|
|
||||||
filter.authors = pubkeys;
|
|
||||||
filter.search = undefined;
|
filter.search = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = await Storages.search();
|
const store = await Storages.search();
|
||||||
|
|
||||||
return store.query([filter], { signal })
|
const events = await store.query([filter], { signal })
|
||||||
.then((events) => hydrateEvents({ events, store, signal }));
|
.then((events) => hydrateEvents({ events, store, signal }));
|
||||||
|
|
||||||
|
if (type !== 'accounts') return events;
|
||||||
|
|
||||||
|
const orderedEvents: NostrEvent[] = events.map((event, index) => {
|
||||||
|
const pubkey = pubkeys[index];
|
||||||
|
|
||||||
|
const orderedEvent = events.find((e) => e.pubkey === pubkey);
|
||||||
|
if (orderedEvent) return orderedEvent;
|
||||||
|
|
||||||
|
return event;
|
||||||
|
});
|
||||||
|
|
||||||
|
return orderedEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get event kinds to search from `type` query param. */
|
/** Get event kinds to search from `type` query param. */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue