如果我应该通过其他方法解决这个问题,请提出建议。我正在创建一个基于项目的协作过滤器。我使用LinkRating2类填充数据库,对于每个链接,我需要调用超过1000个用户并收集他们的评级以执行计算,然后我用它来创建另一个表。所以我需要为给定的链接调用1000多个实体。
例如,假设超过1000个用户被评为“link1”,那么我需要调用的给定链接属性将超过1000个此类实例。
我将如何完成这个例子?
class LinkRating2(db.Model):
user = db.StringProperty()
link = db.StringProperty()
rating2 = db.FloatProperty()
query =LinkRating2.all()
link1 = 'link string name'
a = query.filter('link = ', link1)
aa = a.fetch(1000)##how would i get more than 1000 for a given link1 as shown?
##keybased over 1000 in other post example i need method for a subset though not key
class MyModel(db.Expando):
@classmethod
def count_all(cls):
"""
Count *all* of the rows (without maxing out at 1000)
"""
count = 0
query = cls.all().order('__key__')
while count % 1000 == 0:
current_count = query.count()
if current_count == 0:
break
count += current_count
if current_count == 1000:
last_key = query.fetch(1, 999)[0].key()
query = query.filter('__key__ > ', last_key)
return count
答案 0 :(得分:1)
Wooble指出1,000实体限制现在已成为过去,因此您实际上不需要使用游标来执行此操作 - 只需一次获取所有内容(它比获取1,000实体更快)批量也是因为数据存储的往返次数会减少等等。)
在版本1.3.1中移除了1000实体限制:http://googleappengine.blogspot.com/2010/02/app-engine-sdk-131-including-major.html
使用游标的旧解决方案:
使用query cursors获取超过前1,000个实体的结果:
# continuing from your code ... get ALL of the query's results:
more = aa
while len(more) == 1000:
a.with_cusor(a.cursor()) # start the query where we left off
more = a.fetch(1000) # get the next 1000 results
aa = aa + more # copy the additional results into aa
答案 1 :(得分:1)
最近删除了1000个实体的获取限制;如果您可以在限定时间内完成,则可以根据需要获取。您的实体看起来很小,因此您可以在请求中获取超过1000个。