lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.67k stars 133 forks source link

Add getStoredFields method #210

Closed lucaong closed 1 year ago

lucaong commented 1 year ago

To retrieved the stored fields for a document given its ID:

const documents = [
  { id: 1, title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita' },
  { id: 2, title: 'I Promessi Sposi', text: 'Quel ramo del lago di Como' }
]
const ms = new MiniSearch({ fields: ['title', 'text'], storeFields: ['title', 'text'] })
ms.addAll(documents)

ms.getStoredFields(1)
// => { title: 'Divina Commedia', text: 'Nel mezzo del cammin di nostra vita' }

ms.getStoredFields(321)
// => undefined