lib/utils.js
/**
 * formatData - format search results into items we can process easier. This includes
 * 1) only keeping fields we show in the UI
 * 2) highlight matching words in text
 * 3) if showing 'passages', ignore all other results
 */
format search results into items we can process easier. This includes
1) only keeping fields we show in the UI
2) highlight matching words in text
3) if showing 'passages', ignore all other results
format search results into items we can process easier . This includes 1 ) only keeping fields we show in the UI 2 ) highlight matching words in text 3 ) if showing ' passages ' ignore all other results
function formatData(data) {
  var formattedData = {};
  var newPassages = [];
  var count = 0;
  data.forEach(function(dataItem) {
    if (dataItem.field === 'text') {
      count = count + 1;
      var newPassage = {
        id: count,
        text: dataItem.passage_text,
        score: dataItem.passage_score,
      };
      newPassages.push(newPassage);
    }
  });
  formattedData.results = newPassages;
  console.log('Formatting Data: size = ' + newPassages.length);
  return formattedData;
}
function formatData ( data ) { var formattedData = { } ; var newPassages = [ ] ; var count = 0 ; data . forEach ( function ( dataItem ) { if ( dataItem . field === 'text' ) { count = count + 1 ; var newPassage = { id : count , text : dataItem . passage_text , score : dataItem . passage_score , } ; newPassages . push ( newPassage ) ; } } ) ; formattedData . results = newPassages ; console . log ( 'Formatting Data: size = ' + newPassages . length ) ; return formattedData ; }
formatData - format search results into items we can process easier.
formatData - format search results into items we can process easier .
// only keep the data we show in the UI.