MCPcopy
hub / github.com/redis/redis-py / _parse_spellcheck

Method _parse_spellcheck

redis/commands/search/commands.py:312–347  ·  view source on GitHub ↗
(self, res, **kwargs)

Source from the content-addressed store, hash-verified

310 return result, ProfileInformation(res[1])
311
312 def _parse_spellcheck(self, res, **kwargs):
313 corrections = {}
314 if res == 0:
315 return corrections
316
317 for _correction in res:
318 if isinstance(_correction, int) and _correction == 0:
319 continue
320
321 if len(_correction) != 3:
322 continue
323 if not _correction[2]:
324 continue
325 if not _correction[2][0]:
326 continue
327
328 # For spellcheck output
329 # 1) 1) "TERM"
330 # 2) "{term1}"
331 # 3) 1) 1) "{score1}"
332 # 2) "{suggestion1}"
333 # 2) 1) "{score2}"
334 # 2) "{suggestion2}"
335 #
336 # Following dictionary will be made
337 # corrections = {
338 # '{term1}': [
339 # {'score': '{score1}', 'suggestion': '{suggestion1}'},
340 # {'score': '{score2}', 'suggestion': '{suggestion2}'}
341 # ]
342 # }
343 corrections[_correction[1]] = [
344 {"score": _item[0], "suggestion": _item[1]} for _item in _correction[2]
345 ]
346
347 return corrections
348
349 def _parse_config_get(self, res, **kwargs):
350 return {kvs[0]: kvs[1] for kvs in res} if res else {}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected