8 #include <boost/date_time/gregorian/gregorian.hpp>
9 #include <boost/date_time/posix_time/ptime.hpp>
28 OPENTREP_Service (std::ostream& ioLogStream,
const PORFilePath_T& iPORFilepath,
31 : _opentrepServiceContext (NULL) {
32 init (ioLogStream, iPORFilepath, iTravelDBFilePath, iSQLiteDBFilePath);
37 OPENTREP_Service (std::ostream& ioLogStream,
40 : _opentrepServiceContext (NULL) {
41 init (ioLogStream, iTravelDBFilePath, iSQLiteDBFilePath);
45 OPENTREP_Service::OPENTREP_Service() : _opentrepServiceContext (NULL) {
50 OPENTREP_Service::OPENTREP_Service (
const OPENTREP_Service& iService) {
62 std::ostream& ioLogOutputFile) {
67 void OPENTREP_Service::init (std::ostream& ioLogStream,
68 const TravelDBFilePath_T& iTravelDBFilePath,
69 const SQLiteDBFilePath_T& iSQLiteDBFilePath) {
74 OPENTREP_ServiceContext& lOPENTREP_ServiceContext =
76 _opentrepServiceContext = &lOPENTREP_ServiceContext;
80 lOPENTREP_ServiceContext.setWorld (lWorld);
84 void OPENTREP_Service::init (std::ostream& ioLogStream,
85 const PORFilePath_T& iPORFilepath,
86 const TravelDBFilePath_T& iTravelDBFilePath,
87 const SQLiteDBFilePath_T& iSQLiteDBFilePath) {
92 OPENTREP_ServiceContext& lOPENTREP_ServiceContext =
94 iTravelDBFilePath, iSQLiteDBFilePath);
95 _opentrepServiceContext = &lOPENTREP_ServiceContext;
99 lOPENTREP_ServiceContext.setWorld (lWorld);
103 void OPENTREP_Service::finalise() {
108 if (_opentrepServiceContext == NULL) {
112 assert (_opentrepServiceContext != NULL);
126 const DBFilePathPair_T lDBFilePathPair (lTravelDBFilePath, lSQLiteDBFilePath);
135 if (_opentrepServiceContext == NULL) {
139 assert (_opentrepServiceContext != NULL);
148 oNbOfEntries = XapianIndexManager::getSize (lTravelDBFilePath);
149 const double lIndexSizeMeasure = lIndexSizeChronometer.
elapsed();
153 << lIndexSizeMeasure <<
" - "
154 << lOPENTREP_ServiceContext.
display());
165 if (_opentrepServiceContext == NULL) {
169 assert (_opentrepServiceContext != NULL);
178 oNbOfMatches = XapianIndexManager::drawRandomLocations (lTravelDBFilePath,
181 const double lRandomGetMeasure = lRandomGetChronometer.
elapsed();
185 << lRandomGetMeasure <<
" - "
186 << lOPENTREP_ServiceContext.
display());
195 if (_opentrepServiceContext == NULL) {
199 assert (_opentrepServiceContext != NULL);
211 lDBCreationChronometer.
start();
213 const double lDBCreationMeasure = lDBCreationChronometer.
elapsed();
217 <<
" - " << lOPENTREP_ServiceContext.
display());
226 if (_opentrepServiceContext == NULL) {
230 assert (_opentrepServiceContext != NULL);
246 lBuildSearchIndexChronometer.
start();
247 oNbOfEntries = IndexBuilder::buildSearchIndex (lPORFilePath,
250 const double lBuildSearchIndexMeasure =
251 lBuildSearchIndexChronometer.
elapsed();
255 << lBuildSearchIndexMeasure <<
" - "
256 << lOPENTREP_ServiceContext.
display());
268 if (_opentrepServiceContext == NULL) {
272 assert (_opentrepServiceContext != NULL);
276 boost::posix_time::ptime lNowDateTime =
277 boost::posix_time::second_clock::local_time();
282 <<
"==================================================="
284 << lNowDateTime <<
" - Match query '" << iTravelQuery
285 <<
"' on Xapian database (index)");
288 if (iTravelQuery.empty() ==
true) {
289 std::ostringstream errorStr;
290 errorStr <<
"The travel request is empty.";
301 lRequestInterpreterChronometer.
start();
302 nbOfMatches = RequestInterpreter::interpretTravelRequest (lTravelDBFilePath,
306 const double lRequestInterpreterMeasure =
307 lRequestInterpreterChronometer.
elapsed();
311 << lRequestInterpreterMeasure <<
" - "
312 << lOPENTREP_ServiceContext.
display());
std::pair< const TravelDBFilePath_T, const SQLiteDBFilePath_T > DBFilePathPair_T
NbOfDBEntries_T getIndexSize()
Structure allowing measuring the time elapsed between two events.
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
unsigned short NbOfMatches_T
const TravelDBFilePath_T & getTravelDBFilePath() const
NbOfDBEntries_T buildSQLDB()
const PORFilePath_T & getPORFilePath() const
static NbOfDBEntries_T buildSQLDB(const PORFilePath_T &, const SQLiteDBFilePath_T &)
const SQLiteDBFilePath_T & getSQLiteDBFilePath() const
Class holding the context of the OpenTrep services.
const OTransliterator & getTransliterator() const
static FacWorld & instance()
void setLogParameters(const LOG::EN_LogLevel iLogLevel, std::ostream &ioLogStream)
unsigned int NbOfDBEntries_T
std::list< Word_T > WordList_T
const std::string display() const
static FacOpenTrepServiceContext & instance()
NbOfMatches_T drawRandomLocations(const NbOfMatches_T &iNbOfDraws, LocationList_T &)
std::list< Location > LocationList_T
OPENTREP_ServiceContext & create(const TravelDBFilePath_T &, const SQLiteDBFilePath_T &)
NbOfDBEntries_T buildSearchIndex()
NbOfMatches_T interpretTravelRequest(const std::string &iTravelQuery, LocationList_T &, WordList_T &)
std::pair< const PORFilePath_T, const DBFilePathPair_T > FilePathSet_T
static Logger & instance()
FilePathSet_T getFilePaths() const
void logInit(const LOG::EN_LogLevel iLogLevel, std::ostream &ioLogOutputFile)