Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fergies-inverted-index

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fergies-inverted-index

An inverted index that allows javascript objects to be easily serialised and retrieved using promises and map-reduce

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
220K
decreased by-28.87%
Maintainers
1
Weekly downloads
 
Created
Source

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

CommandOptionsDescription
INITnameOpens an index called the value of indexName and makes it available globally as indexName and global[indexName].
OPENnameOpens an index called the value of indexName and returns a Promise with the index.

Query API

CommandOptionsAcceptsReturnsWritesDescription
AGGREGATE-propertiesidsnoAggregation: 1st arg is aggregation, 2nd arg is filter
AND-propertiesidsnoBoolean AND. Return IDs of objects that have prop.A AND prop.b
BUCKET-propertiesidsno"Bag of IDs" for this property space
DELETE-idsidsyesRemove objects from index
DISTINCTgte, ltepropertiespropertiesnoReturn all properties in a range.
GETgte, ltepropertiesidsnoGet the IDs of objects with a property in the given range
MAXlimitpropertiespropertiesnoGet the highest property in this namespace
MINlimitpropertiespropertiesnoGet the lowest property in this namespace
NOT-idsidsnoGet all IDs of objects in set A that are not in set B
OBJECT-idsobjectsnoGet an object by its ID
OR-propertiesidsnoBoolean OR. Return IDs of objects that have either prop.A OR prop.b
PUT-objectsidsyesAdd objects to index
STORE-leveluplevelupbothGet the underlying levelup store.

Getting started

Initialise and populate an index


// Make a new index, or open an existing one with this name
// EITHER:
require('fergies-inverted-index').INIT({ name: 'idx' }) // index now available globally as "idx"
// idx not immediately available if promise resolution is ignored
// some time later...
idx.PUT([ /* my array of objects */ ]).then(doStuff)

// OR:
require('fergies-inverted-index').OPEN({ name: 'idx' }).then(idx => {
  idx.PUT([ /* my array of objects */ ]).then(doStuff) // no global, idx must be passed around
  // idx is always open and available
})

Query the index


// (given objects that contain: { land: <land>, colour: <colour>, population: <number> ... })

// get all object IDs where land=SCOTLAND and colour=GREEN
idx.AND('land:SCOTLAND', 'colour:GREEN').then(result)

// as above, but return whole objects
idx.AND('land:SCOTLAND', 'colour:GREEN').then(idx.OBJECT).then(result)

// Get all object IDs where land=SCOTLAND, and those where land=IRELAND
idx.OR('land:SCOTLAND', 'land:IRELAND').then(result)

// queries can be embedded within each other
idx.AND(
  'land:SCOTLAND',
  idx.OR('colour:GREEN', 'colour:BLUE')
).then(result)

// get all object IDs where land=SCOTLAND and colour is NOT GREEN
idx.NOT(
  idx.GET('land:SCOTLAND'),                 // everything in this set
  idx.GET('colour:GREEN', 'colour:RED').    // minus everything in this set
).then(result)

// Get max population
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?

FAQs

Package last updated on 14 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc