11 #include <boost/filesystem.hpp>
49 lQueryStringWordList);
50 if (lQueryStringWordList.size() == 1) {
56 WordSet_T::const_iterator itWord = ioWordSet.find (iQueryString);
57 if (shouldBeKept ==
true && itWord == ioWordSet.end()) {
58 ioWordSet.insert (iQueryString);
59 ioWordList.push_back (iQueryString);
74 for (ResultList_T::const_iterator itResult = lResultList.begin();
75 itResult != lResultList.end(); ++itResult) {
77 const Result* lResult_ptr = *itResult;
78 assert (lResult_ptr != NULL);
85 if (hasFullTextMatched ==
false) {
88 assert (hasFullTextMatched ==
true);
126 const Xapian::Database& iDatabase,
137 for (StringPartition::StringPartition_T::const_iterator itSet =
139 itSet != iStringPartition.
_partition.end(); ++itSet) {
155 for (StringSet::StringSet_T::const_iterator itString =
156 lStringSet.
_set.begin();
157 itString != lStringSet.
_set.end(); ++itString) {
159 const std::string lQueryString (*itString);
174 const std::string& lMatchedString =
179 if (lMatchedString.empty() ==
true) {
186 <<
"========================================="
187 << std::endl <<
"Result holder: "
188 << lResultHolder.
toString() << std::endl
189 <<
"========================================="
190 << std::endl << std::endl);
196 }
catch (
const Xapian::Error& error) {
223 const bool doesBestMatchingResultHolderExist =
226 if (doesBestMatchingResultHolderExist ==
true) {
236 <<
", and has got a weight of "
238 <<
"%. The corrected string set is: "
239 << lCorrectedStringSet);
250 interpretTravelRequest (
const TravelDBFilePath_T& iTravelDBFilePath,
257 assert (iTravelQuery.empty() ==
false);
264 boost::filesystem::path lTravelDBFilePath (iTravelDBFilePath.begin(),
265 iTravelDBFilePath.end());
266 if (!(boost::filesystem::exists (lTravelDBFilePath)
267 && boost::filesystem::is_directory (lTravelDBFilePath))) {
268 std::ostringstream oStr;
269 oStr <<
"The file-path to the Xapian database/index ('"
270 << iTravelDBFilePath <<
"') does not exist or is not a directory.";
272 throw FileNotFoundException (oStr.str());
276 Xapian::Database lXapianDatabase (iTravelDBFilePath);
280 <<
"=========================================");
284 QuerySlices lQuerySlices (lXapianDatabase, iTravelQuery);
293 lQuerySlices.getStringPartitionList();
294 for (StringPartitionList_T::const_iterator itSlice =
295 lStringPartitionList.begin();
296 itSlice != lStringPartitionList.end(); ++itSlice) {
297 StringPartition lStringPartition = *itSlice;
298 const std::string& lTravelQuerySlice = lStringPartition.getInitialString();
305 ResultCombination& lResultCombination =
319 lResultCombination, ioWordList);
324 lResultCombination.displayXapianPercentages();
329 lResultCombination.calculateEnvelopeWeights();
335 lResultCombination.calculateCodeMatches();
340 lResultCombination.calculatePageRanks();
345 lResultCombination.calculateHeuristicWeights();
350 lResultCombination.calculateCombinedWeights();
366 <<
"========================================="
367 << std::endl <<
"Summary:" << std::endl
368 << lPlaceHolder.toShortString() << std::endl
369 <<
"========================================="
378 lPlaceHolder.createLocations (ioLocationList);
379 oNbOfMatches = ioLocationList.size();
const ResultList_T & getResultList() const
std::vector< std::string > WordList_T
ResultHolder & create(const TravelQuery_T &iQueryString, const Xapian::Database &iDatabase)
bool chooseBestMatchingResultHolder()
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
static void initLinkWithResult(ResultHolder &, Result &)
void addUnmatchedWord(const TravelQuery_T &iQueryString, WordList_T &ioWordList, WordSet_T &ioWordSet)
unsigned short NbOfMatches_T
static FacPlace & instance()
const ResultHolder & getBestMatchingResultHolder() const
StringSet getCorrectedStringSet() const
Structure modelling a (geographical) location.
static FacResultCombination & instance()
static Location retrieveLocation(const Xapian::Document &)
std::string fullTextMatch(const Xapian::Database &, const TravelQuery_T &)
static void initLinkWithResultHolder(ResultCombination &, ResultHolder &)
std::string describeShortKey() const
std::list< StringPartition > StringPartitionList_T
Result & create(const TravelQuery_T &, const Xapian::Database &)
std::list< Word_T > WordList_T
std::string describeShortKey() const
bool hasFullTextMatched() const
const Percentage_T & getBestMatchingWeight() const
static FacResult & instance()
static void tokeniseStringIntoWordList(const TravelQuery_T &, WordList_T &)
std::set< std::string > WordSet_T
std::string describe() const
Class wrapping functions on a list of Result objects.
std::list< Result * > ResultList_T
Class modelling a place/POR (point of reference).
static bool shouldKeep(const std::string &iPhrase, const std::string &iWord)
std::list< Location > LocationList_T
void searchString(const StringPartition &iStringPartition, const Xapian::Database &iDatabase, ResultCombination &ioResultCombination, WordList_T &ioWordList)
ResultCombination & create(const TravelQuery_T &iQueryString)
Class wrapping functions on a list of ResultHolder objects.
std::string toString() const
static FacResultHolder & instance()
void fillPlace(Place &) const
static FacPlaceHolder & instance()
StringPartition_T _partition
static void initLinkWithPlace(PlaceHolder &, Place &)
std::string toString() const
Class holding a set of strings, e.g., {"rio", "de", "janeiro"}.
std::string TravelQuery_T
void createPlaces(const ResultCombination &iResultCombination, PlaceHolder &ioPlaceHolder)
void chooseBestMatchingResultHolder(ResultCombination &ioResultCombination)
Class wrapping a set of Xapian documents having matched a given query string.
const RawDataString_T & getBestDocData() const