自适应网站 seo怎么做,建材网站建设案例,wordpress显示全英文版,网站开发 前端vue 后端c有时我们需要随机地获取数据记录#xff08;实体#xff09;#xff0c;比如博客程序中的“随机文章”的实现。 目前 GAE 并没有 API 可以直接获取随机实体#xff0c;要实现这样的需求我们只能自己想办法了 :-) 在 stackoverflow 上也有人提过该问题#xff0c;总结如下实体比如博客程序中的“随机文章”的实现。 目前 GAE 并没有 API 可以直接获取随机实体要实现这样的需求我们只能自己想办法了 :-) 在 stackoverflow 上也有人提过该问题总结如下 Generate and store a random number on your entities as you create them, then pick a random number and look (via a query) for the closet record(s) to it.Implement some mechanism to ensure your entity ids are densely populated, then fetch within the known range using keys.Periodically generate random lists of the entities and return entities from those lists. This may take the form of a stack that entities are popped off of, or as actual lists that are returned. 目前 B3log Solo 在处理“随机阅读”上采用的是方法一即在每个文章实体上添加一个属性保存 0-1 的随机浮点数。 在获取随机文章时生成一个 0-1 的随机数mid作为查询条件以此查询条件作为边界0 mid 1来过滤实体保存的随机值属性。 这个方法基本可以达到随机的效果了为了让随机的效果更动态一点我们可以考虑经常更新文章实体中的随机浮点值 访问文章时即在更新文章浏览次数时一并更新该文章的随机浮点值后台定时任务获取一定数量的随机文章然后更新它们的随机浮点值用户做文章更新时加上以上处理后随机的效果比较好了 :-)本文是使用 B3log Solo 从 简约设计の艺术 进行同步发布的原文地址http://88250.b3log.org/get-gae-random-entities.html 转载于:https://www.cnblogs.com/lanzhi/archive/2011/01/10/6468264.html