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)
Initialization API
Command | Options | Description |
---|
INIT | name | Opens an index called the value of indexName and makes it available globally as indexName and global[indexName] . |
OPEN | name | Opens an index called the value of indexName and returns a Promise with the index. |
Query API
Command | Options | Accepts | Returns | Writes | Description |
---|
AGGREGATE | - | properties | ids | no | Aggregation: 1st arg is aggregation, 2nd arg is filter |
AND | - | properties | ids | no | Boolean AND. Return IDs of objects that have prop.A AND prop.b |
BUCKET | - | properties | ids | no | "Bag of IDs" for this property space |
DELETE | - | ids | ids | yes | Remove objects from index |
DISTINCT | gte , lte | properties | properties | no | Return all properties in a range. |
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
require('fergies-inverted-index').INIT({ name: 'idx' })
idx.PUT([ ]).then(doStuff)
require('fergies-inverted-index').OPEN({ 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?