rcullito / searchbing

gem to use the bing search api
http://rubygems.org/gems/searchbing
32 stars 12 forks source link

Search results maxed out at 50 #1

Closed DavidVII closed 11 years ago

DavidVII commented 11 years ago

I'm not sure if this is specific to the gem or a limitation of the API. Is there a way to get more than 50 results? I'd preferably like to pull the result count of a query by doing something like bing_results.count and get the total results from bing, not just the first 50.

I'm also curious to know how I would go about gathering the next 50?

I'm rather new to ruby, so pardon me if I'm asking a rather simple question.

rcullito commented 11 years ago

In answer to your first question, for a single request with a basic account the limit is 50.

An explanation for why results are limited to 50 by Alessandro Catorcini, of bing's api team, can be found here: http://www.bing.com/blogs/developer/f/12254/t/647793.aspx

In answer to your second question, it is possible to to obtain the next fifty results by supplying a $skip parameter of 50, which pretty much just functions like an offset.

I just updated the gem to take advantage of this, but if you pull down a fresh copy(0.2.0), you could start counting at 50 by adding an additional parameter to the search method as below:

bing_results = bing_image.search("puffin", 50)

*if you're new to ruby just run 'gem update searchbing' from the command line to update to the latest copy of the gem

DavidVII commented 11 years ago

This is great! Thanks.

I'm curious if there's a way to pull the total number of results. Not the actual results, but the total number:

Here's the number I'm talking about: number

Is that currently possible with the API or Gem?

DavidVII commented 11 years ago

This is a bit dated, but it looks like they removed the total, but added it back in: Link

rcullito commented 11 years ago

As far as I can see neither Totals or Web Totals are present in the metadata that is coming back from bing's api. Hopefully in a future version it will be publicly available.

DavidVII commented 11 years ago

Oh man, really? I just found this where they talk about a WebTotal that you can use either xml or json. Check it out: link. It was posted in April, but perhaps they removed it again?

rcullito commented 11 years ago

I just updated the gem to point to the most recent bing api endpoint referenced in that article. If you pull down 2.1 you can run something like:


    bing_web = Bing.new('your key goes here', 50, 'Web')
    bing_web_results = bing_web.search("your_search_term")
    puts bing_web_results[0]["WebTotal"]

You would specify ImageTotal or VideoTotal if you performed that type of search.

DavidVII commented 11 years ago

Oh sweet! This works wonderfully. I suppose we should close the thread. Thank you so much for taking the time to do this. I really appreciate it.