Fergie's Inverted Index
This is my inverted index library. There are many like it, but this one is mine.
Throw JavaScript objects at the index and they will become retrievable by their properties using promises and map-reduce (see examples)
API
Command | Options | Accepts | Returns | Writes | Description |
---|
AND | - | properties | ids | no | Boolean AND. Return IDs of objects that have prop.A AND prop.b |
DELETE | - | ids | ids | yes | Remove objects from index |
DISTINCT | gte , lte | properties | properties | no | Return all properties in a range. |
EACH | - | properties | ids | no | For each property provided, get IDs of objects that contain it (use with DISTINCT, MAX and MIN) |
GET | gte , lte | properties | ids | no | Get the IDs of objects with a property in the given range |
MAX | limit | properties | properties | no | Get the highest property in this namespace |
MIN | limit | properties | properties | no | Get the lowest property in this namespace |
NOT | - | ids | ids | no | Get all IDs of objects in set A that are not in set B |
OBJECT | - | ids | objects | no | Get an object by its ID |
OR | - | properties | ids | no | Boolean OR. Return IDs of objects that have either prop.A OR prop.b |
PUT | - | objects | ids | yes | Add objects to index |
STORE | - | levelup | levelup | both | Get the underlying levelup store. |
Getting started
Initialise and populate an index
const fin = require('fergies-inverted-index')
fin({ name: 'idx' }).then(idx => {
idx.PUT([ ]).then(doStuff)
})
Query the index
idx.AND('land:SCOTLAND', 'colour:GREEN').then(result)
idx.AND('land:SCOTLAND', 'colour:GREEN').then(idx.OBJECT).then(result)
idx.OR('land:SCOTLAND', 'land:IRELAND').then(result)
idx.AND(
'land:SCOTLAND',
idx.OR('colour:GREEN', 'colour:BLUE')
).then(result)
idx.NOT(
idx.GET('land:SCOTLAND'),
idx.GET('colour:GREEN', 'colour:RED').
).then(result)
idx.MAX('population').then(result)
(See the tests for more examples.)
Compiling a client-side index that will run in the browser.
Why distribute indexes?