[Question] Why an id in the input dataset is required?
See original GitHub issueI may ask a dumb question but I didn’t see the answer in the documentation or existing issues.
If the documents passed to miniSearch.addAll()
is containing data that doesn’t have an id filed this error occurs.
Uncaught Error: MiniSearch: document does not have ID field "id"
Question 1: But why is the id filed required in the input? I understand we need a reference for the results, but there are several options other than requiring and id field in the input data:
- As the input in an array, use the array index as id for the results
- Use a unique field already existing on the data, eg. if the name field is unique so it can be used as a reference of the results
I already have a json dataset that is used for several usages, eg. like a pseudo API. I’m not super fan of adding an extra id field with arbitrary values for each item as it will make the file bigger & give me extra work when I could actually re-use the name field or array index as an id.
Question 2: Is it possible to make the id requirement optional & use another unique field as reference/index?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Hi @noraj , An ID field is needed to uniquely identify documents. The array index is not a good choice in general, because one can use
addAll()
several times with different arrays to index different lists of documents, or useadd()
to index a single document.That said, you can use any field that uniquely identifies a document as the ID field. By default, a field named
“id”
is assumed, but you can customize that with theidField
option. For example, if your documents are uniquely identified by a“productCode”
field, you can do:If the ID field is nested, or needs to be retrieved or calculated in some custom way, you can also specify your own
extractField
logic.In the API documentation you can read about all the options that you can pass to the constructor.
I hope this helps
@lucaong I added all static search engines (including MiniSearch) to Awesome Static Website Services. Among them all I choose MiniSearch for my website. It’s was the first one I tested but it worked so well, was so easy and configurable as I needed that I don’t even tested the others.
So if you want an awesome showcase I made the search engine the front of my website: https://inventory.raw.pm/ The code is here: https://inventory.raw.pm/js/search.js