Online Server Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 19 March 2007

Using AJAX Search to integrate search results into your site

Posted on 21:03 by Unknown
Posted by Dion Almaer, Google Developer Programs

We are very fortunate at Google to have amazing people come in to speak to us on many interesting topics. We record these talks and make them available on Google Video.

We recently added a feature on the Google Code website that displays recent videos from our tech talk series.

You could do this directly using the Video Bar or the Video Search Control which have wizards to make implementation trivial.

In our case, we wanted to make the bottom right portlet fit in with the look and feel of the rest of the site, so we decided to go a little more low level.

The the AJAX Search API the actually act of searching happens in the Searchers set of JavaScript classes. We used the GvideoSearch class which extends the base GSearch functionality to work with Google Video.

The resulting code was simple. At its heart we:
  • Told the searcher to give us the most recent searches via videoSearch.setResultOrder(GSearch.ORDER_BY_DATE) (as opposed to the default 'most relevant' setting)
  • Told the searcher that we would handle generating the HTML ourselves via videoSearch.setNoHtmlGeneration()
  • Do the work of creating the HTML from the results after the results come back. We track this with videoSearch.setSearchCompleteCallback()
When the search returns the results are put into a results[] array. These results are GvideoResult JavaScript objects with properties that we can then query, such as the published date, content snippet, title, duration, video URL, and the thumbnail image.

We used this to dynamically create the HTML and then inserted it into the DOM with innerHTML.

var result = videoSearch.results[x];
var nicerDate = new Date();
nicerDate.setTime(Date.parse(result.published ));

var dateFormatted = (nicerDate.getMonth()+1) + '/' + nicerDate.getDate()
+ '/' + nicerDate.getFullYear();

output += '<div class="featured"><div class="project"><div '
+ 'class="screenshot"><a href="' + result.url
+ '" rel="nofollow"><img src="' + result.tbUrl + '" alt="'
+ result.titleNoFormatting + ' Screenshot" width="129" height="110" '
+ '/></a></div><div class="info"><div '
+ 'class="name"><a href="' + result.url + '" rel="nofollow">'
+ result.titleNoFormatting + '</a></div><div '
+ 'class="author videodateformat">Recorded on ' + dateFormatted
+ '</div><div class="duration">Duration: '
+ parseInt( result.duration / 60) + ' mins</div></div><p '
+ 'class="videosnippet">' + result.content
+ '</p></div></div>';

A bit ugly, I know. If we wanted a cleaner approach, we could have used DOM methods directly, or we could have created this using a JavaScript Template package.

What is important to know, is that the AJAX Search API is a powerful beast. On the one hand you can run a wizard and get results that you can copy and paste onto your web pages. On the other hand you can get low level and query the backend which returns simple JSON for you to manipulate.

The AJAX Search team seems to release something new on just about a weekly basis, so subscribe to the Google AJAX Search API Blog to follow along.
Email ThisBlogThis!Share to XShare to Facebook
Posted in ajax search, howto | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Google Summer of Code & Danish Linux Forum
    Posted by Leslie Hawthorn, Open Source Team The Danish Linux Conference is celebrating its tenth anniversary this year, and the date is com...
  • Weekly Google Code Roundup for July 2-6th
    By Dion Almaer, Google Developer Programs Having the July 4th holiday smack in the middle of the week creates a strange week when it is hard...
  • Weekly Google Code Roundup for June 11-15th
    By Dion Almaer, Google Developer Programs In API and developer-product news... I will start by going meta. Linking to a roundup from a round...
  • Weekly Google Code Roundup for July 16-20th
    By Dion Almaer, Google Developer Programs This week we have the pleasure of having MashupCamp hosted walking distance from the Googleplex. I...
  • Weekly Google Code Roundup for July 23-27th
    By Dion Almaer, Google Developer Programs It has been a busy time for conferences. From MashupCamp last week, to OSCON and The Ajax Experien...
  • Google Gadget Ventures
    By Tom Stocky, Google Developer Programs Good news for Google Gadget developers. We've just launched Google Gadget Ventures , a new pil...
  • Weekly Google Code Roundup for July 8-12th
    By Dion Almaer, Google Developer Programs In API and developer-product news... Othman Laraki talked about the Gears roadmap and development ...
  • Google Developer Day sessions move to San Jose Convention Center
    Posted by Andrew Bowers, Google Developer Programs Thanks to the incredible interest in Google Developer Day, we've moved the session po...
  • Google Sitemaps Launches
    Today, Google launched Google Sitemaps , a new service designed for webmasters that enables them to automatically submit their web pages to ...
  • Google Developer Podcast Episode Four: Mark Limber on Google SketchUp
    By Dion Almaer, Google Developer Programs Using iTunes? We have published the fourth episode of the Google Developer Podcast, which feature...

