Skip to content

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