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) {
328 ++itWord, ++itNextWord, ++idx, ++idx_rel) {
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.