![]() |
|
sfYahooBossPlugin - 0.1.2James Charlesworth |
|
The sfYahooBossPlugin allows you to easily integrate web search into your Symfony project.
The sfYahooBossPlugin is licensed under the MIT License.
Install the plugin
$ symfony plugin:install sfYahooBossPlugin $ symfony cc
Be sure that the plugin is activated in config/ProjectConfiguration.class.php
You can eiter set your key each time you instatiate the YahooBoss object: [php] $YahooBoss = new YahoooBoss('API_KEY');
Even better, set the api key in your app.yml file: [plain] all: yahooboss_api_key: your_api_key
Update your action to show the search form and results.
Create the form:
// apps/[APP_NAME]/modules/[MODULE_NAME]/actions/actions.class.php class MyActionActions extends sfActions { /** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new YahooBossForm(); //call the new search action $this->processSearch($request,$this->form); } }
Next, create the processsSearch action:
[php]
//...
protected function processSearch(sfWebRequest $request, sfForm $form)
{
if (!$request->getParameter('search'))
{
$this->boss = array('results'=>null);
$this->csrf_token = null;
return;
}
$this->form = new YahooBossForm();
$this->form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($this->form->isValid())
{
$search = new YahooBoss();
//see http://developer.yahoo.com/search/boss/boss_guide/News_Search.html
//for date ranges
// $search->setAge('100d');
//see http://developer.yahoo.com/search/boss/boss_guide/Web_Search.html#optional_args_web
// for view args
$view = '';//delicious_saves,delicious_toptags,keyterms,searchmonkey_feed
$search->setView($view);
$search->setCount(10); //number of results per page
$search_query = $request->getParameter('search');
$this->query = $search_query['q'];
//the search query
$search->setQuery($this->query);
//limit results to one site
// $search->setSite('seoatl.com');
// $search->setOrderByDate();
if(!isset($search_query['start']))
{
$this->start=0;
} else {
$this->start = $search_query['start'];
}
$search->setStart($this->start); //important for pagination
$this->boss = $search->execute();
$this->csrf_token = $search_query['_csrf_token'];//need to pass csrf token if enabled
}
}