【问题标题】:Is there any reliable way to get the data from PostgreSQL according to the user interest in the Django Rest Framework?根据用户对 Django Rest Framework 的兴趣,有没有可靠的方法从 PostgreSQL 获取数据?
【发布时间】:2022-11-03 18:36:20
【问题描述】:
我们的项目在功能上类似于 Twitter
我们希望根据用户对帖子的点赞、分享和cmets,根据用户的兴趣在Feed上显示帖子
- 我们可以如何以及在哪里保存用户的活动?
- 我们如何使用 Django QuerySet 和 DRF 为用户分页过滤和获取帖子数据
- 我们如何使用最近+兴趣相关的数据对帖子数据进行排序
如果有任何更好的方法存在,那么请分享一些关于它的细节。
提前致谢!
【问题讨论】:
标签:
django
postgresql
django-rest-framework
【解决方案1】:
This is a standard personalization/recommendation use case, and there are a few standard approaches:
Content-based filtering: select posts that are similar to ones the user has interacted with. You can use techniques like TF-IDF to calculate a similarity score between posts.
Collaborative filtering: select posts that people with a similar activity history to the user have interacted with.
Typically you would precalculate recommendation scores in a background job, and store them in a separate table. Then when showing a feed to a user, you just ORDER BY the score column to prioritize recommended posts.
You can combine the two approaches by taking a weighted average of content-based and collaborative scores.
Note that all of this assumes you have a adequate volume of data and activity to make the recommendations useful. For a new site with few users it may be better to just show chronological posts initially.