I'm trying to add spelling correction to Omega (1.0.7) by defining a
$suggestion OmegaScript keyword with the following patch, but
Xapian::QueryParser::get_corrected_query_string() always returns an
empty string. I'm using a database with tens of thousands of
documents, each with hundreds of words, so I would expect that a
misspelling like "comptuer" should readily be corrected to
"computer,"
but it's not. I've tried numerous misspelled queries but none of them
yield a correction string, so I suspect I'm doing something wrong.
Does anyone have any ideas?
Thank you,
Yevgeny Binder
--------------------------
--- query.cc.orig 2008-07-15 23:42:17.000000000 -0500
+++ query.cc 2008-09-03 20:17:02.000000000 -0500
@@ -236,7 +236,11 @@
}
try {
- query = qp.parse_query(query_string);
+ query = qp.parse_query(query_string,
+ qp.FLAG_PHRASE |
+ qp.FLAG_PARTIAL |
+ qp.FLAG_AUTO_MULTIWORD_SYNONYMS |
+ qp.FLAG_SPELLING_CORRECTION);
} catch (Xapian::QueryParserError &e) {
error_msg = e.get_msg();
return BAD_QUERY;
@@ -799,6 +803,7 @@
CMD_stoplist,
CMD_sub,
CMD_substr,
+CMD_suggestion,
CMD_terms,
CMD_thispage,
CMD_time,
@@ -918,6 +923,7 @@
T(stoplist, 0, 0, N, Q), // return list of stopped terms
T(sub, 2, 2, N, 0), // subtract
T(substr, 2, 3, N, 0), // substring
+T(suggestion, 0, 0, N, Q), // misspelled word correction suggestion
T(terms, 0, 0, N, M), // list of matching terms
T(thispage, 0, 0, N, M), // page number of current page
T(time, 0, 0, N, M), // how long the match took (in seconds)
@@ -1767,6 +1773,9 @@
value = args[0].substr(start, len);
break;
}
+ case CMD_suggestion:
+ value = qp.get_corrected_query_string();
+ break;
case CMD_terms:
if (enquire) {
// list of matching terms