olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.96k stars 548 forks source link

Question: Given a search result ref, how to find the document added to the searchIndex? #251

Closed tashburn closed 7 years ago

tashburn commented 7 years ago

I add a bunch of documents to the index of the form {id:1, name:'Suzy'}, where id is the ref.

Then I search, and get [{"ref":1, "score":0.217593}]

Now, based on the ref of 1, which is the id, how do I get Suzy ?

olivernn commented 7 years ago

There are multiple issues asking this very question.

It really depends on how you store the documents that you've indexed in lunr. Lunr does not store the documents for you, it instead builds an index which supports full text search only.

Typically the documents are kept in memory, probably in a hash, and then the reference returned with the search results is used to retrieve the contents of the document from that hash. It really is dependent on your application though, you could be retrieving them from a server using xhr, or pulling them from a client side db like localStorage or IndexedDB, lunr doesn't care.

tashburn commented 7 years ago

I see. I had thought that lunr would store the docs internally. Thanks for explaining.