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
})
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>
// db exists in a leveldb instance if run on a server
PUT([ /* my array of objects */ ]).then(doStuff)
// search for terms without specifing any fields
SEARCH('SCOTLAND', 'GREEN').then(result)
See the tests for more examples.