21 : _database (iDatabase), _queryString (iQueryString) {
31 if (iStringPartition.
empty() ==
false) {
32 _slices.push_back (iStringPartition);
53 std::ostringstream oStr;
60 std::ostringstream oStr;
66 short idx_sublist = 0;
67 for (StringPartitionList_T::const_iterator itSlice =
_slices.begin();
68 itSlice !=
_slices.end(); ++itSlice, ++idx_sublist) {
70 if (idx_sublist != 0) {
78 oStr << idx_sublist <<
". " << lStringPartition;
114 return oEditDistance;
122 const std::string& iWord1,
const std::string& iWord2) {
123 bool oDoesMatch =
false;
126 std::ostringstream oStr;
127 oStr << iWord1 <<
" " << iWord2;
128 const std::string lQueryString (oStr.str());
131 Xapian::MSet lMatchingSet;
135 Xapian::QueryParser lQueryParser;
136 lQueryParser.set_database (iDatabase);
144 lQueryParser.set_default_op (Xapian::Query::OP_PHRASE);
156 Xapian::Enquire enquire (iDatabase);
164 const Xapian::Query& lXapianQuery =
165 lQueryParser.parse_query (lQueryString,
166 Xapian::QueryParser::FLAG_BOOLEAN
167 | Xapian::QueryParser::FLAG_PHRASE
168 | Xapian::QueryParser::FLAG_LOVEHATE);
171 enquire.set_query (lXapianQuery);
174 lMatchingSet = enquire.get_mset (0, 20);
177 int nbMatches = lMatchingSet.size();
186 if (nbMatches != 0) {
198 assert (lMatchingSet.empty() ==
true);
209 const std::string& lCorrectedString =
210 iDatabase.get_spelling_suggestion (lQueryString, lAllowableEditDistance);
214 if (lCorrectedString.empty() ==
true || lCorrectedString == lQueryString) {
227 assert (lCorrectedString.empty() ==
false
228 && lCorrectedString != lQueryString);
241 const Xapian::Query& lCorrectedXapianQuery =
242 lQueryParser.parse_query (lCorrectedString,
243 Xapian::QueryParser::FLAG_BOOLEAN
244 | Xapian::QueryParser::FLAG_PHRASE
245 | Xapian::QueryParser::FLAG_LOVEHATE);
247 enquire.set_query (lCorrectedXapianQuery);
248 lMatchingSet = enquire.get_mset (0, 20);
251 nbMatches = lMatchingSet.size();
261 if (nbMatches != 0) {
281 << lQueryString <<
"', spelling suggestion: `"
283 <<
"', with a Levenshtein edit distance of "
285 <<
" over an allowable edit distance of "
286 << lAllowableEditDistance <<
", provides no match, "
287 <<
"which is not consistent with the existence of "
288 <<
"the spelling correction.");
291 }
catch (
const Xapian::Error& error) {
301 void QuerySlices::init() {
306 const unsigned short nbOfWords = lWordList.size();
309 if (nbOfWords <= 1) {
319 WordList_T::const_iterator itWord = lWordList.begin();
320 WordList_T::const_iterator itNextWord = lWordList.begin(); ++itNextWord;
321 for (
unsigned short idx = 1, idx_rel = 1; itNextWord != lWordList.end();
322 ++itWord, ++itNextWord, ++idx, ++idx_rel) {
323 const std::string& leftWord = *itWord;
324 const std::string& rightWord = *itNextWord;
333 const bool lDoesMatch =
336 if (lDoesMatch ==
true) {
365 const std::string& leftWord = *itWord;
TravelQuery_T _queryString
std::vector< std::string > WordList_T
const NbOfErrors_T K_DEFAULT_SIZE_FOR_SPELLING_ERROR_UNIT
#define OPENTREP_LOG_ERROR(iToBeLogged)
static int getDistance(const std::string &iSource, const std::string &iTarget)
std::string createStringFromWordList(const WordList_T &iWordList, const unsigned short iSplitIdx, const bool iFromBeginningFlag)
void push_back(const StringPartition &iStringPartition)
std::string describeKey() const
unsigned short NbOfErrors_T
std::string describe() const
StringPartitionList_T _slices
void tokeniseStringIntoWordList(const std::string &iPhrase, WordList_T &ioWordList)
const Xapian::Database & _database
QuerySlices(const Xapian::Database &, const TravelQuery_T &)
std::string TravelQuery_T
void fromStream(std::istream &ioIn)
bool doesMatch(const Xapian::Database &iDatabase, const std::string &iWord1, const std::string &iWord2)
Helper function to query for a Xapian-based full text match.
void toStream(std::ostream &ioOut) const
static unsigned int calculateEditDistance(const TravelQuery_T &iPhrase)
Helper function.