Thursday, August 20, 2009

How can you tell if you're on the last page of results?

Question:

When using XML results, what's the trick to figuring out if you're on
the last page of results?

Say I ask the Mini for results using Start=1, Number=10, and say I get
exactly 10 results back. How can I know if this is the last page or
if there's another one behind it?

If I get, say, seven results back, then I know this is the last page
(and I hide my "Next" link). But if there's only 10 results, and I
get them all back, and really have no way of knowing if there are more
results behind this one.

I know that the Mini gives you back an estimating number of results in
the XML response, but Google goes to great pains to tell you not to
depend on this number for filtering. It's never right anyway (if it
says there are 10,000 results, and I give it a Start param of 9,999,
I'll never get anything back).

Answer:
There are ways to find previous and last page. the following tags gives you those details:

/GSP/RES/NB/PU == Previous page URL
/GSP/RES/NB/NU == Next page URL

If NU is empty, you're on the last page!