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);
159 enquire.set_weighting_scheme(Xapian::BM25Weight(1.0, 0.0, 1.0, 0.0, 0.5));
167 const Xapian::Query& lXapianQuery =
168 lQueryParser.parse_query (lQueryString,
169 Xapian::QueryParser::FLAG_BOOLEAN
170 | Xapian::QueryParser::FLAG_PHRASE
171 | Xapian::QueryParser::FLAG_LOVEHATE);
174 enquire.set_query (lXapianQuery);
180 int nbMatches = lMatchingSet.size();
189 if (nbMatches != 0) {
201 assert (lMatchingSet.empty() ==
true);
212 const std::string& lCorrectedString =
213 iDatabase.get_spelling_suggestion (lQueryString, lAllowableEditDistance);
217 if (lCorrectedString.empty() ==
true || lCorrectedString == lQueryString) {
230 assert (lCorrectedString.empty() ==
false
231 && lCorrectedString != lQueryString);
244 const Xapian::Query& lCorrectedXapianQuery =
245 lQueryParser.parse_query (lCorrectedString,
246 Xapian::QueryParser::FLAG_BOOLEAN
247 | Xapian::QueryParser::FLAG_PHRASE
248 | Xapian::QueryParser::FLAG_LOVEHATE);
250 enquire.set_query (lCorrectedXapianQuery);
254 nbMatches = lMatchingSet.size();
264 if (nbMatches != 0) {
284 << lQueryString <<
"', spelling suggestion: `"
286 <<
"', with a Levenshtein edit distance of "
288 <<
" over an allowable edit distance of "
289 << lAllowableEditDistance <<
", provides no match, "
290 <<
"which is not consistent with the existence of "
291 <<
"the spelling correction.");
294 }
catch (
const Xapian::Error& error) {
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.