11 #include <boost/filesystem.hpp>
12 #include <boost/random/random_device.hpp>
13 #include <boost/random/uniform_int_distribution.hpp>
25 boost::filesystem::path
27 boost::filesystem::path oTravelDBFilePath (iTravelDBFilePath.begin(),
28 iTravelDBFilePath.end());
29 if (!(boost::filesystem::exists (oTravelDBFilePath)
30 && boost::filesystem::is_directory (oTravelDBFilePath))) {
31 std::ostringstream oStr;
32 oStr <<
"The file-path to the Xapian database/index ('"
33 << iTravelDBFilePath <<
"') does not exist or is not a directory.";
38 return oTravelDBFilePath;
43 getSize (
const TravelDBFilePath_T& iTravelDBFilePath) {
51 Xapian::Database lXapianDatabase (iTravelDBFilePath);
54 const Xapian::doccount& lDocCount = lXapianDatabase.get_doccount();
59 return oNbOfDBEntries;
64 drawRandomLocations (
const TravelDBFilePath_T& iTravelDBFilePath,
74 Xapian::Database lXapianDatabase (iTravelDBFilePath);
80 if (lTotalNbOfDocs == 0) {
88 boost::random::random_device lRandomDevice;
89 boost::random::uniform_int_distribution<> uniformDistrib (1, lTotalNbOfDocs);
94 unsigned int lRandomNbInt = uniformDistrib (lRandomDevice);
95 Xapian::docid lDocID =
static_cast<Xapian::docid
> (lRandomNbInt);
98 Xapian::Document::Internal* lDocPtr =
99 lXapianDatabase.get_document_lazily (lDocID);
101 unsigned short currentNbOfIterations = 0;
102 while (lDocPtr == NULL && 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 lDocPtr = lXapianDatabase.get_document_lazily (lDocID);
118 if (lDocPtr == NULL) {
121 <<
"generated so that it corresponds to "
122 <<
"a document in the Xapian database.");
126 const Xapian::Document lDoc (lDocPtr);
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)
unsigned short NbOfMatches_T
static Location retrieveLocation(const Xapian::Document &)
unsigned int NbOfDBEntries_T
std::list< Location > LocationList_T
boost::filesystem::path checkTravelDBFilePath(const TravelDBFilePath_T &iTravelDBFilePath)