Domanda

I use Soulmate to autocomplete search results, however I want to be able to delete records after a while so they don't show up in the searchfield again. To reload the list with Soulmate seems a bit hacky and unnecessary.

I have used json to load and I have a unique record "id"

{"id":1547,"term":"Foo Baar, Baaz","score":85}

How can I delete that record from redis so it wont show up in the search results again?

È stato utile?

Soluzione

It is not trivial to do it directly from Redis, using redis-cli commands. Looking at soulmate code, the data structure is as follows:

  • a soulmate-index:[type] set containing all the prefixes

  • a soulmate-data:[type] hash object containing the association between the id and the json object.

  • per prefix, a soulmate-index:[type]:[prefix] sorted set (with score and id)

So to delete an item, you need to:

Retrieve the json object from its id (you already did it) -> id 1547
HDEL soulmate-data:[type] 1547
Generate all the possible prefixes from "Foo Baar, Baaz"
For each prefix:
   SREM soulmate-data:[type] [prefix]
   ZREM soulmate-index:[type]:[prefix] 1547

Probably it would be easier to directly call the remove method provided in the Soulmate.Loader class from a Ruby script, which automates everything for you.

https://github.com/seatgeek/soulmate/blob/master/lib/soulmate/loader.rb

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top