Integrating Yahoo! BOSS with your ruby on rails application

By manik October 29, 2009

What is Yahoo! BOSS? Yahoo developer website cites it as:

“Yahoo! Search BOSS (Build your Own Search Service) is an initiative in Yahoo! Search to open up Yahoo!’s search infrastructure and enable third parties to build revolutionary search products leveraging their own data, content, technology, social graph, or other assets. This release includes Web, News, and Image Search as well as Spelling Suggestions.”

Some of the possible implementation of Yahoo! Boss may be finding related posts for your article, suggested tag/category for an article/query, correcting misspelled words by providing suggestions, fetching latest news on a topic dynamically, search over delicious tags, customized language search. Some of these have been tried and successfully implemented. An example is the TechCrunch’s Search Engine.

Here is a concise guide on how to use this new service in your next rails application.

Obtain API key

Get an application key from

Install BOSSMan Gem

BOSSMan is a gem for interaction with the Yahoo BOSS web service written by John Pignata. Install it using the following commands:

gem install gemcutter
gem tumble
gem install bossman


Put this in your environment.rb

require 'bossman'
include BOSSMan
BOSSMan.application_id = <Your Application ID>

Web Search

Use the following code to execute search over the web:

boss = Search.web("Apple Pie", { :count => 2, :filter => "-hate" })
puts "Number of results: #{boss.totalhits}"

boss.results.each do |result|
  puts "#{result.title}"
  puts "#{result.dispurl}"
  puts "#{result.abstract}"

# => Number of results: 2618888
# => <b>Apple</b> <b>pie</b> - Wikipedia, the free encyclopedia
# => <b></b>/wiki/<wbr><b>Apple</b>_<b>pie</b>
# => English <b>apple</b> <b>pie</b> recipes go back to the time of Chaucer. <b>...</b> The basis of Dutch <b>apple</b> <b>pie</b> is a crust on the bottom and around the edges. <b>...</b>

boss = Search.web("Moon", { :count => 10, :type => "nonhtml,-pdf" })

boss.results.each do |result|
  puts "#{result.title}"
  puts "#{result.dispurl}"
  puts "#{result.abstract}"

# => www.<b></b>/~rusmart/<wbr><b>moon</b>.doc
# => We noticed was that one of the scan lines took longer to scan the <b>moon</b> then any other. This occurred toward the middle of the <b>moon</b>. <b>...</b>

boss = Search.web("Star", { :sites => "", :style=>'raw' })
boss.results.each do |result|
  puts "#{result.title}"
  puts "#{result.dispurl}"
  puts "#{result.abstract}"

# => John Cena - WWE: Raw
# => www.<b></b>/super<b>star</b>s/raw/<wbr>johncena
# => Official profile from WWE for the professional wrestler John Cena, who has been training since he was 15. Features lots of photos and video clips, including John ...

Apart from universal arguments mentioned at the end of this document, the following arguments can also be used:

Parameters Values/Description
:filter Filter out adult or hate content
Syntax: :filter => "-hate, -porn"
:type Specifies document formats (pdf, msoffice,etc)
:view Syntax: :view => "view1,view2", etc

:view => "keyterms" will retrieve related words and phrases for each search result.

:view => "searchmonkey_feed" will retrieve structured data markup, if available, for the search result in dataRSS format.

:view => "searchmonkey_rdf" will retrieve structured data markup, if available, for the search result in rdf format.

:view => "delicious_toptags" will retrieve the top public delicious tags for a document and the counts associated with each tag

:view => "delicious_saves" will retrieve the number of times a document was saved in delicious

:view => "language" identifies the language of the document

:abstract :abstract => "long" will retrieve and display an abstract of a web document up to 300 characters. This expanded abstract provides the requestor with a larger piece of information to work from in a web search query. The default for abstract is an abbreviated description.

Click here to view list of response fields returned by web search.

Images Search

For searching images on web, use the following code:

boss = Search.images("snow hills", { :dimensions => "large" })

boss.results.each do |result|
  puts "#{result.url}: #{result.abstract}"

# => Copyright © 2004 Chiltern hills east from near Ivinghoe snow habitats landscapes British Isles

Click here for list of additional arguments that can be provided with image search.

Click here to view list of response fields returned by image search.

News Search

Yahoo! BOSS also provides news search capabilties.

boss ="free shipping", { :age => "1d-2w", :orderby => "date", :count => 1})

boss.results.each do |result|
  puts "#{result.title} [from #{result.source}]"
  puts "#{result.abstract}"
# => Wal-Mart announces weekly price cuts for holidays [from USA Today]
# => Wal-Mart said it will cut prices this holiday season for a week at a time on thousands of items, from bananas to board games. The first group of cuts hit Wednesday.

Click here for list of additional arguments that can be provided with news search.

Click here to view list of response fields returned by news search.

Spelling Search

Correct your misspelled words using its spelling suggestion feature:

boss = BOSSMan::Search.spelling("acknowlegment")
puts boss.suggestion # => acknowledgment

Site Explorer

You can also search for the pages from other sites linking into your site pages.

links = Search.se_inlink("", :count => 2) { |result| p result.url }
# =>
# =>

For displays a list of all pages belonging to a domain in the Yahoo! index, use se_pagedata method provided.

links = Search.se_pagedata("", :count => 1) { |result| p "#{result.url} - #{result.abstract}" }
# => - Use Twitter to send status updates (tweets) through your cell phone, instant messenger, or via the Web, and notify friends and followers of the little things <b>...</b>

Universal Arguments for Web, Images and News

Following is the list of most commonly used arguments with web, image and news search. For more comprehensive list click here

Argument Options/Details
:start Ordinal position of first result. First position is 0. Default sets start to 0.
:count Total number of results to return. Maximum value is 50. Default sets count to 10.
:format The data format of the response. Value can be set to either "xml" or "json". Default sets format to "json".
:callback The name of the callback function to wrap the result. Parameter is valid only if format is set to "json". No default value exists.
:sites Restrict BOSS search results to a set of pre-defined sites. Multiple sites must be comma separated. Example: (:sites => ","). The Images service does not yet support multiple sites.
:view Retrieve additional search data provided by the respective BOSS service. Please see individual chapters to see what view options are available.
:style By default for web search result titles and abstracts contain bold HTML tags around the search term. Use :style => "raw" to remove the bold tags around the search terms in titles and abstracts.
Share this:

Leave a comment

Your email address will not be published. Required fields are marked *


  1. Pingback: Flow » Blog Archive » Daily Digest for October 30th - The zeitgeist daily
  2. Play Videos says:

    Fedora 15 features new versions of Rails, OCaml, and Python. GDB and GCC have also been updated. (Fedora 15 was built with GCC 4.6.0, too!) * Productivity Applications. LibreOffice is filled with tools for everyday use, including word processing, …

  3. Kamagra says:

    Each is a head-turner. Silhouettes are strong, bold and avant garde and
    colours range from ruby-red and peacock blue to her favoured neutrals –