modules/search/search.js
function search(db, origin, destination, departure, options, callback) {
  _log("====== STARTING SEARCH ======");
  _log("ORIGIN: " + origin.name);
  _log("DESTINATION: " + destination.name);
  _log("DATE/TIME: " + departure.toString());
  _log("OPTIONS: " + JSON.stringify(options, null, 2));


  // List of Results
  let RESULTS = [];


  // Get the initial Trip Search Dates
  _getTripSearchDates(db, departure, options.preDepartureHours*60, options.postDepartureHours*60, function(err, tripSearchDates) {
    _log("===== SEARCH TIME RANGE =====");
    for ( let i = 0; i < tripSearchDates.length; i++ ) {
      _log(JSON.stringify(tripSearchDates[i], null, 2));
    }

    // Database Query Error
    if ( err ) {
      return callback(err);
    }


    // Get the Initial Trips
    _getTripsFromStop(db, origin, destination, origin, tripSearchDates, [], function(err, direct, indirect) {
      _log("======= INITIAL TRIPS =======");
      _log("DIRECT TRIPS: " + direct.length);
      _log("INDIRECT TRIPS: " + indirect.length);

      // Database Query Error
      if ( err ) {
        return callback(err);
      }


      // Process Direct Trips
      for ( let i = 0; i < direct.length; i++ ) {
        let trip = direct[i];

        // Create a new Trip Search Result Segment
        let segment = new TripSearchResultSegment(trip, origin, destination);

        // Create new Trip Search Result
        let result = new TripSearchResult(segment);

        // Add Result to List
        RESULTS.push(result);
      }


      // Process Indirect Trips, if transfers are allowed
      if ( indirect.length > 0 && options.allowTransfers ) {
        _log("====== TRANSFER SEARCH ======");

        // Process the Indirect Trips
        _processTrips(db, options, origin, destination, origin, indirect, [], function(err, results) {
          _log("=== TRANSFER SEARCH RETURN ==");

          // Add results to final list
          RESULTS = RESULTS.concat(results);

          // Finish
          _finish();

        });

      }


      // No transfers required or disabled, finish
      else {
        _finish();
      }


    });


  });


  /**
   * Finished processing all trips, get Results ready to return
   * @private
   */
  function _finish() {
    _log("=============================");

    // Clean the Results
    RESULTS = _cleanResults(RESULTS);

    // Return the Results
    return callback(null, RESULTS);

  }


}
function search(db, origin, destination, departure, options, callback) {
  _log("====== STARTING SEARCH ======");
  _log("ORIGIN: " + origin.name);
  _log("DESTINATION: " + destination.name);
  _log("DATE/TIME: " + departure.toString());
  _log("OPTIONS: " + JSON.stringify(options, null, 2));


  // List of Results
  let RESULTS = [];


  // Get the initial Trip Search Dates
  _getTripSearchDates(db, departure, options.preDepartureHours*60, options.postDepartureHours*60, function(err, tripSearchDates) {
    _log("===== SEARCH TIME RANGE =====");
    for ( let i = 0; i < tripSearchDates.length; i++ ) {
      _log(JSON.stringify(tripSearchDates[i], null, 2));
    }

    // Database Query Error
    if ( err ) {
      return callback(err);
    }


    // Get the Initial Trips
    _getTripsFromStop(db, origin, destination, origin, tripSearchDates, [], function(err, direct, indirect) {
      _log("======= INITIAL TRIPS =======");
      _log("DIRECT TRIPS: " + direct.length);
      _log("INDIRECT TRIPS: " + indirect.length);

      // Database Query Error
      if ( err ) {
        return callback(err);
      }


      // Process Direct Trips
      for ( let i = 0; i < direct.length; i++ ) {
        let trip = direct[i];

        // Create a new Trip Search Result Segment
        let segment = new TripSearchResultSegment(trip, origin, destination);

        // Create new Trip Search Result
        let result = new TripSearchResult(segment);

        // Add Result to List
        RESULTS.push(result);
      }


      // Process Indirect Trips, if transfers are allowed
      if ( indirect.length > 0 && options.allowTransfers ) {
        _log("====== TRANSFER SEARCH ======");

        // Process the Indirect Trips
        _processTrips(db, options, origin, destination, origin, indirect, [], function(err, results) {
          _log("=== TRANSFER SEARCH RETURN ==");

          // Add results to final list
          RESULTS = RESULTS.concat(results);

          // Finish
          _finish();

        });

      }


      // No transfers required or disabled, finish
      else {
        _finish();
      }


    });


  });


  /**
   * Finished processing all trips, get Results ready to return
   * @private
   */
  function _finish() {
    _log("=============================");

    // Clean the Results
    RESULTS = _cleanResults(RESULTS);

    // Return the Results
    return callback(null, RESULTS);

  }


}
function search ( db , origin , destination , departure , options , callback ) { _log ( "====== STARTING SEARCH ======" ) ; _log ( "ORIGIN: " + origin . name ) ; _log ( "DESTINATION: " + destination . name ) ; _log ( "DATE/TIME: " + departure . toString ( ) ) ; _log ( "OPTIONS: " + JSON . stringify ( options , null , 2 ) ) ; // List of Results let RESULTS = [ ] ; // Get the initial Trip Search Dates _getTripSearchDates ( db , departure , options . preDepartureHours * 60 , options . postDepartureHours * 60 , function ( err , tripSearchDates ) { _log ( "===== SEARCH TIME RANGE =====" ) ; for ( let i = 0 ; i < tripSearchDates . length ; i ++ ) { _log ( JSON . stringify ( tripSearchDates [ i ] , null , 2 ) ) ; } // Database Query Error if ( err ) { return callback ( err ) ; } // Get the Initial Trips _getTripsFromStop ( db , origin , destination , origin , tripSearchDates , [ ] , function ( err , direct , indirect ) { _log ( "======= INITIAL TRIPS =======" ) ; _log ( "DIRECT TRIPS: " + direct . length ) ; _log ( "INDIRECT TRIPS: " + indirect . length ) ; // Database Query Error if ( err ) { return callback ( err ) ; } // Process Direct Trips for ( let i = 0 ; i < direct . length ; i ++ ) { let trip = direct [ i ] ; // Create a new Trip Search Result Segment let segment = new TripSearchResultSegment ( trip , origin , destination ) ; // Create new Trip Search Result let result = new TripSearchResult ( segment ) ; // Add Result to List RESULTS . push ( result ) ; } // Process Indirect Trips, if transfers are allowed if ( indirect . length > 0 && options . allowTransfers ) { _log ( "====== TRANSFER SEARCH ======" ) ; // Process the Indirect Trips _processTrips ( db , options , origin , destination , origin , indirect , [ ] , function ( err , results ) { _log ( "=== TRANSFER SEARCH RETURN ==" ) ; // Add results to final list RESULTS = RESULTS . concat ( results ) ; // Finish _finish ( ) ; } ) ; } // No transfers required or disabled, finish else { _finish ( ) ; } } ) ; } ) ; /**
   * Finished processing all trips, get Results ready to return
   * @private
   */ function _finish ( ) { _log ( "=============================" ) ; // Clean the Results RESULTS = _cleanResults ( RESULTS ) ; // Return the Results return callback ( null , RESULTS ) ; } }
Perform a Trip Search between the origin and destination Stops
with the provided parameters and options
@param {RightTrackDB} db The Right Track DB to query
@param {Stop} origin Origin Stop
@param {Stop} destination Destination Stop
@param {DateTime} departure Requested Departure Date/Time
@param {Object} options Trip Search Options
@param {function} callback Callback Function
@private
Perform a Trip Search between the origin and destination Stops with the provided parameters and options