[Xapian-discuss] Making Spelling Suggestion/Correction Work!
Benny Chan
misterchan at gmail.com
Fri Jul 27 23:38:07 BST 2007
Hello All,
I have found solutions to my previous issues and have stumbled upon a new
one. Spelling suggestion. I can't get it to work. I index my documents as
usual, then I run this code in PHP:
//create a query parser
$query_parser = new XapianQueryParser();
$query_parser->set_default_op(XapianQuery::OP_AND);
$rp = new XapianDateValueRangeProcessor(0, true);
$query_parser->add_valuerangeprocessor($rp);
//set the stemmer and turn on the stemming strategy
$stemmer = new XapianStem("english");
$query_parser->set_stemmer($stemmer);
$query_parser->set_stemming_strategy(XapianQueryParser::STEM_SOME);
//set the database
$query_parser->set_database($db);
//set prefix
$query_parser->add_boolean_prefix("category", "XC");
//add prefix so you can search within titles
$query_parser->add_prefix("title", "S");
//create enquire object
$enq = new XapianEnquire($db);
//parse and create the query
$query = $query_parser->parse_query($_REQUEST["search"],
XapianQueryParser::FLAG_SPELLING_CORRECTION);
if (strlen(trim($_REQUEST["broad_category_id"])) > 0) {
$query = new XapianQuery(XapianQuery::OP_FILTER, $query, new
XapianQuery("XC" . $_REQUEST["broad_category_id"]));
}
$var = $query_parser->get_corrected_query_string();
echo $var . "\n";
I type in mispelled words like "edcation" and "scool" but get nothing. The
words "education" and "school" return results so I'm assuming those words
are in the spelling database. However, I don't know. I just index documents
as usual without manually creating a separate spelling database. Should I?
This seems like such a cool feature, I'm dying to get it to work. If anyone
can shed some light on this, I'd really appreciate it. Thanks for reading.
Benny
More information about the Xapian-discuss
mailing list