feat(search): add @tower/search package with Meilisearch client and helpers
Implements Task 2 of Plan 4 (Archive & Search): provides createMeiliClient, configureIndex, indexMessage, and deleteMessage for use by the worker and API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { MeiliSearch } from 'meilisearch';
|
||||
|
||||
export { MeiliSearch } from 'meilisearch';
|
||||
|
||||
export interface MeiliDocument {
|
||||
id: string; // DB Message.id
|
||||
content: string;
|
||||
senderName: string; // empty string when null
|
||||
sourceGroupId: string;
|
||||
sourceGroupName: string;
|
||||
tags: string[];
|
||||
platform: string;
|
||||
approvedAt: number; // Unix ms — Meilisearch sorts numbers, not ISO strings
|
||||
}
|
||||
|
||||
export const MESSAGES_INDEX = 'tower-messages';
|
||||
|
||||
export function createMeiliClient(url: string, masterKey: string): MeiliSearch {
|
||||
return new MeiliSearch({ host: url, apiKey: masterKey });
|
||||
}
|
||||
|
||||
export async function configureIndex(client: MeiliSearch): Promise<void> {
|
||||
await client.index(MESSAGES_INDEX).updateSettings({
|
||||
searchableAttributes: ['content', 'senderName', 'sourceGroupName'],
|
||||
filterableAttributes: ['sourceGroupId', 'tags', 'platform'],
|
||||
sortableAttributes: ['approvedAt'],
|
||||
});
|
||||
}
|
||||
|
||||
export async function indexMessage(client: MeiliSearch, doc: MeiliDocument): Promise<void> {
|
||||
await client.index(MESSAGES_INDEX).addDocuments([doc]);
|
||||
}
|
||||
|
||||
export async function deleteMessage(client: MeiliSearch, id: string): Promise<void> {
|
||||
await client.index(MESSAGES_INDEX).deleteDocument(id);
|
||||
}
|
||||
Reference in New Issue
Block a user