gem 'soulmate' to your GEMFILE and bundle installredis as a dependencyafter_save callback to your model object:class Person
after_save :load_into_soulmate
def load_into_soulmate
loader = Soulmate::Loader.new("person")
loader.add("id" => id, "term" => name)
# term will be the attribute you want to search for in autocomplete
end
end
If the following error occurs: Redis::CommandError: ERR value is not a valid float
score: 1 in the loader.add() parameter hashAfter that, run a task to update your model objects
Soulmate::Loader.new(db_name).add({
"term" => "value of field that will be sesrched on",
"id" => "record.id" if using ActiceRecord,
"value" => "string representation what to return to frontend"
})
keys * to obtain all keys in this current redis dbSoulmate::Loader.new("person") will create the following keys:
soulmate-data:person: stores in a hash the attributes you added
when you used loader.addsoulmate-index:person: stores a list of partial substrings of the term attribute
keys *keys soulmate-data:person *: retrieves all values in this keykeys soulmate-index:person:sub_string*: retrieves all values in the DB that contain this sub_stringhgetall soulmate-data:personhget soulmate-data:person 1: get value with id = 1select #: selects a dbdbsize: returns the number of keys in that dbsoulmate-index and soulmate-data keyssoulmate-index: is the collection of partial strings of the search termsoulmate-data: is the hash object formed when you produce the hash in the matches collectionzscore soulmate-index:cat:f7f 1643: contains the key of the db as well as the id
(should be the same id of the product) of the keyredis-cli FLUSHALLredis-cli FLUSHDBredis-cli -n <database_number> FLUSHDB