def search(request): query_string = request.GET.get('query') task_submit = request.POST.get('task') confirmation = '' price = '' tasks = [] choices = [] if query_string: n_grams = pre_process.get_query_grams(query_string) path, choices = services_tree.search_services_tree(n_grams) confirmation = 'So, you want ' + ' '.join(path) + '?' if task_submit: choices = services_tree.services_tree[task_submit] try: len(choices) tasks = choices except: price = str(choices) return render( request, 'service_search/search.html', { 'query': query_string, 'confirmation': confirmation, 'tasks': tasks, 'price': price, })
def search(request): query_string = request.GET.get('query') task_submit = request.POST.get('task') confirmation = '' price = '' service_provider = '' tasks = [] if query_string: n_grams = pre_process.get_query_grams(query_string) path, choices = services_tree.search_services_tree(n_grams) confirmation = 'So, you want ' + ' '.join(path) + '?' if task_submit: choices = services_tree.services_tree[task_submit] try: len(choices) tasks = choices except: price = str(choices) return render(request, 'service_search/search.html', { 'query': query_string, 'confirmation': confirmation, 'tasks': tasks, 'price': price, })
# retrieve the item in the list with the max score best_match = max(matches, key=lambda item: item[1]) return best_match def search_services_tree(query_n_grams, node='root'): path = [] while not is_price(services_tree[node]): children = services_tree[node] node, score = get_top_match(query_n_grams, children) if score < 65: return path, children path.append(node) return path, services_tree[node] def is_price(value): try: value + 1 return True except: return False if __name__ == '__main__': query_string = "Install washing machine" query_n_grams = pre_process.get_query_grams(query_string) path, price = search_services_tree(query_n_grams, 'new') print path, price