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

Method sugget

redis/commands/search/commands.py:1988–2042  ·  view source on GitHub ↗

Get a list of suggestions from the AutoCompleter, for a given prefix. Parameters: prefix : str The prefix we are searching. **Must be valid ascii or utf-8** fuzzy : bool If set to true, the prefix search is done in fuzzy mode. **

(
        self,
        key: str,
        prefix: str,
        fuzzy: bool = False,
        num: int = 10,
        with_scores: bool = False,
        with_payloads: bool = False,
    )

Source from the content-addressed store, hash-verified

1986 return (await pipe.execute())[-1]
1987
1988 async def sugget(
1989 self,
1990 key: str,
1991 prefix: str,
1992 fuzzy: bool = False,
1993 num: int = 10,
1994 with_scores: bool = False,
1995 with_payloads: bool = False,
1996 ) -> List[SuggestionParser]:
1997 """
1998 Get a list of suggestions from the AutoCompleter, for a given prefix.
1999
2000 Parameters:
2001
2002 prefix : str
2003 The prefix we are searching. **Must be valid ascii or utf-8**
2004 fuzzy : bool
2005 If set to true, the prefix search is done in fuzzy mode.
2006 **NOTE**: Running fuzzy searches on short (<3 letters) prefixes
2007 can be very
2008 slow, and even scan the entire index.
2009 with_scores : bool
2010 If set to true, we also return the (refactored) score of
2011 each suggestion.
2012 This is normally not needed, and is NOT the original score
2013 inserted into the index.
2014 with_payloads : bool
2015 Return suggestion payloads
2016 num : int
2017 The maximum number of results we return. Note that we might
2018 return less. The algorithm trims irrelevant suggestions.
2019
2020 Returns:
2021
2022 list:
2023 A list of Suggestion objects. If with_scores was False, the
2024 score of all suggestions is 1.
2025
2026 For more information see `FT.SUGGET <https://redis.io/commands/ft.sugget>`_.
2027 """ # noqa
2028 args = [SUGGET_COMMAND, key, prefix, "MAX", num]
2029 if fuzzy:
2030 args.append(FUZZY)
2031 if with_scores:
2032 args.append(WITHSCORES)
2033 if with_payloads:
2034 args.append(WITHPAYLOADS)
2035
2036 ret = await self.execute_command(*args)
2037 results = []
2038 if not ret:
2039 return results
2040
2041 parser = SuggestionParser(with_scores, with_payloads, ret)
2042 return [s for s in parser]

Callers

nothing calls this directly

Calls 3

SuggestionParserClass · 0.85
appendMethod · 0.45
execute_commandMethod · 0.45

Tested by

no test coverage detected