Есть ли надежный способ получить данные из PostgreSQL в соответствии с интересами пользователя в Django Rest Framework?
Наш проект по функциональности похож на Twitter. Мы хотим показывать посты в ленте в соответствии с интересами пользователя, основываясь на его лайках, акциях и комментариях к постам
- как и где мы можем сохранять действия пользователя?
- как мы можем фильтровать и получать данные постов, используя Django QuerySet и DRF пагинации для пользователя .
- как мы можем сортировать данные постов с помощью недавних + связанных с интересами данных
если существует какой-либо лучший подход, то, пожалуйста, поделитесь некоторыми подробностями о нем.
Заранее спасибо!
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.