Skip to content

Instantly share code, notes, and snippets.

@AnnamrajuSarvani
Created July 26, 2017 08:06
Show Gist options
  • Save AnnamrajuSarvani/bd0ac82bc946e97e989a7b91600642ca to your computer and use it in GitHub Desktop.
Save AnnamrajuSarvani/bd0ac82bc946e97e989a7b91600642ca to your computer and use it in GitHub Desktop.
exports.Search=function(){
var JSONStream = require('JSONStream');
var Readable = require('stream').Readable
var index;
function indexData(err, newIndex) {
if (!err) {
var result = [];
index = newIndex;
index.search({
query:[{
AND:{
"*" :["linseed, linpep"]
}
}]
})
.on('data', function(data) {
result.push({
"text": data.document
});
})
.on('end', function() {
index.close(function(err) {
console.log(result);
});
})
} else {
console.log(err)
}
}
var ops = {
indexPath: 'sample_index',
logLevel: 'error',
fieldOptions:{
topics:{
searchable: true
}
},
}
require('search-index')(ops, indexData)
}
exports.Search();
exports.createIndex=function(){
var ops = {
indexPath: 'sample_index',
logLevel: 'error',
fieldOptions:{
topics:{
searchable: true,
seperator:','
// nGramLength: {gte: 1, lte: 100}
}
},
// preserveCase: false,
// nGramLength: {gte: 1, lte: 100},
}
var index;
require('search-index')(ops, indexData)
function indexData(searchIndex){
index=searchIndex;
fs.createReadStream('stream.json')
.pipe(index.feed())
.on('finish',function(){
console.log('read done--->');
})
}
}
exports.createIndex();
{
"title": "NATIONAL AVERAGE PRICES FOR FARMER-OWNED RESERVE",
"body": "The U.S. Agriculture Department\nreported the farmer-owned reserve national five-day average\nprice through February 25 as follows (Dlrs/Bu-Sorghum Cwt) -\n Natl Loan Release Call\n Avge Rate-X Level Price Price\n Wheat 2.55 2.40 IV 4.65 --\n V 4.65 --\n VI 4.45 --\n Corn 1.35 1.92 IV 3.15 3.15\n V 3.25 --\n X - 1986 Rates.\n\n Natl Loan Release Call\n Avge Rate-X Level Price Price\n Oats 1.24 0.99 V 1.65 -- \n Barley n.a. 1.56 IV 2.55 2.55\n V 2.65 -- \n Sorghum 2.34 3.25-Y IV 5.36 5.36\n V 5.54 -- \n Reserves I, II and III have matured. Level IV reflects\ngrain entered after Oct 6, 1981 for feedgrain and after July\n23, 1981 for wheat. Level V wheat/barley after 5/14/82,\ncorn/sorghum after 7/1/82. Level VI covers wheat entered after\nJanuary 19, 1984. X-1986 rates. Y-dlrs per CWT (100 lbs).\nn.a.-not available.\n Reuter\n\u0003",
"date": "26-FEB-1987 15:10:44.60",
"topics": ["grain", "wheat", "corn", "barley", "oat", "sorghum"],
"places": ["usa"],
"id": "5"
} {
"title": "ARGENTINE 1986/87 GRAIN/OILSEED REGISTRATIONS",
"body": "Argentine grain board figures show\ncrop registrations of grains, oilseeds and their products to\nFebruary 11, in thousands of tonnes, showing those for futurE\nshipments month, 1986/87 total and 1985/86 total to February\n12, 1986, in brackets:\n Bread wheat prev 1,655.8, Feb 872.0, March 164.6, total\n2,692.4 (4,161.0).\n Maize Mar 48.0, total 48.0 (nil).\n Sorghum nil (nil)\n Oilseed export registrations were:\n Sunflowerseed total 15.0 (7.9)\n Soybean May 20.0, total 20.0 (nil)\n The board also detailed export registrations for\nsubproducts, as follows,\n SUBPRODUCTS\n Wheat prev 39.9, Feb 48.7, March 13.2, Apr 10.0, total\n111.8 (82.7) .\n Linseed prev 34.8, Feb 32.9, Mar 6.8, Apr 6.3, total 80.8\n(87.4).\n Soybean prev 100.9, Feb 45.1, MAr nil, Apr nil, May 20.0,\ntotal 166.1 (218.5).\n Sunflowerseed prev 48.6, Feb 61.5, Mar 25.1, Apr 14.5,\ntotal 149.8 (145.3).\n Vegetable oil registrations were : \n Sunoil prev 37.4, Feb 107.3, Mar 24.5, Apr 3.2, May nil,\nJun 10.0, total 182.4 (117.6). \n Linoil prev 15.9, Feb 23.6, Mar 20.4, Apr 2.0, total 61.8,\n(76.1). \n Soybean oil prev 3.7, Feb 21.1, Mar nil, Apr 2.0, May 9.0,\nJun 13.0, Jul 7.0, total 55.8 (33.7). REUTER\n\u0003",
"date": "26-FEB-1987 15:14:36.41",
"topics": ["veg-oil", "Linseed, Linpep", "lin-oil", "soy-oil", "sun-oil", "soybean", "oilseed", "corn", "sunseed", "grain", "sorghum", "wheat"],
"places": ["argentina"],
"id": "6"
}
@AnnamrajuSarvani
Copy link
Author

run "node index.js" and after creating index
run "node app.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment