Counting results in Google App Engine GQL query
I am trying to build a search engine in Google App Engine and wants to display the number of results obtained from that search query. I am using fetch() to display few results at a time but dont know how to display 开发者_StackOverflowthe number of results obtained from the search. The count() function has a limit of 1000 only and my results can exceed even 10,00,000. So, if someone know how to do so please suggest me.........
As others have told you, count()
doesn't scale efficiently.
To retrieve more than 1000 entities, despite of what the documentation says, you have to specify an upper limit:
your_model.all().count(100000000)
count function doesn't have a limit. It's description:
count(limit): Returns the number of results this query fetches. count() is somewhat faster than retrieving all of the data by a constant factor, but the running time still grows with the size of the result set. It's best to only use count() in cases where the count is expected to be small, or specify a limit. count() has no maximum limit. If you don't specify a limit, the datastore continues counting until it finishes counting or times out. From: GQL
So, you can use count() for it.
EDIT: You can do it starting from version 1.3.6 (released Aug-17-2010).
Have a look to changelog.
Also this should be helpful: How to fetch more than 1000?
If you still struggle with fetching no more that 1000 than try to iterate over the query fetching 1000 at a time and setting the offset to the next 1000 as explained at previous link.
精彩评论