rutan / potmum

Potmum is cloud note-app.
MIT License
114 stars 11 forks source link

Prioritize recent articles in popular articles #37

Open onk opened 6 years ago

onk commented 6 years ago

Current algorithm of popular article has a problem that older articles come higher.

scope :popular, -> {
  where(publish_type: 2).order(stock_count: :desc, view_count: :desc)
}

I want to add recently weight to popular article.

There are 3 choices.

Use Search Engine such as elasticsearch, solr etc

Search engine is the best solution because this is search problem.

e.g.

By introducing a search engine, we can also get "advanced search" and "related articles" widget.

Use Redis sorted set

redis sorted set is one of the best ways to implement access ranking.

e.g. https://siguniang.wordpress.com/2014/09/15/access-ranking-with-redis-sorted-sets/

boffin gem seems to be the best in my reading. boffin uses zunionstore very well and it can provide simple and flexible access rankings.

For example, the ranking in 7 days that stock has double weighted than view is as follows.

Article.top_ids({ stocks: 2, views: 1 }, days: 7)

boffin is less active, but I think there is no problem.

redis is also used as a queue for asynchronous/scheduled processing such as sidekiq. It can be used to asynchronize notifications, to post rankings to slack on daily, etc.

Use Analytics gems which using ActiveRecord

There is no need to add any middleware, so we can continue to use heroku for free. But the access ranking that depends on both stock count and view count will be handmade. Analytics gems can be used if the ranking only view count.

Probably use these gems.

Smaller and easier to read gem is https://github.com/patorash/acts_as_footprintable.

My opinion

I think that both search engines and async/scheduled processing are necessary for this type of application. So finally we need to install elasticsearch and redis-server. But at this point the judgment that does not use these is reasonable (because there is demo app work on heroku).

Which way is better to implement ranking is almost the same. (if really have to choose it, redis(only ranking) > elasticsearch(only ranking) >>> ActiveRecord)

rutan commented 6 years ago

I agree with that proposal. The popular article page is not useful on my team... :cry:

Potmum is an application that can run on Heroku. So I think it is better to implement it with Redis which has a free plan. ( https://elements.heroku.com/addons/heroku-redis )


On the other hand, I know the environment where there are lots of articles. Therefore, I think that it is necessary to be able to use a search engine as an optional.

* required
    * PostgreSQL
    * Redis <- New!
* optional
    * ElasticSearch, Solr or ... (I have not decided which to use...)