Closed bmccorm2 closed 10 months ago
I can't get any results coming from my document index. Do you know what i am doing wrong?
import Flexsearch from "flexsearch"; const documents = [ { id: 1, name: 'person one', title: 'first place' }, { id: 2, name: 'person two', title: 'second place' }, { id: 3, name: 'person three', title: 'second place' }, ]; const Document = Flexsearch.Document ?? Flexsearch; const index = Document({ tokenize: 'forward', document: { id: 'id', index: ['name', 'title'], }, }); documents.forEach((e) => { index.add({ id: e.id, name: e.name, title: e.title }); }); export const search = (query: string) => { const results = index.search(query, ['name', 'title']); return results.map((e: number) => { return documents[e]; }); };
You aren't using a flat representation of the result, so this will break return documents[e];
return documents[e];
Read here about the result set: https://github.com/nextapps-de/flexsearch?tab=readme-ov-file#the-result-set
I can't get any results coming from my document index. Do you know what i am doing wrong?