11#include <boost/filesystem.hpp>
12#include <boost/random/random_device.hpp>
13#include <boost/random/uniform_int_distribution.hpp>
26 boost::filesystem::path
28 boost::filesystem::path oTravelDBFilePath (iTravelDBFilePath.begin(),
29 iTravelDBFilePath.end());
30 if (!(boost::filesystem::exists (oTravelDBFilePath)
31 && boost::filesystem::is_directory (oTravelDBFilePath))) {
32 std::ostringstream oStr;
33 oStr <<
"The file-path to the Xapian database/index ('"
34 << iTravelDBFilePath <<
"') does not exist or is not a directory.";
39 return oTravelDBFilePath;
44 getSize (
const TravelDBFilePath_T& iTravelDBFilePath) {
52 Xapian::Database lXapianDatabase (iTravelDBFilePath);
55 const Xapian::doccount& lDocCount = lXapianDatabase.get_doccount();
60 return oNbOfDBEntries;
75 Xapian::Database lXapianDatabase (iTravelDBFilePath);
81 if (lTotalNbOfDocs == 0) {
89 boost::random::random_device lRandomDevice;
90 boost::random::uniform_int_distribution<> uniformDistrib (1, lTotalNbOfDocs);
95 unsigned int lRandomNbInt = uniformDistrib (lRandomDevice);
96 Xapian::docid lDocID =
static_cast<Xapian::docid
> (lRandomNbInt);
99 Xapian::termcount lDocLength = lXapianDatabase.get_doclength (lDocID);
101 unsigned short currentNbOfIterations = 0;
102 while (lDocLength == 0 && currentNbOfIterations <= 100) {
105 <<
" document ID does not exist in the Xapian "
106 <<
"database. Another ID will be generated.");
109 lRandomNbInt = uniformDistrib (lRandomDevice);
110 lDocID =
static_cast<Xapian::docid
> (lRandomNbInt);
113 lDocLength = lXapianDatabase.get_doclength (lDocID);
118 if (lDocLength == 0) {
121 <<
"generated so that it corresponds to "
122 <<
"a document in the Xapian database.");
126 const Xapian::Document lDoc = lXapianDatabase.get_document (lDocID);
127 const std::string& lDocDataStr = lDoc.get_data();
128 const RawDataString_T& lDocData = RawDataString_T (lDocDataStr);
134 ioLocationList.push_back (lLocation);
139 oNbOfMatches = ioLocationList.size();
140 if (oNbOfMatches != iNbOfDraws) {
143 <<
"but " << oNbOfMatches
144 <<
" have been generated.");
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
#define OPENTREP_LOG_NOTIFICATION(iToBeLogged)
static Location retrieveLocation(const Xapian::Document &)
unsigned int NbOfDBEntries_T
std::list< Location > LocationList_T
boost::filesystem::path checkTravelDBFilePath(const TravelDBFilePath_T &iTravelDBFilePath)
unsigned short NbOfMatches_T