Skip to content

Instantly share code, notes, and snippets.

@blahah
Last active April 11, 2017 14:33
Show Gist options
  • Save blahah/4005a93812cbcec9bfa385a31320132b to your computer and use it in GitHub Desktop.
Save blahah/4005a93812cbcec9bfa385a31320132b to your computer and use it in GitHub Desktop.
stream never reads more than 20 results...
const resultbatcher = ds => {
let count = 0
const write = (list, cb) => {
count += list.length
bus.emit('results:receive', {
hits: list.map(r => {
r.source = ds.key
return r
})
})
cb()
}
const flush = cb => {
if (count === 0) {
bus.emit('results:none', ds.name)
} else {
bus.emit('results:count', { count: count, source: ds.name })
}
}
return bulk.obj(write, flush)
}
active.forEach(ds => datasource.fetch(ds.key, (err, source) => {
if (err) throw err
pump(source.db.search(query), resultbatcher(source), err => {
if (err) throw err
})
}))
var lookup = through.obj(function (data, enc, cb) {
if (typeof data === 'string') data = JSON.parse(data.toString('utf8'))
self.docstore.get(data.id, function (err, doc) {
if (err) return cb(err)
data.document = doc
cb(null, data)
})
})
return pumpify.obj(self.index.search(q, searchOpts), lookup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment