OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
OPENTREP::OPENTREP_Service Class Reference

Interface for the OPENTREP Services. More...

#include <opentrep/OPENTREP_Service.hpp>

Public Types

typedef std::pair< const TravelDBFilePath_T, const SQLDBConnectionString_TDBFilePathPair_T
 
typedef std::pair< const PORFilePath_T, const DBFilePathPair_TFilePathSet_T
 

Public Member Functions

NbOfDBEntries_T getIndexSize ()
 
NbOfMatches_T drawRandomLocations (const NbOfMatches_T &iNbOfDraws, LocationList_T &)
 
NbOfMatches_T interpretTravelRequest (const std::string &iTravelQuery, LocationList_T &, WordList_T &)
 
FilePathSet_T getFilePaths () const
 
const DeploymentNumber_TgetDeploymentNumber () const
 
bool checkXapianDBOnFileSystem (const TravelDBFilePath_T &) const
 
bool createSQLDBUser ()
 
void setSQLDBConnectString (const SQLDBConnectionString_T &)
 
void createSQLDBTables ()
 
void createSQLDBIndexes ()
 
OPENTREP::DeploymentNumber_T toggleDeploymentNumber ()
 
OPENTREP::shouldIndexNonIATAPOR_T toggleShouldIncludeAllPORFlag ()
 
OPENTREP::shouldIndexPORInXapian_T toggleShouldIndexPORInXapianFlag ()
 
OPENTREP::shouldAddPORInSQLDB_T toggleShouldAddPORInSQLDBFlag ()
 
NbOfDBEntries_T insertIntoDBAndXapian ()
 
NbOfDBEntries_T getNbOfPORFromDB ()
 
NbOfMatches_T listByIataCode (const IATACode_T &, LocationList_T &)
 
NbOfMatches_T listByIcaoCode (const ICAOCode_T &, LocationList_T &)
 
NbOfMatches_T listByFaaCode (const FAACode_T &, LocationList_T &)
 
NbOfMatches_T listByUNLOCode (const UNLOCode_T &, LocationList_T &)
 
NbOfMatches_T listByUICCode (const UICCode_T &, LocationList_T &)
 
NbOfMatches_T listByGeonameID (const GeonamesID_T &, LocationList_T &)
 
 OPENTREP_Service (std::ostream &ioLogStream, const TravelDBFilePath_T &, const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &)
 
 OPENTREP_Service (std::ostream &ioLogStream, const PORFilePath_T &, const TravelDBFilePath_T &, const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &, const shouldIndexNonIATAPOR_T &, const shouldIndexPORInXapian_T &, const shouldAddPORInSQLDB_T &)
 
 ~OPENTREP_Service ()
 

Detailed Description

Interface for the OPENTREP Services.

Definition at line 25 of file OPENTREP_Service.hpp.

Member Typedef Documentation

◆ DBFilePathPair_T

Get the file-paths of the Xapian database/index and of the OPTD-maintained POR (points of reference).

Returns
std::pair<const PORFilePath_T, File-path of the file of POR (points of reference). std::pair<const TravelDBFilePath_T, File-path of the Xapian database. const SQLDBConnectionString_T> > Connection string of the SQL DB.

Definition at line 74 of file OPENTREP_Service.hpp.

◆ FilePathSet_T

Definition at line 75 of file OPENTREP_Service.hpp.

Constructor & Destructor Documentation

◆ OPENTREP_Service() [1/2]

OPENTREP::OPENTREP_Service::OPENTREP_Service ( std::ostream & ioLogStream,
const TravelDBFilePath_T & iTravelDBFilePath,
const DBType & iSQLDBType,
const SQLDBConnectionString_T & iSQLDBConnStr,
const DeploymentNumber_T & iDeploymentNumber )

Constructor for search-/query-related services.

Parameters
std::ostream&Output log stream (for instance, std::cout).
constTravelDBFilePath_T& File-path of the Xapian index/database.
constDBType& SQL database type (can be no database at all).
constSQLDBConnectionString_T& SQL DB connection string.
constDeploymentNumber_T& Deployment number/version.

Definition at line 48 of file OPENTREP_Service.cpp.

◆ OPENTREP_Service() [2/2]

OPENTREP::OPENTREP_Service::OPENTREP_Service ( std::ostream & ioLogStream,
const PORFilePath_T & iPORFilepath,
const TravelDBFilePath_T & iTravelDBFilePath,
const DBType & iSQLDBType,
const SQLDBConnectionString_T & iSQLDBConnStr,
const DeploymentNumber_T & iDeploymentNumber,
const shouldIndexNonIATAPOR_T & iShouldIndexNonIATAPOR,
const shouldIndexPORInXapian_T & iShouldIndexPORInXapian,
const shouldAddPORInSQLDB_T & iShouldAddPORInSQLDB )

Constructor for indexing-related services.

Parameters
std::ostream&Output log stream (for instance, std::cout).
constPORFilePath_T& File-path of the file of POR (points of reference).
constTravelDBFilePath_T& File-path of the Xapian index/database.
constDBType& SQL database type (can be no database at all).
constSQLDBConnectionString_T& SQL DB connection string.
constDeploymentNumber_T& Deployment number/version.
constshouldIndexNonIATAPOR_T& Whether to include non-IATA POR.
constshouldIndexPORInXapian_T& Whether to index POR in Xapian.
constshouldAddPORInSQLDB_T& Whether to add POR in SQL database.

Definition at line 32 of file OPENTREP_Service.cpp.

◆ ~OPENTREP_Service()

OPENTREP::OPENTREP_Service::~OPENTREP_Service ( )

Destructor.

Definition at line 70 of file OPENTREP_Service.cpp.

Member Function Documentation

◆ getIndexSize()

NbOfDBEntries_T OPENTREP::OPENTREP_Service::getIndexSize ( )

Get the number of documents within the Xapian database (index).

Returns
NbOfDBEntries_T Number of documents within the Xapian database.

Definition at line 210 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::OPENTREP_ServiceContext::getTravelDBFilePath(), OPENTREP_LOG_DEBUG, and OPENTREP::BasChronometer::start().

Referenced by main().

◆ drawRandomLocations()

NbOfMatches_T OPENTREP::OPENTREP_Service::drawRandomLocations ( const NbOfMatches_T & iNbOfDraws,
LocationList_T & ioLocationList )

Return a given number of locations, all randomly draw from the Xapian database (index).

Parameters
LocationList_T&List of (geographical) locations randomly picked up from the Xapian database.
Returns
NbOfMatches_T Number of documents actually retrieved from the Xapian database/index.

Definition at line 238 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::OPENTREP_ServiceContext::getTravelDBFilePath(), OPENTREP_LOG_DEBUG, and OPENTREP::BasChronometer::start().

◆ interpretTravelRequest()

NbOfMatches_T OPENTREP::OPENTREP_Service::interpretTravelRequest ( const std::string & iTravelQuery,
LocationList_T & ioLocationList,
WordList_T & ioWordList )

Match the given string, thanks to a full-text search on the underlying Xapian index (named "database").

Parameters
conststd::string& (Travel-related) query string (e.g., "sna francicso rio de janero lso angles reykyavki nce iev mow").
LocationList_T&List of (geographical) locations, if any, matching the given query string.
WordList_T&List of non-matched words of the query string.
Returns
NbOfMatches_T Number of matches.

Definition at line 960 of file OPENTREP_Service.cpp.

References checkXapianDBOnFileSystem(), OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::OPENTREP_ServiceContext::getTransliterator(), OPENTREP::OPENTREP_ServiceContext::getTravelDBFilePath(), OPENTREP_LOG_DEBUG, OPENTREP_LOG_ERROR, and OPENTREP::BasChronometer::start().

Referenced by parseQuery().

◆ getFilePaths()

◆ getDeploymentNumber()

const DeploymentNumber_T & OPENTREP::OPENTREP_Service::getDeploymentNumber ( ) const

Get the deployment number.

Returns
DeploymentNumber_T& The current deployment number

Definition at line 160 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::getDeploymentNumber().

◆ checkXapianDBOnFileSystem()

bool OPENTREP::OPENTREP_Service::checkXapianDBOnFileSystem ( const TravelDBFilePath_T & iTravelDBFilePath) const

Check that the directory hosting the Xapian database/index exists and is accessible.

Returns
bool Whether the directory of the Xapian database/index exists and is accessible

