Bruno at Badiliz | 2 Mar 18:36 2009
Picon

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
(Continue reading)

James Aylett | 2 Mar 18:44 2009

Re: 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
Olly Betts | 3 Mar 04:56 2009

Re: Xapian, PHP bindings and spellings correction

On Mon, Mar 02, 2009 at 05:44:09PM +0000, James Aylett wrote:
> 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().

But note that you'll also need to OR in the default flags (with the |
operator) if you want them.

Cheers,
    Olly
Bruno at Badiliz | 3 Mar 12:23 2009
Picon

Re: Xapian, PHP bindings and spellings correction

Olly Betts <olly <at> survex.com> writes:

> 
> On Mon, Mar 02, 2009 at 05:44:09PM +0000, James Aylett wrote:
> > 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().
> 
> But note that you'll also need to OR in the default flags (with the |
> operator) if you want them.
> 
> Cheers,
>     Olly
> 

Hello James
Hello Olly,

Thank you for your answer. I had tryed what you propose me... without succes.
Here was the first code I had tryed (the exception try part):

try {
  $database = new XapianDatabase( $_PATH.'/_inc/cache/xapian/pa' );
  $enquire = new XapianEnquire($database);
  $query_string = xapianEncode( $_GET['q'] );
  $rset = new XapianRSet();
  $qp = new XapianQueryParser();
(Continue reading)

Olly Betts | 3 Mar 12:48 2009

Re: Xapian, PHP bindings and spellings correction

On Tue, Mar 03, 2009 at 11:23:31AM +0000, Bruno at Badiliz wrote:
> Even with this code, get_corrected_query_string()does not return any words even
> with a misspell word "chaussuire"  in a database of 40000 doc and 436 doc which
> contain "chaussure" without the "i" !!!

I suspect you haven't added any spellings to your database.

You can either do this from the text being indexed (if using
TermGenerator, then set FLAG_SPELLING to do it automatically:
http://xapian.org/docs/apidoc/html/classXapian_1_1TermGenerator.html )
or add spellings from a dictionary (using WritableDatabase::add_spelling():
http://xapian.org/docs/apidoc/html/classXapian_1_1WritableDatabase.html )
or both if you wish.

Cheers,
    Olly
Bruno at Badiliz | 3 Mar 13:42 2009
Picon

Re: Xapian, PHP bindings and spellings correction

Hi Olly,

I'am sorry to say .... that you were right ! 
Excuse me to take your time because I forget to set the FLAG_SPELLING and
the database to my termGenerator during the indexation.
I just add this 2 lines and everything run exactly has it should : 
  $indexer->set_flags( XapianTermGenerator::FLAG_SPELLING );
  $indexer->set_database( $database );

One more time thank you for your help and your wonderfull work

Best regards, 
Bruno at Badiliz

-----Message d'origine-----
De : Olly Betts [mailto:olly <at> survex.com] 
Envoyé : mardi 3 mars 2009 12:49
À : Bruno at Badiliz
Cc : xapian-discuss <at> lists.xapian.org
Objet : Re: [Xapian-discuss] Xapian, PHP bindings and spellings correction

On Tue, Mar 03, 2009 at 11:23:31AM +0000, Bruno at Badiliz wrote:
> Even with this code, get_corrected_query_string()does not return any words
even
> with a misspell word "chaussuire"  in a database of 40000 doc and 436 doc
which
> contain "chaussure" without the "i" !!!

I suspect you haven't added any spellings to your database.

(Continue reading)


Gmane