Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addFields and removeFields methods #187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

lucaong
Copy link
Owner

@lucaong lucaong commented Nov 27, 2022

Resolves: #170

This methods add/remove fields to an existing document.

This is useful to patch some fields in an existing document without having to replace it.

Example:

addFields

const miniSearch = new MiniSearch({ fields: ['title', 'text', 'author'] })
   
miniSearch.add({ id: 1, title: 'Neuromancer' })
   
miniSearch.addFields(1, {
  text: 'The sky above the port was the color of television, tuned to a dead channel.',
  author: 'William Gibson'
})
   
// The above is equivalent to:
miniSearch.add({
  id: 1,
  title: 'Neuromancer',
  text: 'The sky above the port was the color of television, tuned to a dead channel.',
  author: 'William Gibson'
})

removeFields

const miniSearch = new MiniSearch({ fields: ['title', 'text', 'author'] })

miniSearch.add({
  id: 1,
  title: 'Neuromancer',
  text: 'The sky above the port was the color of television, tuned to a dead channel.',
  author: 'William Gibson'
})
   
miniSearch.removeFields(1, {
  text: 'The sky above the port was the color of television, tuned to a dead channel.',
  author: 'William Gibson'
})
   
// The above is equivalent to:
miniSearch.add({
  id: 1,
  title: 'Neuromancer'
})

This method adds fields to an existing document. The fields should not
exist already on the document, or an error is thrown.

This is useful to patch an existing document with some additional field,
without having to replace it.
Symmetric to addFields
@lucaong lucaong changed the title Add addFields method Add addFields and removeFields methods Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding single field (extending fieldlist) to document
1 participant