47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { indexSearchDocuments } from '@/lib/server/search';
|
|
|
|
function getArg(name: string) {
|
|
const prefix = `--${name}=`;
|
|
const entry = process.argv.find((value) => value.startsWith(prefix));
|
|
return entry ? entry.slice(prefix.length).trim() : null;
|
|
}
|
|
|
|
async function main() {
|
|
const source = (getArg('source') ?? 'all').toLowerCase();
|
|
const ticker = getArg('ticker')?.toUpperCase() ?? null;
|
|
const accessionNumber = getArg('accession') ?? null;
|
|
const userId = getArg('user') ?? 'system-backfill';
|
|
|
|
const sourceKinds: Array<'filing_document' | 'filing_brief' | 'research_note'> | null = source === 'all'
|
|
? ['filing_document', 'filing_brief', 'research_note'] as const
|
|
: source === 'documents'
|
|
? ['filing_document'] as const
|
|
: source === 'filings'
|
|
? ['filing_brief'] as const
|
|
: source === 'research'
|
|
? ['research_note'] as const
|
|
: null;
|
|
|
|
if (!sourceKinds) {
|
|
throw new Error('Unsupported --source value. Use all, documents, filings, or research.');
|
|
}
|
|
|
|
if (sourceKinds.includes('research_note') && !userId) {
|
|
throw new Error('--user is required when backfilling research notes.');
|
|
}
|
|
|
|
const result = await indexSearchDocuments({
|
|
userId,
|
|
ticker,
|
|
accessionNumber,
|
|
sourceKinds
|
|
});
|
|
|
|
console.log(JSON.stringify(result, null, 2));
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error instanceof Error ? error.message : error);
|
|
process.exitCode = 1;
|
|
});
|