An Ajax Based Yahoo Suggest and Search Portlet

Recently I got to try the Yahoo Search API . Yahoo offer many REST based service APIs which could be consumed for web-applications. Tried to develop a JSR 286 portlet (Portlet spec v2.0) that uses Ajax and serveResource feature of JSR286 specification to make aysnchronous API calls to the portlet which in turn makes calls the Yahoo REST services through Apache HttpClient. Since the result of the REST calls are JSON based, it is not difficult to extrace the suggest or search results.

From the Portlet Perspective, the XMLHttpRequest from the VIEW Jsp sends a resourceURL with the search keywords as the input parameters to the portlet.The portlet implements the ResourceServingPortlet interface, and thus implements the abstract method serveResource, in which calls to the REST services are made. The response type is set as 'application/json' and the resultant JSON object is embedded in the resourceResponse. The onReadyStateChange action handler of the JSP processes this JSON response and displays the search results.

To the end user, the portlet offers a search box, which offers suggestions as the user keys down letters, (with each keypress, aysnchronous REST calls are made to the yahoo related search API  and the resultant suggestions are displayed as a dropdown and when the Search button is pressed with a specific user-entered or user-selected keyword, aynschronous calls are made to retrieve the search results similar to the previous case. 

Though this portlet was initially a product of academic interest, it could be further developed to adapt to Google and other custom search engines, which Im currently trying to enhance.  The pre-requisites are a Portlet V 2.0 portlet container (Sun's OSPC 2.0 could be used) and Apache HttpClient.

 This portlet is available for download and use here

 

 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

nitkal

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks