23 : _database (iDatabase), _queryString (iQueryString) {
24 init (iTransliterator);
33 if (iStringPartition.
empty() ==
false) {
34 _slices.push_back (iStringPartition);
55 std::ostringstream oStr;
62 std::ostringstream oStr;
68 short idx_sublist = 0;
69 for (StringPartitionList_T::const_iterator itSlice =
_slices.begin();
70 itSlice !=
_slices.end(); ++itSlice, ++idx_sublist) {
72 if (idx_sublist != 0) {
80 oStr << idx_sublist <<
". " << lStringPartition;
116 return oEditDistance;
124 const std::string& iWord1,
const std::string& iWord2) {
125 bool oDoesMatch =
false;
128 std::ostringstream oStr;
129 oStr << iWord1 <<
" " << iWord2;
130 const std::string lQueryString (oStr.str());
133 Xapian::MSet lMatchingSet;
137 Xapian::QueryParser lQueryParser;
138 lQueryParser.set_database (iDatabase);
146 lQueryParser.set_default_op (Xapian::Query::OP_PHRASE);
158 Xapian::Enquire enquire (iDatabase);
166 const Xapian::Query& lXapianQuery =
167 lQueryParser.parse_query (lQueryString,
168 Xapian::QueryParser::FLAG_BOOLEAN
169 | Xapian::QueryParser::FLAG_PHRASE
170 | Xapian::QueryParser::FLAG_LOVEHATE);
173 enquire.set_query (lXapianQuery);
176 lMatchingSet = enquire.get_mset (0, 20);
179 int nbMatches = lMatchingSet.size();
188 if (nbMatches != 0) {
200 assert (lMatchingSet.empty() ==
true);
211 const std::string& lCorrectedString =
212 iDatabase.get_spelling_suggestion (lQueryString, lAllowableEditDistance);
216 if (lCorrectedString.empty() ==
true || lCorrectedString == lQueryString) {
229 assert (lCorrectedString.empty() ==
false
230 && lCorrectedString != lQueryString);
243 const Xapian::Query& lCorrectedXapianQuery =
244 lQueryParser.parse_query (lCorrectedString,
245 Xapian::QueryParser::FLAG_BOOLEAN
246 | Xapian::QueryParser::FLAG_PHRASE
247 | Xapian::QueryParser::FLAG_LOVEHATE);
249 enquire.set_query (lCorrectedXapianQuery);
250 lMatchingSet = enquire.get_mset (0, 20);
253 nbMatches = lMatchingSet.size();
263 if (nbMatches != 0) {
283 << lQueryString <<
"', spelling suggestion: `"
285 <<
"', with a Levenshtein edit distance of "
287 <<
" over an allowable edit distance of "
288 << lAllowableEditDistance <<
", provides no match, "
289 <<
"which is not consistent with the existence of "
290 <<
"the spelling correction.");
293 }
catch (
const Xapian::Error& error) {
303 void QuerySlices::init (
const OTransliterator& iTransliterator) {
312 const unsigned short nbOfWords = lWordList.size();
315 if (nbOfWords <= 1) {
325 WordList_T::const_iterator itWord = lWordList.begin();
326 WordList_T::const_iterator itNextWord = lWordList.begin(); ++itNextWord;
327 for (
unsigned short idx = 1, idx_rel = 1; itNextWord != lWordList.end();
328 ++itWord, ++itNextWord, ++idx, ++idx_rel) {
329 const std::string& leftWord = *itWord;
330 const std::string& rightWord = *itNextWord;
339 const bool lDoesMatch =
342 if (lDoesMatch ==
true) {
371 const std::string& leftWord = *itWord;