Categories

  • 20% project
  • 3d
  • accessibility
  • advogato
  • ajax
  • ajax search
  • ajax search books news apis
  • amarok
  • android
  • apache
  • apis
  • apis. charts
  • apple
  • atom publishing protocol
  • axsjax
  • barcodes
  • blogger
  • building ajax apps
  • c++
  • caja
  • calendar
  • camino
  • chronoscope
  • cifs
  • cms
  • collada
  • community
  • conferences
  • cricket
  • cryptography
  • danish linux forum
  • developer
  • django
  • documentation
  • dojo
  • dot net
  • dreamweaver
  • drupal
  • eclipse
  • eclipsecon
  • education
  • email
  • events
  • feeds
  • firevox
  • fosdem
  • freebsd
  • freenet
  • gadgets
  • gcc
  • gdata
  • gdd07
  • geoserver
  • getpaid
  • ghop
  • gnome
  • gnome women's summer outreach program
  • Google
  • google apps for your domain
  • google chart api
  • google checkout
  • google code
  • google code project hosting
  • google code search
  • google data apis
  • google developer day
  • google earth
  • google gadgets
  • google gears
  • google grants
  • google mashup editor
  • google summer of code
  • google web toolkit
  • green linux
  • gsoc
  • gtags
  • guice
  • GWSOP
  • gwt
  • haproxy
  • hibernate
  • howto
  • hpux
  • html
  • html5
  • igoogle
  • image search
  • Imara
  • interviews
  • java
  • javascript
  • joomla
  • joomladayus2007
  • joomladayusa
  • karaoke
  • KDE
  • KDE 4.0
  • kernel
  • kernel summit
  • kml
  • linux
  • linux foundation
  • linux summit
  • linux virtual server
  • linuxconf eu
  • LoCo
  • london
  • mac
  • MacFuse
  • maps
  • meetup
  • MIT CSAIL
  • mobile
  • mylar
  • MySQL
  • mythtv
  • named
  • netbsd
  • nss
  • objective-c
  • OCaml
  • ocr
  • ODF
  • oha
  • OOXML
  • open source
  • openajax alliance
  • opensocial
  • openssl
  • oreilly
  • oscon
  • oscon2007
  • oss devs
  • ossjam
  • osx
  • pactester
  • phone
  • picasa
  • picasa web
  • plone
  • plone sprint
  • podcast
  • portugal
  • programming
  • py3k
  • python
  • python sprint
  • reader
  • research
  • samba
  • scalability
  • screencast
  • security
  • shindig
  • silverstripe
  • sitemaps
  • sixapart
  • sketchup
  • soc
  • solaris
  • spa2007
  • speakers
  • standards
  • student programs
  • subversion
  • summer of code
  • syndication
  • testing
  • themes
  • topp
  • ubucon
  • ubuntu
  • unit test
  • unix
  • video
  • Vim
  • weekly roundup
  • windows
  • windows programming
  • Winter of Code
  • youtube
  • zurich
  • ZXing

Blog Archive

  • ►  2008 (7)
    • ►  January (7)
  • ▼  2007 (159)
    • ►  December (8)
    • ►  November (13)
    • ►  October (16)
    • ►  September (11)
    • ►  August (16)
    • ►  July (11)
    • ►  June (14)
    • ►  May (13)
    • ►  April (12)
    • ▼  March (19)
      • Interview with Ian Hickson on X/HTML 5
      • Google Summer of Code 2007: Student Applications A...
      • Four Google open source tools on Google Code
      • Class projects and science on Google Code
      • Joining the OpenAjax Alliance
      • Findings from research on release management
      • Open Source Developers @ Google Speaker Series: Je...
      • GData for Picasa Web Albums
      • Ode to Hibernate
      • Using AJAX Search to integrate search results into...
      • Now Accepting Student Applications for Google Summ...
      • World Cup Cricket 2007: Don't pray for rain
      • Google Hosts C++ Standards Meeting
      • Guice, Google's internal Java dependency injection...
      • Google Summer of Code: Mentors apply now!
      • Scalability counts
      • Google APIS at SPA 2007
      • Google gtags version 1.0
      • Mark Lucovsky interview on the AJAX Search API and...
    • ►  February (14)
    • ►  January (12)
  • ►  2006 (98)
    • ►  December (10)
    • ►  November (14)
    • ►  October (13)
    • ►  September (11)
    • ►  August (14)
    • ►  July (9)
    • ►  June (5)
    • ►  May (5)
    • ►  April (6)
    • ►  March (4)
    • ►  February (2)
    • ►  January (5)
  • ►  2005 (40)
    • ►  December (4)
    • ►  November (1)
    • ►  October (3)
    • ►  September (2)
    • ►  August (5)
    • ►  July (3)
    • ►  June (11)
    • ►  May (2)
    • ►  April (4)
    • ►  March (5)
Powered by Blogger.

About Me

Unknown
View my complete profile