106 unsigned short& ioSpellingErrorDistance,
107 std::string& ioQueryString,
108 std::string& ioXapianDBFilepath,
109 std::string& ioSQLDBTypeString,
110 std::string& ioSQLDBConnectionString,
111 unsigned short& ioDeploymentNumber,
112 std::string& ioLogFilename,
113 unsigned short& ioSearchType,
114 std::ostringstream& oStr) {
117 if (ioQueryString.empty() ==
true) {
126 boost::program_options::options_description generic (
"Generic options");
127 generic.add_options()
128 (
"prefix",
"print installation prefix")
129 (
"version,v",
"print version string")
130 (
"help,h",
"produce help message");
134 boost::program_options::options_description config (
"Configuration");
138 "Spelling error distance (e.g., 3)")
141 "Xapian database filepath (e.g., /tmp/opentrep/xapian_traveldb)")
144 "SQL database type (e.g., nodb for no SQL database, sqlite for SQLite, pg for PostgreSQL, mysql for MariaDB/MySQL)")
146 boost::program_options::value< std::string >(&ioSQLDBConnectionString),
147 "SQL database connection string (e.g., ~/tmp/opentrep/sqlite_travel.db for SQLite, "
148 "\"dbname=trep_trep user=trep password=trep\" for PostgreSQL, "
149 "\"db=trep_trep user=trep password=trep\" for MariaDB/MySQL)")
152 "Deployment number (from to N, where N=1 normally)")
155 "Filepath for the logs")
158 "Type of search request (0 = full text, 1 = coordinates)")
160 boost::program_options::value< WordList_T >(&lWordList)->multitoken(),
161 "Travel query word list (e.g. sna francisco rio de janero los angeles reykyavki), "
162 "which sould be located at the end of the command line (otherwise, "
163 "the other options would be interpreted as part of that travel query word list)")
168 boost::program_options::options_description hidden (
"Hidden options");
171 boost::program_options::value< std::vector<std::string> >(),
172 "Show the copyright (license)");
174 boost::program_options::options_description cmdline_options;
175 cmdline_options.add(generic).add(config).add(hidden);
177 boost::program_options::options_description config_file_options;
178 config_file_options.add(config).add(hidden);
180 boost::program_options::options_description visible (
"Allowed options");
181 visible.add(generic).add(config);
183 boost::program_options::positional_options_description p;
184 p.add (
"copyright", -1);
186 boost::program_options::variables_map vm;
187 boost::program_options::
188 store (boost::program_options::command_line_parser (argc, argv).
189 options (cmdline_options).positional(p).run(), vm);
191 std::ifstream ifs (
"opentrep-searcher.cfg");
192 boost::program_options::store (parse_config_file (ifs, config_file_options),
194 boost::program_options::notify (vm);
196 if (vm.count (
"help")) {
197 std::cout << visible << std::endl;
201 if (vm.count (
"version")) {
202 std::cout << PACKAGE_NAME <<
", version " << PACKAGE_VERSION << std::endl;
206 if (vm.count (
"prefix")) {
207 std::cout <<
"Installation prefix: " << PREFIXDIR << std::endl;
211 if (vm.count (
"deploymentnb")) {
212 ioDeploymentNumber = vm[
"deploymentnb"].as<
unsigned short >();
213 oStr <<
"Deployment number: " << ioDeploymentNumber << std::endl;
216 if (vm.count (
"xapiandb")) {
217 ioXapianDBFilepath = vm[
"xapiandb"].as< std::string >();
218 oStr <<
"Xapian database filepath is: " << ioXapianDBFilepath
219 << ioDeploymentNumber << std::endl;
222 if (vm.count (
"sqldbtype")) {
223 ioSQLDBTypeString = vm[
"sqldbtype"].as< std::string >();
224 oStr <<
"SQL database type is: " << ioSQLDBTypeString << std::endl;
230 ioSQLDBConnectionString =
"";
243 if (vm.count (
"sqldbconx")) {
244 ioSQLDBConnectionString = vm[
"sqldbconx"].as< std::string >();
251 const std::string& lSQLDBConnString =
253 ioSQLDBConnectionString,
256 oStr <<
"SQL database connection string is: " << lSQLDBConnString
260 if (vm.count (
"log")) {
261 ioLogFilename = vm[
"log"].as< std::string >();
262 oStr <<
"Log filename is: " << ioLogFilename << std::endl;
265 oStr <<
"The type of search is: " << ioSearchType << std::endl;
267 oStr <<
"The spelling error distance is: " << ioSpellingErrorDistance
271 oStr <<
"The travel query string is: " << ioQueryString << std::endl;
281 std::ostringstream oStr;
288 lNonMatchedWordList);
290 oStr << nbOfMatches <<
" (geographical) location(s) have been found "
291 <<
"matching your query (`" << iTravelQuery <<
"'). "
292 << lNonMatchedWordList.size() <<
" word(s) was/were left unmatched."
295 if (nbOfMatches != 0) {
297 for (OPENTREP::LocationList_T::const_iterator itLocation =
298 lLocationList.begin();
299 itLocation != lLocationList.end(); ++itLocation, ++idx) {
301 oStr <<
" [" << idx <<
"]: " << lLocation << std::endl;
305 if (lNonMatchedWordList.empty() ==
false) {
306 oStr <<
"List of unmatched words:" << std::endl;
309 for (OPENTREP::WordList_T::const_iterator itWord =
310 lNonMatchedWordList.begin();
311 itWord != lNonMatchedWordList.end(); ++itWord, ++idx) {
313 oStr <<
" [" << idx <<
"]: " << lWord << std::endl;
321int main (
int argc,
char* argv[]) {
327 std::string lLogFilename;
330 std::string lXapianDBNameStr;
333 unsigned short lSearchType;
336 unsigned short lSpellingErrorDistance;
339 std::string lSQLDBTypeStr;
342 std::string lSQLDBConnectionStr;
348 std::ostringstream oIntroStr;
351 const int lOptionParserStatus =
353 lXapianDBNameStr, lSQLDBTypeStr, lSQLDBConnectionStr,
354 lDeploymentNumber, lLogFilename, lSearchType, oIntroStr);
361 std::ofstream logOutputFile;
363 logOutputFile.open (lLogFilename.c_str());
364 logOutputFile.clear();
367 std::cout << oIntroStr.str();
371 boost::posix_time::ptime lTimeUTC =
372 boost::posix_time::second_clock::universal_time();
373 logOutputFile <<
"[" << lTimeUTC <<
"][" << __FILE__ <<
"#"
374 << __LINE__ <<
"]:Parameters:" << std::endl
375 << oIntroStr.str() << std::endl;
378 std::ostringstream oStr;
379 if (lSearchType == 0) {
385 lDBType, lSQLDBConnStr,
392 const bool lExistXapianDBDir =
394 if (lExistXapianDBDir ==
false) {
395 std::ostringstream errorStr;
396 errorStr <<
"Error - The file-path to the Xapian database/index ('"
397 << lActualXapianDBDir
398 <<
"') does not exist or is not a directory." << std::endl;
399 errorStr <<
"\tThat usually means that the OpenTREP indexer "
400 <<
"(opentrep-indexer) has not been launched yet, "
401 <<
"or that it has operated on a different Xapian "
402 <<
"database/index file-path." << std::endl;
403 errorStr <<
"\tFor instance the Xapian database/index may have been "
404 <<
"created with a different deployment number ("
405 << lDeploymentNumber <<
" being the current deployment number)";
406 std::cerr << errorStr.str() << std::endl;
411 const std::string& lOutput =
parseQuery (opentrepService, lTravelQuery);
415 oStr <<
"Finding the airports closest to: " << lTravelQuery << std::endl;
419 std::cout << oStr.str();
422 lTimeUTC = boost::posix_time::second_clock::universal_time();
423 logOutputFile <<
"[" << lTimeUTC <<
"][" << __FILE__ <<
"#"
424 << __LINE__ <<
"]:Results:" << std::endl
425 << oStr.str() << std::endl;
428 logOutputFile.close();
int readConfiguration(int argc, char *argv[], unsigned short &ioSpellingErrorDistance, std::string &ioQueryString, std::string &ioXapianDBFilepath, std::string &ioSQLDBTypeString, std::string &ioSQLDBConnectionString, unsigned short &ioDeploymentNumber, std::string &ioLogFilename, unsigned short &ioSearchType, std::ostringstream &oStr)