search: search use FTS to search for statuses

This commit is contained in:
Alex Gleason 2023-08-30 12:16:04 -05:00
parent 5e9a3dd8d1
commit df14ff66bc
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { AppController } from '@/app.ts';
import * as eventsDB from '@/db/events.ts';
import { lookupAccount } from '@/utils.ts';
import { toAccount } from '@/transformers/nostr-to-mastoapi.ts';
import { toAccount, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
const searchController: AppController = async (c) => {
const q = c.req.query('q');
@ -13,9 +14,12 @@ const searchController: AppController = async (c) => {
// TODO: Support searching statuses and hashtags.
const event = await lookupAccount(decodeURIComponent(q));
const events = await eventsDB.getFilters([{ kinds: [1], search: q }]);
const statuses = await Promise.all(events.map((event) => toStatus(event, c.get('pubkey'))));
return c.json({
accounts: event ? [await toAccount(event)] : [],
statuses: [],
statuses: statuses.filter(Boolean),
hashtags: [],
});
};