Autocomplete

class autocomplete.autocompleter.Autocompleter(limit: int, fuzzy_match_threshold: int, trigram_match_threshold: int)

Autocomplete user input by providing matching questions from the database.

limit

number of results to return

Type:

int

fuzzy_match_threshold

threshold for fuzzy matching with levenshtein, only results with a similarity score below this threshold will be returned

Type:

int

trigram_match_threshold

threshold for trigram matching, only results with a similarity score above this threshold will be returned

Type:

int

async get_autocomplete(db: Session, question: str, language: str = None, k: int = 0, tag: str = None)

Returns matching results according to a defined behaviour.

If the user input ends with a “?” character, return a set of questions that may be relevant to the user. Else return the results stored in the cache from the previous query.

If there are at lest 5 results from fuzzy matching, fuzzy matching returned. Otherwise, results of semantic similarity matching are returned alongside the fuzzy matching results.

Parameters:
  • db (Session) – database session

  • question (str) – question to match

  • language (str) – question and results language

  • k (int) – number of results to return

Returns:

a list of matching results

Return type:

list of str