blob: 2fb3adcd051cac9a65a32c61249299114e998ab9 (
plain)
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
|
#!/usr/bin/env node
const elasticlunr = require( './elasticlunr.min' );
const fs = require( 'fs' );
const JSONStream = require( 'JSONStream' );
const es = require( 'event-stream' );
console.log( 'Creating ElasticLunr index..' );
const index = new elasticlunr.Index( );
index.addField( 'title' );
index.addField( 'content' );
index.setRef( 'uri' );
index.saveDocument( true );
var stream = fs.createReadStream( './posts.json' );
stream.pipe( JSONStream.parse( '*') )
.pipe( es.mapSync( function( data ) {
index.addDoc( data );
return data;
} )
.on( 'end', function( ) {
fs.writeFile( './posts.index', JSON.stringify( index ),
function( err ) {
if( err ) throw err;
console.log( 'Finished creating index..' );
}
);
} )
)
|