Bruno at Badiliz
2009-Mar-02 17:36 UTC
[Xapian-discuss] Xapian, PHP bindings and spellings correction
Hello, With PHP, I try to get spelling corrections but after 2 days of trying I can make it work !!! Here is my < simple > code : <?php require_once( '../global.info.php' ); require_once( 'xapian.class.php' ); require_once( 'xapianencode.func.php' ); // Open the database for searching. try { $database = new XapianDatabase( $_PATH.'/_inc/cache/xapian/pa' ); // Start an enquire session. $enquire = new XapianEnquire($database); // Combine the rest of the command line arguments with spaces between // them, so that simple queries don't have to be quoted at the shell // level. $query_string = xapianEncode( $_GET['q'] ); $rset = new XapianRSet(); $qp = new XapianQueryParser(); $stemmer = new XapianStem( 'french' ); $qp->set_stemmer($stemmer); $qp->set_database($database); $qp->set_stemming_strategy(XapianQueryParser::STEM_SOME); $query = $qp->parse_query( $query_string ); //, XapianQueryParser::FLAG_SPELLING_CORRECTION); print 'Parsed query is: '. $query->get_description() .'<br />'."\n"; // Find the top 10 results for the query. $enquire->set_query($query); $matches = $enquire->get_mset(0, 100); //correction spelling echo '<hr />'; $i = $database->spellings_begin(); while( ! $i->equals( $database->spellings_end())) { var_dump( $i ); } echo '<hr />'; // Display the results. print $matches->get_matches_estimated() .' results found:<br />'."\n"; $i = $matches->begin(); while ( ! $i->equals($matches->end())) { $n = $i->get_rank() + 1; $data = $i->get_document()->get_data(); echo "$n: {$i->get_percent()}% docid={$i->get_docid()} [$data]<br />"; echo "<br />\n\n"; $i->next(); } } catch (Exception $e) { print $e->getMessage() . "<br />\n"; exit(1); } The spellings_begin() boucle does not return any words even with a misspell word '' chaussuire' in a database of 40000 doc and 436 doc wich contain 'chaussure' without the 'i' !!! Have you any idea of what is wrong in my code ? Thank you very much for your help Bruno Badiliz PS to Xapian team : A big thanks for your a great job ;-) I am going to replace a deadly (hardware) Google Search Appliance with Xapian as soon as possible ;-)
James Aylett
2009-Mar-02 17:44 UTC
[Xapian-discuss] Xapian, PHP bindings and spellings correction
On Mon, Mar 02, 2009 at 06:36:01PM +0100, Bruno at Badiliz wrote:> $query = $qp->parse_query( $query_string ); //, > XapianQueryParser::FLAG_SPELLING_CORRECTION);Uncomment this, and then check $query->get_corrected_query_string().> $i = $database->spellings_begin(); > while( ! $i->equals( $database->spellings_end())) { > var_dump( $i ); > }This doesn't do what you expect it to do, and is probably not helpful to you at all. See <http://xapian.org/docs/apidoc/html/classXapian_1_1Database.html#2f78aa0fe39a3b68e10ca865dc0f86ef>. J -- James Aylett talktorex.co.uk - xapian.org - uncertaintydivision.org