문제

I have a program in JAVA that sends an HTTP GET message to Google Books API. I want to get books that answer the search criteria "cooking". The max number of items in a response is 40 and this is the number I set in the GET message.

https://www.googleapis.com/books/v1/volumes?q=cooking&projection=full&startIndex=0&maxResults=40&key=/*My Key*/

In the response I get, the value of "totalItem" is about 450. This looks very wrong because searching in google books GUI or "cooking" yields 5.8 million results.

Any one knows why is it like this?

Second issue: The first request I send asks for results in index 0-39, after that 40-79... up to a 1000. 1000 is the daily limit of the curtesy queries of this API. For some reason each time I get the JSON file, the "totalItem" value is different! always arround 450,
but I see no consistency in there.

Anyone knows something about that?

도움이 되었습니까?

해결책

The totalItems retrieved is infact, openSearch:totalResults. According to openSearch specification,

The "totalResults" element

The number of search results available for the current search.

If the totalResults element does not appear on the page then the search client should consider the current page to be the last page of search results.

Restrictions: The value must be a non-negative integer. Default: The default value is equal to the offset index of the last search result on the current page. Requirements: The element may appear zero or one time.

This is not working for this API though, and if you decrease the maxResults to 1, your totalItems will soar to 590s. Nothing in the google documentation says anything about that explicitly. The closest one I got was at the youtube API documentation

The tag identifies the number of items in the result set for the feed. Please note that the tag value is an approximation and may not represent an exact value. In addition, the maximum value for this tag is 1,000,000. You should not use this value to create pagination links.

Did you need totalItems for pagination?

다른 팁

To answer your first question on the search results between books api and books GUI, see the following thread. Has to do with content and metadata in GUI search and just metadata in api.

http://www.google.com/support/forum/p/booksearch-apis/thread?tid=38628f43b3bf6ee4&hl=en

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top