Skip to content

Prioritize recent articles in popular articles #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
onk opened this issue Nov 20, 2017 · 1 comment
Open

Prioritize recent articles in popular articles #37

onk opened this issue Nov 20, 2017 · 1 comment

Comments

@onk
Copy link
Contributor

onk commented Nov 20, 2017

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
  • Use Redis sorted set
  • Use Analytics gems which using ActiveRecord

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
Copy link
Owner

rutan commented Nov 21, 2017

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

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...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants