Python 使用fuzzyfuzzy构建建议列表

Python 使用fuzzyfuzzy构建建议列表,python,fuzzywuzzy,Python,Fuzzywuzzy,我正在从数据库中构建一个建议引擎。我使用fuzzywuzzy模块将用户输入字符串与现有数据库匹配,如下所示 if request.method == "GET": display_dict = {} user_input = request.GET["user_input"] # get user input match_dict = {} food_items_obj = food_items.objects.all() # fetch all object

我正在从数据库中构建一个建议引擎。我使用fuzzywuzzy模块将用户输入字符串与现有数据库匹配,如下所示

if request.method == "GET":
    display_dict = {}
    user_input = request.GET["user_input"]  # get user input
    match_dict = {}

    food_items_obj = food_items.objects.all() # fetch all objects from table

    for items in food_items_obj :
        match = fuzz.ratio(user_input.lower(),items.name.lower()) # try to match the user input with existing names
        match_dict[match] = items.name        # put it one dictionary

    matched_dict = OrderedDict(sorted(match_dict.items(),reverse = True)) # sort the dictionary 
    if max(matched_dict.keys()) == 100: # if exact match then put in a dict and return back
        display_dict[100] = matched_dict[100]
    else :                              
  # if not found then try best matching words.. 
  ###########THIS PART I NEED SOME HELP! #############
        for k,v in matched_dict.items():
            if user_input in v :
                display_dict[k] = v  # if user input is substring of the names in database
            else:
                if k > sum([k for k,v in matched_dict.items()])/len(matched_dict): # best I could think of was to take average of ratio and display items greater than that.  
                display_dict[k] = v

    return render(request,"suggestions/home.html",{'recommendations_list':display_dict,'time_taken': time_taken})
所以我需要一些其他方面的信息。我无法从数据库中准确地选择我想要的单词

Example input :
user input : gobi
suggestions that came up:
Did you mean maaza ## unexpected word 
Did you mean gobi 65
Did you mean gobi pepper fry
Did you mean gobi parota
Did you mean kadai gobi
Did you mean aloo gobi

如何改进这一建议?我还可以使用哪些库?还有什么最好的方法(从记忆和时间的角度来看)可以做到同样的事情呢?提前谢谢

您使用的比率是多少?您正在尝试近似编辑距离吗?