[Xapian-discuss] Getting spelling to work

Deron Meranda deron.meranda at gmail.com
Tue Jan 8 18:29:52 GMT 2008


I can't seem to get the spelling correction/suggestion feature to work with
the query parser.  Using the Python bindings with Xapian 1.0.5.

Roughly I'm doing this...

### Set up the database with a spelling word
db = xapian.WritableDatabase( '/path/to/index', xapian.DB_CREATE_OR_OPEN )
db.add_spelling( 'database' )
db.flush()

[w.term for w in db.spellings()]
==> ['database']

db.get_spelling_suggestion( 'datapase' )
==> 'database'     # OKAY, RETURNS CORRECT SPELLING

### Set up a query parser and enquier object
qp = xapian.QueryParser()
qp.set_database( db )
stemmer = xapian.Stem( 'en' )
qp.set_stemmer( stemmer )
qp.set_stemming_strategy( qp.STEM_SOME )

enq = xapian.Enquire( db )
enq.set_cutoff( 25 )

### Do a query with the correctly spelled word
query = qp.parse_query( 'database', qp.FLAG_SPELLING_CORRECTION )
enq.set_query( query )
mset = enq.get_mset( 0, 20 )

mset.size()
==> 20     # IT FINDS DOCUMENT MATCHES

qp.get_corrected_query_string()
==> ''    # NOTHING SPELLED WRONG, SO THIS IS OKAY(?)


### Do a query with the incorrectly spelled word, edit-distance = 1
query = qp.parse_query( 'datapase', qp.FLAG_SPELLING_CORRECTION )
enq.set_query( query )
mset = enq.get_mset( 0, 20 )

mset.size()
==> 0   # NO MATCHING DOCUMENTS, OKAY(?)

### Get spelling corrected query
qp.get_corrected_query_string()
==> ''    # HUH, EXPECTED TO RETURN 'database'



Note how the get_corrected_query_string() does not return anything.
I expected it to return 'database' instead.  What am I overlooking?
-- 
Deron Meranda



More information about the Xapian-discuss mailing list