2
2
3
3
var watson = require ( 'watson-developer-cloud' ) ;
4
4
var async = require ( 'async' ) ;
5
+ var fs = require ( 'fs' ) ;
5
6
6
7
var retrieve = watson . retrieve_and_rank ( {
7
8
username : 'INSERT YOUR USERNAME FOR THE SERVICE HERE' ,
@@ -14,6 +15,7 @@ var clusterId = 'INSERT YOUR CLUSTER ID HERE';
14
15
var collectionName = 'example_collection' ;
15
16
var configName = 'example_config' ;
16
17
var configZipPath = __dirname + '/resources/example_solr_config.zip' ;
18
+ var jsonDocsFilePath = __dirname + '/resources/solr_docs.json' ;
17
19
18
20
var solrClient = retrieve . createSolrClient ( {
19
21
cluster_id : clusterId ,
@@ -74,7 +76,28 @@ async.series([
74
76
} ) ;
75
77
} ,
76
78
77
- function indexAndCommit ( done ) {
79
+ function indexAndCommitJsonFileDocs ( done ) {
80
+ console . log ( 'Indexing documents via JSON file...' ) ;
81
+ var jsonDocs = JSON . parse ( fs . readFileSync ( jsonDocsFilePath , 'utf8' ) ) ;
82
+ solrClient . add ( jsonDocs , function ( err ) {
83
+ if ( err ) {
84
+ console . log ( 'Error indexing document: ' + err ) ;
85
+ done ( ) ;
86
+ } else {
87
+ console . log ( 'Indexed JSON documents.' ) ;
88
+ solrClient . commit ( function ( err ) {
89
+ if ( err ) {
90
+ console . log ( 'Error committing change: ' + err ) ;
91
+ } else {
92
+ console . log ( 'Successfully commited changes.' ) ;
93
+ }
94
+ done ( ) ;
95
+ } ) ;
96
+ }
97
+ } ) ;
98
+ } ,
99
+
100
+ function indexAndCommitDocObject ( done ) {
78
101
console . log ( 'Indexing a document...' ) ;
79
102
var doc = { id : 1234 , title_t : 'Hello' , text_field_s : 'some text' } ;
80
103
solrClient . add ( doc , function ( err ) {
0 commit comments