Correct user queries are getting corrected....Highlighting issues...help

15 views
Skip to first unread message

Sagar Dutta

unread,
May 21, 2022, 2:16:54 AMMay 21
to Whoosh
Hello all,
I am facing some issues where the correct user queries are getting corrected to something else. How can I make it to ignore the correct words(without spelling mistake).

The logic I was thinking to solve this is:
1. Make a list of correct words from each fields
2. if user query (say classical msic) != word in the list
3. Pass the incorrect word for spelling correction (Here second word "msic" will be corrected)

I have 24 fields in the schema and all are included in the fields to search.
Example:  Schema( Artist=TEXT(stored=True, analyzer=my_analyzer, spelling=True) )

If possible can somebody suggest how can I use the highlighting option in my code. Any hint or direction will do! I could not implement the highlighter, so it is not there in the code.

I am new to whoosh, any hint/suggestion will be highly appreciated. Thanks!

My search code:

    
    def index_search(self, dirname, search_fields, search_query):
   
        ix = index.open_dir(dirname)
        schema = ix.schema

        mp = qparser.MultifieldParser(search_fields, schema, termclass=query.Variations) 
        q = mp.parse(search_query)
       
        with ix.searcher() as s:
       
            corrected = s.correct_query(q, search_query)
           
            if corrected.query != q:
                print("Did you mean:", corrected.string)
                response = input("Enter the response [y/n]: ")
                if response == 'y':
                    cor = corrected.string
                else:
                    cor = search_query
                q_new = mp.parse(cor)
            else:
                q_new = mp.parse(search_query)
           
           
            start_time = time.time()
            results = s.search(q_new)
            print("--- %s seconds ---" % (time.time() - start_time))
           
            found = results.scored_length()

            print("Scored", found, "of exactly", len(results), "documents")
            print("Search Results: \n ")
           
            for i in range(0,found):
                print(results[i])
                print("\n")


Reply all
Reply to author
Forward
0 new messages