Reputation: 15269
I want to create a Js Search index in a Node app, then use this index in a client-side JavaScript app.
It's not clear to me from the README or the benchmark code how to do this.
I've tried this:
// docs is an array of objects, each with a name, title and description
var search = new jsSearch.Search('name');
search.addIndex('title');
search.addIndex('description');
search.addDocuments(docs);
...and this:
var search = new jsSearch.Search('name');
search.searchIndex = new jsSearch.TfIdfSearchIndex('name');
search.addIndex('title');
search.addIndex('description');
search.addDocuments(docs);
...but how can I access the index at that point?
Upvotes: 0
Views: 834
Reputation: 13487
use this index in a client-side JavaScript app
There's no way to pass the in-memory index from Node to a browser to access in the way you normally would (if you just built the index in the browser). js-search
doesn't [currently] support serialization. (Early testing suggested that it's not significantly faster to restore from a serialized format vs just recreating from scratch.)
You could expose the search from Node via an API but I don't think that's what you want or what you're looking for.
So I'd suggest a couple of possibilities:
js-search
(which it seems like you don't, based on your example) then consider using its faster sibling, js-worker-search
.lunr.js
which (I believe) does support serializing and restoring an index.Upvotes: 1