Last active
April 11, 2017 14:33
-
-
Save blahah/4005a93812cbcec9bfa385a31320132b to your computer and use it in GitHub Desktop.
stream never reads more than 20 results...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) | |
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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