Web Search Plugin

  • Tags : search, web, yahoo! boss
  • Latest : 0.1
  • Last Updated: 21 February 2010
  • Grails version : 1.1 > *
  • Authors : Tian Bai
1 vote
Dependency :
compile ":web-search:0.1"

Documentation

Summary

Installation

grails install-plugin web-search

Description

Introduction

This plugin is designed to make use of web search services (for now just Yahoo! Boss Search, later also Google and BING) within Grails applications. In order to use this plugin, you must have accounts with the search service providers. These can be obtained free of charge.

To get a Yahoo! Boss App account, register for an app id at http://developer.yahoo.com/search/boss/.

To “Get an App key” you can register a new user or just use your existing Yahoo ID

Step 1: Install Plugin

This plugin is easily installed from the Grails plugin repository.

Issue this command to install:

grails install-plugin web-search

Step 2: Configure Plugin

The plugin creates a file called WebSearchConfig.groovy in grails-app/conf that has the following content:

search{

//change me! yAppID="YOUR APP KEY"

yVertical="web" yUrl="http://boss.yahooapis.com/ysearch/${yVertical}/v1" yUrlParams="?appid=${yAppID}&format=xml&filter=-porn" yEncoding="UTF-8" yMaxResults=1000 // Yahoo BOS will only return1000 results }

The values are pretty self-explanatory, and match with values used by the Search service. Please note that you must enter your Yahoo App key in order to get the plug-in to work.

Step 3: Start your Grails application

Now you can start your grails application with

grails run-app

After the application is running, type “http://localhost:8080/APP_NAME/search” in your browser. Then your can see a simple input field. Give some words for example “grails” and click the button “OK”. Now you can see a list of results from Yahoo! Boss.

Components

The plugin contains one service (for Yahoo Boss, Google and Bing to follow), one controller, one view and one taglib.

• SearchService

This is the core of this plugin. There are two methods, named “ySearch (String query)” and “ySearch (String query, int maxResults)”. The first method returns all the results from Yahoo! Boss Search Service (But there will not be more than 1001 results, because Yahoo! Boss Search Service does not return more than a thousand answers anyhow). The second method accepts other parameter “maxResults”, with it you can limit the number of results. Each item of results is an instance of Class “de.volzinnovation.plugin.web.search.result.YsearchResult”.

• SearchController

There is only one closure in this controller “index”. When you submit a query, the SearchService will be called and the results will be passed to the “index.gsp”. If no query, then go directly to “index.gsp”.

• View

In view “/search/index.gsp” the results from SearchService are listed as like the search results from Google.

• Taglib

To list each result you can use the method “<w: showYResult/>” in “de.volzinnovation.plugin.web.search.taglib.WebSearchTaglib.groovy” which accepts a parameter ”result”. This parameter should be an instance of Class “de.volzinnovation.plugin.web.search.result.YsearchResult”.

Next Steps

• Integration of Google Search Service (via their AJAX API)

• Integration the Bing Search Service (http://www.bing.com/developers)

Other Stuff

• CHANGELOG

0.1 initial release, developed and tested against Grails 1.1

Suggestions or Comments

Feel free to submit questions or comments to the Grails users mailing list. http://grails.org/Mailing+lists

Alternatively you can contact me directly:

Tian Bai (tb at volzinnovation dot com).