I'm doing searches on a field that is mostly (but not strictly) unique, and I'm trying to find a way to do map/bucket-based search shortcuts for some searches that now happen with binary indexes. Is this something that would be interesting for controldb? Given this content of mock.json, I'm getting a an order of magnitude speedup for searches even with fairly large buckets.
var Benchmark = require('benchmark');
const controldb = require('controldb')
const items = require('./mock.json')
const map = new Map
for (const item of items) {
if (Math.random() > 0.05) item.firstname = '29686947-c999-456b-b15e-1710114088f2'
map.set(item.firstname, [ ...(map.get(item.firstname) || []), item ])
}
const DB = new controldb('better-bibtex', {})
const coll = DB.addCollection('x', {
indices: [ 'id', 'firstname' ],
unique: [ 'id' ],
})
coll.insert(items)
var suite = new Benchmark.Suite;
suite
.add('controldb', function() {
if (coll.find({ $and: [ { firstname: '29686947-c999-456b-b15e-1710114088f2' }, { id: 15000 } ] }).docs().length !== 1) throw new Error('failed')
})
.add('map', function() {
if (map.get('29686947-c999-456b-b15e-1710114088f2').filter(item => item.id === 15000).length !== 1) throw new Error('failed')
})
.on('cycle', function(event) { console.log(String(event.target)) })
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: false });