Posts Tagged ‘rails’

Integrating Yahoo! BOSS with your rails application

Thursday, October 29th, 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 http://developer.yahoo.com/search/boss/.

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

Usage

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}"
end

# => Number of results: 2618888
# => <b>Apple</b> <b>pie</b> - Wikipedia, the free encyclopedia
# => <b>en.wikipedia.org</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}"
end

# => BACKGROUND:
# => www.<b>radford.edu</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 => "wwe.com", :style=>'raw' })
boss.results.each do |result|
  puts "#{result.title}"
  puts "#{result.dispurl}"
  puts "#{result.abstract}"
end

# => John Cena - WWE: Raw
# => www.<b>wwe.com</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}"
end

# => http://www.amanita-photolibrary.co.uk/photo_library/BI_habitats/gb96_chiltern_hills_from_ivinghoe_snow_std.jpg: 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 = BOSSMan::Search.news("free shipping", { :age => "1d-2w", :orderby => "date", :count => 1})

boss.results.each do |result|
  puts "#{result.title} [from #{result.source}]"
  puts "#{result.abstract}"
end
# => 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("http://mail.yahoo.com", :count => 2)
links.results.map { |result| p result.url }
# => http://www.aol.com/
# => http://groups.yahoo.com/

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

links = Search.se_pagedata("twitter.com", :count => 1)
links.results.map { |result| p "#{result.url} - #{result.abstract}" }
# => http://twitter.com/ - 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 => "abc.com,cnn.com"). 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.

Open Maturity Model – Let’s share Best Practices without auditors or certifications

Sunday, February 15th, 2009

Nothing to do with OSMM (open source maturity model). There is some discussion  going in  rails community for  Obie Fernandez post on idea of Rails Maturity Model.

I like the basic idea behind defining some sort of maturity model for rails but I don’t think RMM or anything like that should be modeled on CMM.

After spending  hours looking at views of many people regarding RMM in blogosphere, twitter and rails business google group , I concluded  that we might need some open system instead of something like RMM.

Following is an aggregation of views by various people who feel the need of a some model but dont like the idea of auditors, closed systems or certifications :

For time being , I am calling it Open Maturity Model and trying to draft some  basic principles and guidelines.

So, What is Open Maturity Model ?

For Developers

1. Roadmap for Rails developers to adopt best practices defined by the community.

2. Community giving newcomers a more-or-less official set of guidelines for how to produce quality work. Having some sort of guideline from a trustworthy source is becoming more difficult.

3. It will not take fun out of rails or kills innovation. It will just make the rails community stronger and will attract more people who are not yet sure about rails.

4. Judge yourself , instead of an expensive auditor judging you – if you are serious about doing quality work, open maturity model will give you a good point to start with.

5.  Let experienced developers share their experience on a common wiki in addition to blog posts about their experiences all on their own.

For Clients

1. A no nonsense, no lingo system to help a prospective client to choose a ROR shop. Give them more than just testimonials , a blog post, or a portfolio. The intent is to establish a minimum standard of operational efficiency so that clients who hire based on it can be sure they aren’t dealing with complete idiots.

2. Let’s share Business Knowledge – most development shops are busy coding and spend little to no effort on marketing or business development. Groups like rails business is a good start in this direction.

For Process

1. XP , SCRUM or whatever. One size doesnt fit all. At Vinsol, we follow a process which has evolved after lot of not-so-successful iterations. It works for us and we want to improve and share it with community. But we don’t want to call our process or anybody else’s practice “The Rails Way”. Again , a community website  where companies can register and document the level of process they implement allowing for clients and other companies to provide feedback so they could get ranked.

2. Instead of wasting resources proving that we are level 4 or level 5 by an external auditor, lets just focus on why we are in the business – writing good quality code, having fun doing it and building awesome applications.

3. Continous improvement is very important for growth and survival of many rails companies with thousands of rails shops opening around the world.

Certifications

1. Replace open source projects with certification – open source can play the role of  certification.  Have you ever contributed or tried to contribute  to rails core ? or, show us an interesting/useful open source project you started, or point to bugs that you submitted.

Looking for ideas and suggestions.

Update :  Matthew Ford has started a rails manifesto document in github. Please add your best practices here – http://gist.github.com/65183