Search code examples
angularjsgoogle-search-api

Using google search api cursor in angular js app to get all results for google patent search


I want to make a search into google patent using the following URL which is obsolete

https://ajax.googleapis.com/ajax/services/search/patent?v=1.0&q=thumb%20wrestling%20apparatus&userip=192.168.1.102

It gives me limited number of records per page. But at the end of the JSON it also returns the cursor which has start and label keys. So my question is that how can I use that cursor to show all the records in my search. Like if there are 8 pages and each page contains 4 records so I want to show all 32 records on my UI. How can I achieve that? And second question that is there REST APi for google patent search? If yes then how can I search the patent using REST API and how can I get all the records on one page?


Solution

  • It looks like the API is restricted to a maximum of 8 results per request (you can increase your current 4 results to 8 by using the query param rsz=8.

    So I guess the only way to get all results is by performing multiple requests. So if the current page info data is...

    "pages":[
       {"start":"0","label":1},
       {"start":"8","label":2},
       {"start":"16","label":3},
       {"start":"24","label":4},
       {"start":"32","label":5}
    ]
    

    You would make 5 requests chaining the start param start=0, start=8 ... and so on, extracting the results and pushing to an array store. If you're not already I recommend using something like Restangular, as it would make this process much easier.

    Depending on how your UI is set out, it would be nice maybe to do this with some lazy loading as the user is scrolling through the list?