davidcelis / recommendable

:+1::-1: A recommendation engine using Likes and Dislikes for your Ruby app
http://davidcelis.github.io/recommendable/
MIT License
1.36k stars 114 forks source link

Add ability to return #liked_by ordered by like date #97

Closed Sija closed 10 years ago

Sija commented 10 years ago

Would be super handy for showing last n likes of given model.

davidcelis commented 10 years ago

Hey @Sija, check out #94 for more info on this. The tl;dr is that Redis doesn't keep track of when elements were added or removed from SETs, so it's not really possible unless I were to completely change which underlying data structures are used here (and I'm not terribly interested in doing that right now). Sorry!

Sija commented 10 years ago

How about the returning ids in their insertion order (or rather reverse)? I reckon this should solve the problem without the need of touching underlying data structure.

On 31 Aug 2014, at 17:41, David Celis notifications@github.com wrote:

Hey @Sija, check out #94 for more info on this. The tl;dr is that Redis doesn't keep track of when elements were added or removed from SETs, so it's not really possible unless I were to completely change which underlying data structures are used here (and I'm not terribly interested in doing that right now). Sorry!

— Reply to this email directly or view it on GitHub.

davidcelis commented 10 years ago

I don't do any sorting of the IDs, so those should indeed already be returned in insertion order. That's assuming that the order of elements returned by Redis is consistent. So something like liked_movie_ids would, I'm guessing, be in insertion order but liked_movies would not

Sija commented 10 years ago

@davidcelis yep, I count on that right now. thx for clarification :)

Sija commented 10 years ago

Just FYI, Recommendable uses redis#smembers to get back array in liked_by_ids method and Redis Sets are not sorted, therefore returned array will not keep the order of like insertions.

How about changing the underlying structure to Sorted sets which are providing such functionality? We could use timestamp as a score to keep 'em those likers in line :)

davidcelis commented 10 years ago

This has been requested before (I think in the issue I linked above), but I'm not really sold on changing the underlying data structure. It would be completely incompatible with everybody's current installation of recommendable, and I think that the added functionality is too niche since almost nobody asks for it. IMO this is something that should probably be implemented in the application itself; you can use the before/after hooks provided by recommendable to insert timestamp events in your primary datastore as you wish. Sorry that this answer is probably not what you were looking for!