npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

search-index

1.0.6 • Public • Published

search-index

A network resilient, persistent full-text search library for the browser and Node.js

Gitter npm npm license Travis JavaScript Style Guide

Documentation, API and browser example

Quick start

Initialise search-index

Default method

search-index can be invoked with ES6 import or commonjs require using either lazy loading or a callback:

// Make a new index, or open an existing one with this name
import si from 'search-index'
 
// "lazy load"- db may not be immediately initialized
db = si({ name: 'mySearchIndex' })
 
// ... or callback to be sure you have it in time
si({ name: 'myDB' }, (err, db) => {
  // db is guaranteed to be open and available
})

Script tag method

In the /dist folder there is a file called search-index.<version>.js that can be used as a standalone in a <script> tag. The library is then available under a global variable called searchIndex:

<script type='text/javascript' src='./search-index.1.0.2.js'></script>
<script type='text/javascript'>
  searchIndex({ name: 'myDB' }, (err, db) => {
    // db is now available
  })
</script> 

Add documents to index

// db exists in a leveldb instance if run on a server
db.PUT([ /* my array of objects */ ]).then(doStuff)

Search the index

// search for terms without specifing any fields
db.SEARCH('SCOTLAND', 'GREEN').then(result)
 

More examples

See the tests for more examples.

Keywords

none

install

npm i search-index

Downloadsweekly downloads

353

version

1.0.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability