You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File "C:\Users\Chris\AppData\Local\Python\venv\document-search\Lib\site-packages\whoosh\spelling.py", line 327, in correct_query
sugs = c.suggest(token.text, prefix=prefix, maxdist=maxdist)
File "C:\Users\Chris\AppData\Local\Python\venv\document-search\Lib\site-packages\whoosh\spelling.py", line 73, in suggest
sugs = sorted(heap, key=lambda x: (0 - x[0], x[1]))
File "C:\Users\Chris\AppData\Local\Python\venv\document-search\Lib\site-packages\whoosh\spelling.py", line 73, in
sugs = sorted(heap, key=lambda x: (0 - x[0], x[1]))
TypeError: unsupported operand type(s) for -: 'int' and 'str'
Happens because Corrector expects _suggestions() to return (score, sug) like the other implementations, but MultiCorrector uses iteritems(seen) on a {sug: score} dict, which gives us reversed tuples.
whoosh\spelling.py line 173
classMultiCorrector(Corrector):
""" Merges suggestions from a list of sub-correctors. """def__init__(self, correctors, op):
self.correctors=correctorsself.op=opdef_suggestions(self, text, maxdist, prefix):
op=self.opseen= {}
forcorrinself.correctors:
forscore, sugincorr._suggestions(text, maxdist, prefix):
ifsuginseen:
seen[sug] =op(seen[sug], score)
else:
seen[sug] =scorereturniteritems(seen) # <----- (sug, score) tuples instead of (score, sug)
Proposed fix:
return ((v, k) fork, vinseen.items()) # generator
The text was updated successfully, but these errors were encountered:
CodeOptimist
changed the title
MultiCorrector returns (sug, score) instead of (score, sug)MultiCorrector returns (sug, score) instead of (score, sug)Dec 5, 2023
cclauss
pushed a commit
to cclauss/whoosh-1
that referenced
this issue
Jan 4, 2024
Happens because
Corrector
expects_suggestions()
to return(score, sug)
like the other implementations, butMultiCorrector
usesiteritems(seen)
on a{sug: score}
dict, which gives us reversed tuples.whoosh\spelling.py
line 173Proposed fix:
The text was updated successfully, but these errors were encountered: