forked from lbdremy/solr-node-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateAddStream.js
More file actions
33 lines (28 loc) · 904 Bytes
/
Copy pathcreateAddStream.js
File metadata and controls
33 lines (28 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Create a stream to add documents into the database
*/
// Use `var solr = require('solr-client')` in your code
var solr = require('./../lib/solr');
var csv = require('csv-stream');
var fs = require('fs');
// Create a client
var client = solr.createClient();
// Switch on "auto commit", by default `client.autoCommit = false`
client.autoCommit = true;
// Save all the products in the csv file into the database
fs.createReadStream(__dirname + '/materials/products.csv')
.on('error',onerror)
.pipe(csv.createStream({
escapeChar : '"', // default is an empty string
enclosedChar : '"' // default is an empty string
}))
.on('error',onerror)
.pipe(client.createAddStream())
.on('error',onerror)
.on('end',function(){
console.log('all products are in the database now.');
});
// Error handler
function onerror(err){
console.error(err);
}