question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Why an id in the input dataset is required?

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lucaongcommented, Aug 25, 2020

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 use add() 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 the idField option. For example, if your documents are uniquely identified by a “productCode” field, you can do:

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

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

1reaction
norajcommented, Aug 29, 2020

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

In developing a machine learning model, can I use the ID as ...
Yes, when doing your data analysis and feature selection to train your model, see if it makes sense as an input. Maybe you'll...
Read more >
How to use "IDs" as an input variable to a ML model?
ID variables like phone number should not be included as predictors, because you are trying to train a model to understand general patterns....
Read more >
Question answering - Hugging Face Course
We will fine-tune a BERT model on the SQuAD dataset, which consists of ... First, we need to convert the text in the...
Read more >
1. (*) (45 marks) For input data use the first column | Chegg.com
Question: 1. (*) (45 marks) For input data use the first column in the dataset, ... (a) Let the last two digits of...
Read more >
HTMLElement.dataset - Web APIs | MDN
The dataset read-only property of the HTMLElement interface provides read/write access to custom data attributes (data-*) on elements.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found