{"id":17398423,"url":"https://github.com/vweevers/level-scout","last_synced_at":"2025-04-30T05:22:24.362Z","repository":{"id":31864621,"uuid":"35432568","full_name":"vweevers/level-scout","owner":"vweevers","description":"Range search with a query plan","archived":false,"fork":false,"pushed_at":"2015-05-29T23:56:37.000Z","size":177,"stargazers_count":14,"open_issues_count":5,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-21T13:39:26.241Z","etag":null,"topics":["level","nodejs","proof-of-concept","unmaintained-dont-use"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vweevers.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-11T15:30:24.000Z","updated_at":"2023-12-10T14:47:04.000Z","dependencies_parsed_at":"2022-08-17T15:41:09.774Z","dependency_job_id":null,"html_url":"https://github.com/vweevers/level-scout","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Flevel-scout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Flevel-scout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Flevel-scout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Flevel-scout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vweevers","download_url":"https://codeload.github.com/vweevers/level-scout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251645988,"owners_count":21620848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["level","nodejs","proof-of-concept","unmaintained-dont-use"],"created_at":"2024-10-16T14:56:12.793Z","updated_at":"2025-04-30T05:22:24.339Z","avatar_url":"https://github.com/vweevers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# level-scout\n\n**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.**\n\n[![npm status](http://img.shields.io/npm/v/level-scout.svg?style=flat-square)](https://www.npmjs.org/package/level-scout) [![Travis build status](https://img.shields.io/travis/vweevers/level-scout.svg?style=flat-square\u0026label=travis)](http://travis-ci.org/vweevers/level-scout) [![AppVeyor build status](https://img.shields.io/appveyor/ci/vweevers/level-scout.svg?style=flat-square\u0026label=appveyor)](https://ci.appveyor.com/project/vweevers/level-scout) [![Dependency status](https://img.shields.io/david/vweevers/level-scout.svg?style=flat-square)](https://david-dm.org/vweevers/level-scout)\n\nAs 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.\n\nNote: the API and dependencies are unstable, documentation is missing, terminology possibly garbled. \u003cstrike\u003eRequires sublevel and leveldown (there are some unresolved issues with other backends like memdown).\u003c/strike\u003e **Requires `leveldown \u003e= 1.0.0` or `level/memdown#v1.0.2`, and JSON value encoding. Incompatible with `level-sublevel`.**\n\n## Quick overview\n\n```js\nvar index  = require('level-scout/index')\n    search = require('level-scout/search')\n    select = require('level-scout/select')\n    filter = require('level-scout/filter')\n\nvar db = ..\n\nindex(db, 'age')            // Single property index\nindex(db, 'owner.lastname') // Nested property\nindex(db, ['a', 'b', 'c'])  // Compound index\n\n// Compound index with custom mapper. You\n// can now search for `sum` even though it's\n// not a property of the entity. Function\n// is used for both indexing and filtering.\nindex(db, ['a', 'sum'], function(key, entity){\n  return [entity.a, entity.a + entity.b]\n})\n\n// Insert some data\ndb.batch(..)\n\n// Would select the \"a, sum\" index as access\n// path, because those combined predicates are\n// more selective than \"age\" - and \"color\" is not\n// indexed.\nvar stream = search(db, {\n  a: 45,\n  sum: { gte: 45, lt: 60 },\n  color: 'red',\n  age: 300\n})\n\n// Get a subset of each entity\n.pipe(select({the_age: 'age', color: true}))\n\n// Filter some more (would yield no results)\n.pipe(filter({ the_age: { lt: 100 } }))\n```\n\nSearch with a callback:\n\n```js\nsearch(db, { year: 1988 }, function(err, results, plan){\n  // `plan` contains debug info about the selected\n  // access path and filters\n})\n```\n\n## Setup\n\n```js\nvar levelup  = require('levelup')\n  , index    = require('level-scout/index')\n  , search   = require('level-scout/search')\n\nvar db = levelup('./db', { valueEncoding: 'json' })\n\nindex(db, ..)\nsearch(db, ..)\n```\n\nOr attach the methods to your database:\n\n```js\nindex.install(db)\nsearch.install(db)\n\ndb.index('x')\n\ndb.put('key', {x: 10 }, function(){\n  db.search({x: 10}, function(err, results){\n    // ..\n  })\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Flevel-scout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvweevers%2Flevel-scout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Flevel-scout/lists"}