10 #include <boost/filesystem.hpp>
11 #include <boost/filesystem/fstream.hpp>
12 #include <boost/tokenizer.hpp>
31 Xapian::WritableDatabase& ioDatabase) {
38 Xapian::TermGenerator lTermGenerator;
39 lTermGenerator.set_database (ioDatabase);
40 lTermGenerator.set_document (ioDocument);
46 for (Place::TermSetMap_T::const_iterator itStringSet = lTermSetMap.begin();
47 itStringSet != lTermSetMap.end(); ++itStringSet) {
49 const Weight_T& lWeight = itStringSet->first;
50 const Xapian::termcount lWDFInc =
51 static_cast<const Xapian::termcount
> (lWeight);
55 for (Place::StringSet_T::const_iterator itString = lTermSet.begin();
56 itString != lTermSet.end(); ++itString) {
57 const std::string& lString = *itString;
58 lTermGenerator.index_text (lString, lWDFInc);
67 for (Place::StringSet_T::const_iterator itTerm = lSpellingSet.begin();
68 itTerm != lSpellingSet.end(); ++itTerm) {
69 const std::string& lTerm = *itTerm;
70 ioDatabase.add_spelling (lTerm);
76 <<
" into " << ioDocument.get_description());
80 void IndexBuilder::addDocumentToIndex(Xapian::WritableDatabase& ioDatabase,
82 const OTransliterator& iTransliterator) {
85 Xapian::Document lDocument;
89 const RawDataString_T& lRawDataString = ioPlace.getRawDataString();
94 lDocument.set_data (lRawDataString);
98 ioPlace.buildIndexSets (iTransliterator);
104 const Xapian::docid& lDocID = ioDatabase.add_document (lDocument);
108 ioPlace.setDocID (lDocID);
113 buildSearchIndex (
const PORFilePath_T& iPORFilePath,
114 const TravelDBFilePath_T& iTravelDBFilePath,
115 const OTransliterator& iTransliterator) {
122 <<
"') will be cleared");
123 boost::filesystem::path lTravelDBFilePath (iTravelDBFilePath.begin(),
124 iTravelDBFilePath.end());
125 boost::filesystem::remove_all (lTravelDBFilePath);
126 boost::filesystem::create_directories (lTravelDBFilePath);
129 if (!(boost::filesystem::exists (lTravelDBFilePath)
130 && boost::filesystem::is_directory (lTravelDBFilePath))) {
131 std::ostringstream oStr;
132 oStr <<
"The file-path to the Xapian database/index ('"
133 << iPORFilePath <<
"') does not exist or is not a directory.";
135 throw FileNotFoundException (oStr.str());
140 Xapian::WritableDatabase lDatabase (iTravelDBFilePath, Xapian::DB_CREATE);
144 <<
"') has been checked and open");
154 lDatabase.begin_transaction();
158 << iTravelDBFilePath <<
"')");
168 boost::filesystem::path lPORFilePath (iPORFilePath.begin(),
170 if (!(boost::filesystem::exists (lPORFilePath)
171 && boost::filesystem::is_regular_file (lPORFilePath))) {
173 <<
" does not exist or cannot be open." << std::endl);
175 throw FileNotFoundException (
"The POR file " + iPORFilePath
176 +
" does not exist or cannot be read");
180 boost::filesystem::ifstream fileToBeParsed (lPORFilePath);
182 std::string itReadLine;
183 while (std::getline (fileToBeParsed, itReadLine)) {
185 PORStringParser lStringParser (itReadLine);
188 const Location& lLocation = lStringParser.generateLocation();
196 if (!(lLocation.getCommonName() ==
"NotAvailable")) {
198 lPlace.setLocation (lLocation);
201 IndexBuilder::addDocumentToIndex (lDatabase, lPlace, iTransliterator);
216 lPlace.resetMatrix();
217 lPlace.resetIndexSets();
222 lDatabase.commit_transaction();
#define OPENTREP_LOG_ERROR(iToBeLogged)
std::set< std::string > StringSet_T
#define OPENTREP_LOG_DEBUG(iToBeLogged)
static FacPlace & instance()
unsigned int NbOfDBEntries_T
const TermSetMap_T & getTermSetMap() const
void addToXapian(const Place &iPlace, Xapian::Document &ioDocument, Xapian::WritableDatabase &ioDatabase)
std::map< const Weight_T, StringSet_T > TermSetMap_T
Class modelling a place/POR (point of reference).
std::string describeKey() const
const StringSet_T & getSpellingSet() const
std::string describeSets() const