[Xapian-discuss] Xapian, PHP bindings and

Bruno at Badiliz xapian at badiliz.fr
Mon Mar 2 17:34:51 GMT 2009


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 ;-)



More information about the Xapian-discuss mailing list