class TTAutoCompleter: def __init__(self, host=ip, port=port, db=db, autocomplete_name='Default'): self.ipAdd = host self.ipPort = port self.db = db self.autocomplete = AutoCompleter(autocomplete_name, host, port) def create_auto_complete(self, res): for word in res: self.autocomplete.add_suggestions(Suggestion(word, 1.0)) def suggest(self, keyword): return self.autocomplete.get_suggestions(keyword) #return self.autocomplete.get_suggestions(keyword,fuzzy=True) def delete_auto_complete(self, key): self.autocomplete.delete(key)
def post(self): mydata = request.json location = str(mydata['location']) ac = AutoCompleter(current_app.config["REDISSEARCH_INDEX"], current_app.config["REDISSEARCH_URI"]) res = ac.delete(location); if res == 1: data = {'msg': 'Location deleted'} else: data = {'msg': 'Location not found'} return data, 200
class TAS_Autocompleter: #constructor def __init__(self, autocomplete_name, host='localhost', port=6379): try: self.host = host self.port = port self.table_name = autocomplete_name self.ac = AutoCompleter(autocomplete_name, host, port) except Exception as e: print >> sys.stderr, "TAS_Autocompleter Error inside constructor Index:\'", self.table_name, "\' HOST:\'", self.host, "\' PORT:\'", self.port, "\'\n" print >> sys.stderr, e #will add the list to auto-complete entries in the respective name def add_to_autocomplete(self, new_words): try: for word in new_words: self.ac.add_suggestions(Suggestion(word, 1.0)) except Exception as e: print >> sys.stderr, "TAS_Autocompleter Error inside add_to_autocomplete Index:\'", self.table_name, "\' HOST:\'", self.host, "\' PORT:\'", self.port, "\'\n" print >> sys.stderr, e #not working as is intented, researching more... #btw, will add all the words in autocomplete dictionary def add_to_autocomplete_combination(self, new_words): try: for word in new_words: splitted = word.split(' ') splittedLength = len(splitted) for index in range(0, splittedLength): toAdd = ' '.join(splitted[index:splittedLength]) self.ac.add_suggestions(Suggestion(toAdd, 1.0)) except Exception as e: print >> sys.stderr, "TAS_Autocompleter Error inside add_to_autocomplete_combination Index:\'", self.table_name, "\' HOST:\'", self.host, "\' PORT:\'", self.port, "\'\n" print >> sys.stderr, e #will return auto-suggestions for the give prefix def suggest(self, prefix): try: return self.ac.get_suggestions(prefix, fuzzy=True) except Exception as e: print >> sys.stderr, "TAS_Autocompleter Error inside suggest Index:\'", self.table_name, "\' HOST:\'", self.host, "\' PORT:\'", self.port, "\'\n" print >> sys.stderr, e def delete(self, prefix): try: return self.ac.delete(prefix) except Exception as e: print >> sys.stderr, "TAS_Autocompleter Error inside delete Index:\'", self.table_name, "\' HOST:\'", self.host, "\' PORT:\'", self.port, "\'\n" print >> sys.stderr, e
def delete_from_ac_dict(website_item_doc): """Removes this items's name from autocomplete dictionary""" cache = frappe.cache() name_ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=cache) name_ac.delete(website_item_doc.web_item_name)