lucaong / minisearch

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

Use different field as id #30

Closed sheerun closed 4 years ago

sheerun commented 4 years ago

In my case each record has only "name" and "url" fields. I'd like name to act as id as it's unique.

Is it possible to configure minisearch so it uses name field and doesn't complain that documents don't have this field?

lucaong commented 4 years ago

Hi @sheerun ! Yes, it’s possible, just pass the idField option:

const miniSearch = new MiniSearch({
  fields: ['name', 'url'],
  idField: 'name'
})

Of course, each document has to have a unique name in this case.

Hope this helps!

sheerun commented 4 years ago

whoops, somehow I missed this in docs, thank you!