简体   繁体   English

Django处理分页以实现动态顺序

[英]Django handling pagination for dynamic order

I have done to query content and give as next_url, previous_url , etc. Problem is that query is based on dynamic sorting (just like Facebook newsfeed). 我已经完成了对内容的查询,并给出了next_url,previous_url等信息。问题是该查询基于动态排序(就像Facebook新闻源一样)。

How can I handle for following scenario ? 如何处理以下情况?

User request page 1 and see article 10242. User haven't request page 2 yet. 用户请求页面1,请参阅文章10242。用户尚未请求页面2。 Due to sorting algorithm, article 10242 will potentially moved to page 2. If so, when user request page 2, user will see duplicate post. 由于排序算法的原因,商品10242可能会移至第2页。如果是这样,当用户请求第2页时,用户将看到重复的帖子。

I can't simply delete duplicate post on app. 我不能简单地删除应用上的重复帖子。 It will be okay for duplicate issue but let say when user request page 1, article 10333 is in page 2 but when user request page 2, article 10333 moves to page 1. Is there any recommended mechanism for pagination to support dynamic sorting? 可以解决重复的问题,但是可以说,当用户请求第1页的第10333条位于第2页时,但是当用户请求第2页的第10333条移至第1页时,是否有建议的分页机制来支持动态排序?

Few suggestions: 几点建议:

  1. Change the algorithm to hold a dirty parameter. 更改算法以保留dirty参数。 Anytime someone likes it or changes are made, it becomes dirty and the sorting algorithm can be changed to factor it in. I used couple of search db's (elasticsearch and algolia) that allowed me to customize sorting order based on various parameters. 每当有人喜欢它或进行更改时,它都会变得dirty并且可以将排序算法更改为因素。我使用了几个搜索数据库(elasticsearch和algolia),这些数据库使我可以基于各种参数来自定义排序顺序。 Alongwith this change, you need a user state of what has been viewed and what can be viewed and use it as a filter. 伴随此更改,您需要用户已查看的内容和可以查看的内容的状态,并将其用作过滤器。
    Here is a nice paper where facebook discusses some of its approaches. 是一篇不错的论文,facebook在其中讨论了一些方法。

  2. A simpler approach would be to hold the information of what has been viewed by a user and when the user tries to fetch information filter/demote the article. 一种更简单的方法是保存用户查看过的信息以及用户尝试获取信息时过滤/删除商品的信息。 Keeping per user state will take care of the issue where an article might be viewed by one person but not by another. 保持每个用户的状态将解决一个问题,即一个人可能看到该文章,而另一个人却看不到。
    I personally like nosql databases or something like redis/memcached for such state information 我个人喜欢nosql数据库或类似redis / memcached这样的状态信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM