function webSearch(engine, query, pageNumber, metrics) {
  return new Promise((resolve, reject) => {
    if (supportedEngines.indexOf(engine) === -1) {
      reject(`Search Engine '${engine}' not supported.`);
    }

    metrics = metrics || [];

    let searchEngine = eval(engine);
    
    searchEngine(query, pageNumber)
      .then(formattedResponse => {
        debug(`Getting metrics for formatted response: %O`, formattedResponse);
        getMetrics(formattedResponse, metrics)
          .then(values => {
            for (let response of values) {
              if (typeof formattedResponse.documents[response.index]['metrics'] === 'undefined') {
                formattedResponse.documents[response.index]['metrics'] = {};
              }
              formattedResponse.documents[response.index]['metrics'][response.name] = response.value;
            }
            resolve(formattedResponse);
          })
          .catch(err => reject(err));
      })
      .catch(err => reject(err));
    });
}
/**
 * Makes a request to the specified search engine which returns (callback),
 * the SERP with the calculated metrics.
 *
 * @async
 * @function webSearch
 * @param {string} engine SERP to use [google|bing|ecosia|elasticsearch]
 * @param {string} query Search query
 * @param {number} pageNumber Page number in the result pages
 * @param {array} metrics Array with the name of the metrics to calculate
 * @return {Promise<Object>} An object with the standardized result page (SERP)
 */
Makes a request to the specified search engine which returns (callback),
the SERP with the calculated metrics.


Makes a request to the specified search engine which returns ( callback ) the SERP with the calculated metrics .
function webSearch(engine, query, pageNumber, metrics) {
  return new Promise((resolve, reject) => {
    if (supportedEngines.indexOf(engine) === -1) {
      reject(`Search Engine '${engine}' not supported.`);
    }
    metrics = metrics || [];
    let searchEngine = eval(engine);
    searchEngine(query, pageNumber)
      .then(formattedResponse => {
        debug(`Getting metrics for formatted response: %O`, formattedResponse);
        getMetrics(formattedResponse, metrics)
          .then(values => {
            for (let response of values) {
              if (typeof formattedResponse.documents[response.index]['metrics'] === 'undefined') {
                formattedResponse.documents[response.index]['metrics'] = {};
              }
              formattedResponse.documents[response.index]['metrics'][response.name] = response.value;
            }
            resolve(formattedResponse);
          })
          .catch(err => reject(err));
      })
      .catch(err => reject(err));
    });
}
function webSearch ( engine , query , pageNumber , metrics ) { return new Promise ( ( resolve , reject ) => { if ( supportedEngines . indexOf ( engine ) === - 1 ) { reject ( ` ${ engine } ` ) ; } metrics = metrics || [ ] ; let searchEngine = eval ( engine ) ; searchEngine ( query , pageNumber ) . then ( formattedResponse => { debug ( ` ` , formattedResponse ) ; getMetrics ( formattedResponse , metrics ) . then ( values => { for ( let response of values ) { if ( typeof formattedResponse . documents [ response . index ] [ 'metrics' ] === 'undefined' ) { formattedResponse . documents [ response . index ] [ 'metrics' ] = { } ; } formattedResponse . documents [ response . index ] [ 'metrics' ] [ response . name ] = response . value ; } resolve ( formattedResponse ) ; } ) . catch ( err => reject ( err ) ) ; } ) . catch ( err => reject ( err ) ) ; } ) ; }
Makes a request to the specified search engine which returns (callback),
 the SERP with the calculated metrics.
Makes a request to the specified search engine which returns ( callback ) the SERP with the calculated metrics .