@seneca/search-mini

0.1.6 • Public • Published

Seneca

Run standardisation tests on your Seneca.js plugin.

@seneca/search-mini

Voxgig This open source module is sponsored and supported by Voxgig.

A Seneca search plugin for local testing based on the Minisearch package

Install

$ npm install @seneca/search-mini

Quick Example

// for a live example - please, run the web example from examples/web locally after running npm install
const Seneca = require('seneca')
const SearchMini = require('@seneca/search-mini')

const seneca = Seneca({ log: 'test' })

seneca
  .test()
  .use(SearchMini, {
    search: {
      // fields to be used for each search to be performed
      fields: ['text', 'category'],
      // fields to be stored in the hits after the performed search
      // more on this: https://lucaong.github.io/minisearch
      storeFields: ['text', 'category']
    }

  })

let docs = [
  {
    id: 1,
    title: 'Moby Dick',
    text: 'Call me Ishmael. Some years ago...',
    category: 'fiction'
  },
  {
    id: 2,
    title: 'Zen and the Art of Motorcycle Maintenance',
    text: 'I can see by my watch...',
    category: 'fiction'
  },
  // ...
] 

for(const doc of docs) { // make sure to index all the documents
  // index a document
  await seneca.post('sys:search, cmd:add', { doc, }) // { doc: { id: 'id', ... } }
}


let out = await seneca.post('sys:search, cmd:search',
  // perform a search by query: { query: String, params: Object }
  {
    query: 'drama',
    params: {},
    // params: {prefix: true, fuzzy: 0.2,} // params usage example
    // more on: https://lucaong.github.io/minisearch/#search-options
})

// access the hits of the performed search for reuse
console.log('search hits: ', out.data.hits)

// Removing a doc

let doc = docs[0]
await seneca.post('sys:search, cmd:remove', { ...doc, })


// This is especially useful when you need to update the doc
// and make it present next time you apply 'sys:search, cmd:search'

let doc = docs[1]
doc.text = "new text ..."
await seneca.post('sys:search, cmd:remove', { ...doc, })
await seneca.post('sys:search, cmd:add', { doc, })

More Examples

Motivation

Support

Check out our sponsors and supporters, Voxgig, on their website here.

API

Contributing

The SenecaJS org encourages participation. If you feel you can help in any way, be it with bug reporting, documentation, examples, extra testing, or new features, feel free to create an issue, or better yet - submit a Pull Request. For more information on contribution, please see our Contributing Guide.

Background

Check out the SenecaJS roadmap here!

License

Licensed under MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i @seneca/search-mini

Weekly Downloads

59

Version

0.1.6

License

ISC

Unpacked Size

36.1 kB

Total Files

20

Last publish

Collaborators

  • lmscunha
  • alex01
  • lilsweetcaligula
  • stokesriona
  • rjrodger