/search-index

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

Primary LanguageJavaScriptMIT LicenseMIT

search-index

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

Gitter npm npm license Build Status JavaScript Style Guide

Documentation

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
PUT([ /* my array of objects */ ]).then(doStuff)

Search the index

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

More examples

See the tests for more examples.