Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including search-index with all npm packages installed. Try it out:

var searchIndex = require("search-index")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

search-index v1.0.6

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

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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free