UNPKG

shijing

Version:
41 lines (30 loc) 910 B
var SearchIndex = require('search-index'); var stream = require('stream'); var shijingJSON = require('./json/shijing.json'); var rs = new stream.Readable({ objectMode: true }); rs.push(shijingJSON); rs.push(null); let index; var options = {}; //put the startup options you want here var q = {}; q.query = { AND: {'*': ['?']} // search for string '一' in all ('*') fields }; const indexData = function(err, newIndex) { if (!err) { index = newIndex; rs .pipe(index.defaultPipeline()) // vectorize .pipe(index.add()) // index .on('data', function(data) { // console.log(data); }) .on('end', function() { index.search(q) // <- si is a readable stream that emits documents sorted by relevance .on('data', function(doc) { console.log(doc); }); }); } }; SearchIndex(options, indexData);