Definition at line 202 of file OPENTREP_Service.cpp.

References OPENTREP::FileManager::checkXapianDBOnFileSystem().

Referenced by interpretTravelRequest(), and main().

◆ createSQLDBUser()

bool OPENTREP::OPENTREP_Service::createSQLDBUser ( )

Create the SQL database user ('trep' on MySQL) and database ('trep_trep' on MySQL). That method has no effect on other database types (e.g., nosql, sqlite).

Returns
bool Whether or not the creation of the SQL database user and DB was successful.

Definition at line 270 of file OPENTREP_Service.cpp.

References OPENTREP::DBManager::createSQLDBUser(), OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::OPENTREP_ServiceContext::getDeploymentNumber(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBType::NODB, OPENTREP_LOG_DEBUG, and OPENTREP::BasChronometer::start().

Referenced by main().

◆ setSQLDBConnectString()

void OPENTREP::OPENTREP_Service::setSQLDBConnectString ( const SQLDBConnectionString_T & iSQLDBConnectionString)

Update the connection string.

  • Standard trep user: db=trep_trep user=trep password=trep
  • Administrator user: db=mysql user=root password=admin_user_passwd
Parameters
constSQLDBConnectionString_T& Connection string.

Definition at line 321 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP_LOG_DEBUG, and OPENTREP::OPENTREP_ServiceContext::setSQLDBConnectionString().

Referenced by main().

◆ createSQLDBTables()

void OPENTREP::OPENTREP_Service::createSQLDBTables ( )

◆ createSQLDBIndexes()

◆ toggleDeploymentNumber()

◆ toggleShouldIncludeAllPORFlag()

OPENTREP::shouldIndexNonIATAPOR_T OPENTREP::OPENTREP_Service::toggleShouldIncludeAllPORFlag ( )

◆ toggleShouldIndexPORInXapianFlag()

OPENTREP::shouldIndexPORInXapian_T OPENTREP::OPENTREP_Service::toggleShouldIndexPORInXapianFlag ( )

Toggle the flag stating whether to add the POR in the Xapian index

Returns
OPENTREP::shouldIndexPORInXapian_T New value of the flag

Definition at line 501 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::OPENTREP_ServiceContext::getShouldIndexPORInXapianFlag(), and OPENTREP_LOG_DEBUG.

Referenced by main().

◆ toggleShouldAddPORInSQLDBFlag()

OPENTREP::shouldAddPORInSQLDB_T OPENTREP::OPENTREP_Service::toggleShouldAddPORInSQLDBFlag ( )

Toggle the flag stating whether to add the POR in the SQL database

Returns
OPENTREP::shouldAddPORInSQLDB_T New value of the flag

Definition at line 532 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::OPENTREP_ServiceContext::getShouldAddPORInSQLDB(), OPENTREP_LOG_DEBUG, and OPENTREP::OPENTREP_ServiceContext::setShouldAddPORInSQLDB().

Referenced by main().

◆ insertIntoDBAndXapian()

NbOfDBEntries_T OPENTREP::OPENTREP_Service::insertIntoDBAndXapian ( )

From the file of OPTD-maintained POR (points of reference):

  • Add the relevant POR into the SQL database, if the corresponding flag is set
  • Add the relevant POR into the Xapian index, if the corresponding flag is set

The relevant POR are by default only the IATA-referenced ones. If the corresponding flag is set, then all the POR are relevant. All the above-mentioned flags are specified in the underlying OPENTREP_ServiceContext object.

Returns
NbOfDBEntries_T Number of documents of the file (stream).

Definition at line 897 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::OPENTREP_ServiceContext::getPORFilePath(), OPENTREP::OPENTREP_ServiceContext::getShouldAddPORInSQLDB(), OPENTREP::OPENTREP_ServiceContext::getShouldIncludeAllPORFlag(), OPENTREP::OPENTREP_ServiceContext::getShouldIndexPORInXapianFlag(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::OPENTREP_ServiceContext::getTransliterator(), OPENTREP::OPENTREP_ServiceContext::getTravelDBFilePath(), OPENTREP_LOG_DEBUG, and OPENTREP::BasChronometer::start().

Referenced by main().

◆ getNbOfPORFromDB()

◆ listByIataCode()

NbOfMatches_T OPENTREP::OPENTREP_Service::listByIataCode ( const IATACode_T & iIataCode,
LocationList_T & ioLocationList )

List all the POR (points of reference) corresponding to the given IATA code.

Parameters
constIATACode_T& The given IATA code (key).
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfMatches_T Number of matches.

Definition at line 607 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::DBManager::getPORByIATACode(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBManager::initSQLDBSession(), OPENTREP_LOG_DEBUG, OPENTREP::BasChronometer::start(), and OPENTREP::DBManager::terminateSQLDBSession().

Referenced by main().

◆ listByIcaoCode()

NbOfMatches_T OPENTREP::OPENTREP_Service::listByIcaoCode ( const ICAOCode_T & iIcaoCode,
LocationList_T & ioLocationList )

List all the POR (points of reference) corresponding to the given ICAO code.

Parameters
constICAOCode_T& The given ICAO code (key).
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfMatches_T Number of matches.

Definition at line 656 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::DBManager::getPORByICAOCode(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBManager::initSQLDBSession(), OPENTREP_LOG_DEBUG, OPENTREP::BasChronometer::start(), and OPENTREP::DBManager::terminateSQLDBSession().

Referenced by main().

◆ listByFaaCode()

NbOfMatches_T OPENTREP::OPENTREP_Service::listByFaaCode ( const FAACode_T & iFaaCode,
LocationList_T & ioLocationList )

List all the POR (points of reference) corresponding to the given FAA code.

Parameters
constFAACode_T& The given FAA code (key).
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfMatches_T Number of matches.

Definition at line 704 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::DBManager::getPORByFAACode(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBManager::initSQLDBSession(), OPENTREP_LOG_DEBUG, OPENTREP::BasChronometer::start(), and OPENTREP::DBManager::terminateSQLDBSession().

Referenced by main().

◆ listByUNLOCode()

NbOfMatches_T OPENTREP::OPENTREP_Service::listByUNLOCode ( const UNLOCode_T & iUNLOCode,
LocationList_T & ioLocationList )

List all the POR (points of reference) corresponding to the given UN/LOCODE code.

Parameters
constUNLOCode_T& The given UN/LOCODE code (key).
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfMatches_T Number of matches.

Definition at line 752 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::DBManager::getPORByUNLOCode(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBManager::initSQLDBSession(), OPENTREP_LOG_DEBUG, OPENTREP::BasChronometer::start(), and OPENTREP::DBManager::terminateSQLDBSession().

Referenced by main().

◆ listByUICCode()

NbOfMatches_T OPENTREP::OPENTREP_Service::listByUICCode ( const UICCode_T & iUICCode,
LocationList_T & ioLocationList )

List all the POR (points of reference) corresponding to the given UIC code.

Parameters
constUICCode_T& The given UIC code (key).
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfMatches_T Number of matches.

Definition at line 802 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::DBManager::getPORByUICCode(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBManager::initSQLDBSession(), OPENTREP_LOG_DEBUG, OPENTREP::BasChronometer::start(), and OPENTREP::DBManager::terminateSQLDBSession().

Referenced by main().

◆ listByGeonameID()

NbOfMatches_T OPENTREP::OPENTREP_Service::listByGeonameID ( const GeonamesID_T & iGeonameID,
LocationList_T & ioLocationList )

List all the POR (points of reference) corresponding to the given Geoname ID.

Parameters
constGeonamesID_T& The given Geoname ID (key).
LocationList_T&List of (geographical) locations, if any, matching the given key.
Returns
NbOfMatches_T Number of matches.

Definition at line 849 of file OPENTREP_Service.cpp.

References OPENTREP::OPENTREP_ServiceContext::display(), OPENTREP::BasChronometer::elapsed(), OPENTREP::DBManager::getPORByGeonameID(), OPENTREP::OPENTREP_ServiceContext::getSQLDBConnectionString(), OPENTREP::OPENTREP_ServiceContext::getSQLDBType(), OPENTREP::DBManager::initSQLDBSession(), OPENTREP_LOG_DEBUG, OPENTREP::BasChronometer::start(), and OPENTREP::DBManager::terminateSQLDBSession().

Referenced by main().


The documentation for this class was generated from the following files: