-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize lunr using a promise rather than a function? #497
Comments
Hi
BTW this is not an issue IMMO. just wrap into a Promise the function createLunrIndex(documents,fieldNames) {
return new Promise( (resolve,reject) => {
const idx = lunr(function() {
//
// load documents
// set fields
// ...
})
resolve(idx)
});
}
const idx = await createLunrIndex(documents,fieldNames, ...)
Do you want to add documents dynamically after the index creation? So I fair you have to recreated the index when you have new documents to add. Maybe that's a change request, not an issue. |
async function createIndex(): Promise<lunr.Index>{
const builder = new lunr.Builder();
builder.pipeline.add(
lunr.trimmer,
lunr.stopWordFilter,
lunr.stemmer
)
builder.searchPipeline.add(
lunr.stemmer
)
builder.ref('id');
builder.field('keywords');
await addObjectsToIndex();
return builder.build();
}
async function addObjectsToIndex():Promise<void>{
// do async stuff here
} |
Hi,
Is there a way to pass in a promise to initialize lunr instead of a function?
I want to do a non-blocking stream read to load data for lunr to index, a promise would allow me to keep things async. Any suggestions?
Thanks
The text was updated successfully, but these errors were encountered: