npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

level-scout

v0.4.1

Published

Range search with a query plan

Downloads

8

Readme

level-scout

ltgt syntax + bytewise encoded indexes + stream filters + query planner = pretty awesome search capabilities. A search will use a range query on the most optimal index, even intersect indexes if possible, or do a full scan.

npm status Travis build status AppVeyor build status Dependency status

As an example, suppose you have a compound index on the x and y properties of your entities, resulting in index keys in the form of [x, y, entity key]. If you search for x: 20, y: { gte: 5 }, scout combines those predicates to a key range like gte: [20, 5], lte: [20, undefined]. But if you search for x: { gte: 5 }, y: 20, scout produces a ranged stream for x and filters that by y. Basically, scout can combine zero or more equality predicates with zero or one non-equality predicates, in the order of the index properties (so a compound "x, y" index is not the same as a "y, x" index). And maybe more in the future, if something like a "skip scan" is implemented.

This is experimental. API is unstable, documentation missing, terminology possibly garbled. Requires sublevel and leveldown (there are some unresolved issues with other backends like memdown).

Quick overview

var index  = require('level-scout/index')
    search = require('level-scout/search')
    select = require('level-scout/select')
    filter = require('level-scout/filter')

var db = ..

index(db, 'age')            // Single property index
index(db, 'owner.lastname') // Nested property
index(db, ['a', 'b', 'c'])  // Compound index

// Compound index with custom mapper. You
// can now search for `sum` even though it's
// not a property of the entity. Function
// is used for both indexing and filtering.
index(db, ['a', 'sum'], function(key, entity){
  return [entity.a, entity.a + entity.b]
})

// Insert some data
db.batch(..)

// Would select the "a, sum" index as access
// path, because those combined predicates are
// more selective than "age" - and "color" is not
// indexed.
var stream = search(db, {
  a: 45,
  sum: { gte: 45, lt: 60 },
  color: 'red',
  age: 300
})

// Get a subset of each entity
.pipe(select({the_age: 'age', color: true}))

// Filter some more (would yield no results)
.pipe(filter({ the_age: { lt: 100 } }))

Search with a callback:

search(db, { year: 1988 }, function(err, results, plan){
  // `plan` contains debug info about the selected
  // access path and filters
})

Setup

var level    = require(..)
  , sublevel = require('level-sublevel/bytewise')
  , index    = require('level-scout/index')
  , search   = require('level-scout/search')

var db = sublevel(level(), { valueEncoding: 'json' })

index(db, ..)
search(db, ..)

Or attach the methods to your database:

index.install(db)
search.install(db)

db.index('x')

db.put('key', {x: 10 }, function(){
  db.search({x: 10}, function(err, results){
    // ..
  })
})