TIP_Boss1

Introduction

A content module managing Yahoo BOSS searches

Source file
/Type/module/content/boss1.php
Extends
TIP_Content

A TIP_Content implementation that sets a default data engine capable to directly parse Yahoo BOSS XML responses (version 1).

To be able to use this module, you must sign up to yahoo and get a BOSS application ID:

http://developer.yahoo.com/

This is a required option. When done, you can easily build a search module by providing the following values in the configuration options:

 $cfg = array(
     ...
     'search'   => array(
         'type' => array('module', 'content', 'boss1'),
         'data' => '...'
     )
     ...
 );

putting your newly BOSS application ID in 'data'. Alternatively you can directly specify an URI as data, leaving the {terms} tag where you want the terms to be substituted. This means the following options is roughly equivalent (if the Yahoo URI does not change) to the previous ones:

 $cfg = array(
     ...
     'search'   => array(
         'type' => array('module', 'content', 'boss1'),
         'data' => 'http://boss.yahooapis.com/ysearch/web/v1/{terms}?appid=...&format=xml&abstract=long'
     )
     ...
 );

After configuring it, you can use your newly "search" module in the same way a common TIP_Content module is used.

First of all, you need to implement a search form that calls the "browse" action of this search module. In the following, a really basic example using the TIP_RcbtNg template engine:

 <form id="idSearch" action="{actionUri(browse,,module=search)}" method="post">
   <fieldset>
     <legend>Search on this domain</legend>
     <label for="terms">Terms:</label>
     <input type="text" name="terms" id="terms" value="{(post[terms])}" />
     <input value="Search" type="submit" />
   </fieldset>
 </form>

To be able to access the responses, TIP_Boss1 considers any <result> in the XML as any SQL engine treats a row in a table. The field of this virtual row are mapped to a usable field id using the "fields_xpath" property of the TIP_XML engine. Here it is a list of these virtual fields with their own XPath used to map them:

Adding new field mappings is trivial: actually, I mapped the fields I'm using.

The above fields can be used in you templates just as every other field provided by the more usual TIP_Mysql engine, just remember to use tags in the browse template of the search module. For instance, to show the search result as a simple list of the above module, you can save the following snippet in style/search/browse.rcbt:

 <h1>Search results</h1>
 <ul class="search">{forSelect()}
   <li>
     <strong>{raw(title)}</strong>
     <div>{raw(summary)}</div>
     <a href="{raw(clickurl)}">{raw(url)}</a>
   </li>{}
 </ul>

Because TIP_Boss1 accesses the responses using the TIP_XML data engine there are some known restriction: for instance, you can't do a complex SQL query using the ORDER BY or GROUP BY clauses. For common usage, I think it was not worth the effort for a full-fledged SQL parser. Check the TIP_XML documentation to exactly know which queries can be executed.

Methods

checkOptions (&$options)

&$options
lines
130 - 171
static
yes
access
protected

__construct ($options)

Constructor

$options
array
Properties values
lines
180 - 183
access
protected

Initializes a TIP_Boss1 instance.

actionBrowse (&$conditions) : bool

Perform a browse action

&$conditions
array
The browse conditions
lines
196 - 207
access
protected

Overrides the "browse" action to substitute {terms} in the query URI.

TIP_Boss1 was last modified by TiP on Mon 25 May 2009 06:22:25 PM CEST
Hosted by BerliOS Developer Logo