Forums

How to perform spell check using Whoosh python library

Hi, How to perform spell checking using whoosh library. I have added some code which is there in documentation. but it is not correcting words. Please find my code.

def main():
    print " Hi"

    schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
    ix = create_in("/home/praveen/Downloads/who", schema)
    writer = ix.writer()
    writer.add_document(title=u"First document", path=u"/a", content=u"This is the first document we've added!")
    writer.add_document(title=u"Second document", path=u"/b",content=u"The second one is even more interesting!")
    writer.commit()

    qstring = "frm indea wroking for campany"
    qp = qparser.QueryParser("content", ix.schema)
    q = qp.parse(qstring)
    # Try correcting the query
    with ix.searcher() as s:
            corrected = s.correct_query(q,qstring)
            print(corrected)
            print(corrected.query)
            if corrected.query != q:
                print("Did you mean:", corrected.string)

if __name__ == "__main__":
    main();

And my output is :

Hi
Correction(And([Term('content', u'frm'), Term('content', u'indea'), Term('content', u'wroking'), Term('content', u'campany')]), 'frm indea wroking for campany')
(content:frm AND content:indea AND content:wroking AND content:campany)

Here input is qstring ="frm indea wroking for campany" ,

I am expecting as a output like " from India working for company" But output is coming as it is equal to input string . It is not correcting . Not getting

"Did you mean :"  with suggestions

Thanks,

are those the two documents that are you are using? Or just placeholders for the documents?