@@ -21,7 +21,7 @@ Document Conversion Service and upload it to the Retrieve and Rank Service to ma
2121*/
2222
2323var watson = require ( 'watson-developer-cloud' ) ;
24- var async = require ( 'async' ) ;
24+ var async = require ( 'async' ) ;
2525var fs = require ( 'fs' ) ;
2626
2727/*
@@ -57,18 +57,25 @@ var solrClient = retrieve.createSolrClient({
5757
5858async . waterfall ( [
5959
60- function convert ( done ) {
60+ function convert ( done ) {
6161 // convert a single document
6262 document_conversion . convert ( {
6363 // (JSON) ANSWER_UNITS, NORMALIZED_HTML, or NORMALIZED_TEXT
6464 file : fs . createReadStream ( __dirname + inputDocument ) ,
6565 conversion_target : document_conversion . conversion_target . ANSWER_UNITS ,
66- config : { "html_to_html" :{ "specify_content_to_extract" :{ "enabled" :true , "xpaths" :[ "//h3" ] } } }
67- } , function ( err , response ) {
66+ config : {
67+ html_to_html : {
68+ specify_content_to_extract : {
69+ enabled : true ,
70+ xpaths : [ '//h3' ]
71+ }
72+ }
73+ }
74+ } , function ( err , response ) {
6875 if ( err ) {
6976 console . error ( err ) ;
7077 } else {
71- done ( null , response ) ;
78+ done ( null , response ) ;
7279 }
7380 } ) ;
7481 } ,
@@ -77,13 +84,13 @@ async.waterfall([
7784 console . log ( 'Indexing a document...' ) ;
7885 var doc = mapAnswerUnits2SolrDocs ( response ) ;
7986 solrClient . add ( doc , function ( err ) {
80- if ( err ) {
87+ if ( err ) {
8188 console . log ( 'Error indexing document: ' + err ) ;
8289 done ( ) ;
8390 } else {
8491 console . log ( 'Indexed a document.' ) ;
8592 solrClient . commit ( function ( err ) {
86- if ( err ) {
93+ if ( err ) {
8794 console . log ( 'Error committing change: ' + err ) ;
8895 } else {
8996 console . log ( 'Successfully committed changes.' ) ;
@@ -100,10 +107,12 @@ async.waterfall([
100107 // This query searches for the term 'psychological' in the content_text field.
101108 // For a wildcard query use:
102109 // query.q({ '*' : '*' });
103- query . q ( { 'content_text' : 'psychological' } ) ;
110+ query . q ( {
111+ 'content_text' : 'psychological'
112+ } ) ;
104113
105114 solrClient . search ( query , function ( err , searchResponse ) {
106- if ( err ) {
115+ if ( err ) {
107116 console . log ( 'Error searching for documents: ' + err ) ;
108117 } else {
109118 console . log ( 'Found ' + searchResponse . response . numFound + ' document(s).' ) ;
@@ -117,7 +126,7 @@ async.waterfall([
117126function mapAnswerUnits2SolrDocs ( data ) {
118127 var answerUnits = data . answer_units ;
119128 var solrDocList = [ ] ;
120- answerUnits . forEach ( function ( value ) {
129+ answerUnits . forEach ( function ( value ) {
121130 var solrDoc = convertAnswerUnit2SolrDoc ( value ) ;
122131 solrDocList . push ( solrDoc ) ;
123132 } ) ;
@@ -127,9 +136,15 @@ function mapAnswerUnits2SolrDocs(data) {
127136function convertAnswerUnit2SolrDoc ( au ) {
128137 var solrDoc ;
129138 var auContents = au . content ;
130- auContents . forEach ( function ( auContent ) {
131- if ( auContent . media_type === 'text/plain' ) {
132- solrDoc = { id : au . id , title : au . title , type : au . type , media_type : auContent . media_type , content_text : auContent . text } ;
139+ auContents . forEach ( function ( auContent ) {
140+ if ( auContent . media_type === 'text/plain' ) {
141+ solrDoc = {
142+ id : au . id ,
143+ title : au . title ,
144+ type : au . type ,
145+ media_type : auContent . media_type ,
146+ content_text : auContent . text
147+ } ;
133148 }
134149 } ) ;
135150 return solrDoc ;
0 commit comments