Whoosh fuzzy statement not working.

Viewed 209

When running this block of code, I don't get a hit on any partial matches I put into the query string. For example "Methyl" doesn't return any hits but entire words like "Jenkins" do. Could someone please point out the issue it's probably something stupid I'm doing as I'm using whoosh for the first time. I basically want to be able to achieve partial matches on any set of over three consecutive characters in a string, anywhere in the string.

            import sys
            import os

            from whoosh.fields import Schema, TEXT, STORED
            from whoosh.index import create_in, open_dir
            #from whoosh.query import *
            from whoosh.qparser import QueryParser
            from whoosh.query import FuzzyTerm

            #creating the schema
            schema = Schema(tax_id=STORED,
                            name=TEXT(stored=True))

            #creating the index
            if not os.path.exists("index"):
                os.mkdir("index")

            #ix = create_in("index",schema)
            ix = open_dir("index")
            #writer = ix.writer()
            #writer.add_document(tax_id="17",name=u"Methyliphilus methylitrophus")
            #writer.add_document(tax_id="17",name=u"Methylophilus methylotrophus Jenkins et al. 1987")
            #writer.add_document(tax_id="45",name=u"Chondromyces lichenicolus") 
            #writer.commit()

            #myquery = And([Term("name",u"Chondromyces")])
            with ix.searcher() as searcher:
                query = QueryParser("name", ix.schema, termclass = FuzzyTerm).parse(u"Methyl")
                results = searcher.search(query)
                for i in results:
                    print i['name']
                    print i['tax_id']
0 Answers
Related