public function indexAction()
 {
     $query = trim($this->getRequest()->getQuery('q', ''));
     $this->view->query = $query;
     if (!empty($query)) {
         $count = 10;
         $page = (int) $this->getRequest()->getQuery('p', 1);
         if ($page < 1) {
             $page = 1;
         }
         // Prepare the common options
         $options = array('market' => 'en-GB');
         // We want web and image search results
         $sources = array('web' => array('count' => $count, 'offset' => $count * ($page - 1)));
         // Adjust the query to only search the noginn.com domain
         $query .= ' site:noginn.com';
         // Perform the search!
         $bing = new Noginn_Service_Bing('__APP_ID__');
         $result = $bing->search($query, $sources, $options);
         $webResults = $result->getSource('web');
         $this->view->webResults = $webResults;
         // Paginate the results
         $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($webResults->getTotal()));
         $paginator->setCurrentPageNumber($page);
         $paginator->setItemCountPerPage($count);
         $this->view->paginator = $paginator;
     }
 }
 public function testWebSourceSearch()
 {
     $this->_bing->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     $searchResult = $this->_bing->search('tom graham', array('web' => array('count' => 10, 'offset' => 0)));
     $this->assertTrue($searchResult->hasSource('web'));
     // Check the source name isn't case sensitive
     $this->assertTrue($searchResult->hasSource('Web'));
     $resultSet = $searchResult->getSource('web');
     $this->assertType('Noginn_Service_Bing_WebResultSet', $resultSet);
     $this->assertEquals(10, count($resultSet));
     $this->assertEquals(25800000, $resultSet->getTotal());
     $this->assertEquals(0, $resultSet->getOffset());
     $this->assertEquals(0, $resultSet->key());
     // Attempt to seek below the lower bound
     try {
         $resultSet->seek(-1);
         $this->fail('Expected OutOfBoundsException not thrown');
     } catch (OutOfBoundsException $e) {
         $this->assertContains('Illegal index', $e->getMessage());
     }
     $resultSet->seek(9);
     // Attempt to seek above the upper bound
     try {
         $resultSet->seek(10);
         $this->fail('Expected OutOfBoundsException not thrown');
     } catch (OutOfBoundsException $e) {
         $this->assertContains('Illegal index', $e->getMessage());
     }
     $resultSet->rewind();
     $this->assertTrue($resultSet->valid());
     $result = $resultSet->current();
     $this->assertEquals('Thomas Graham and Sons', $result->getTitle());
     $this->assertEquals('Stockists of engineering fasteners and steel stock. The site gives information on the range of products and a history of the company.', $result->getDescription());
     $this->assertEquals('http://www.thomas-graham.co.uk/', $result->getUrl());
     $this->assertEquals('http://cc.bingj.com/cache.aspx?q=tom+graham&d=76275785218222&w=608c9417,5ee03831', $result->getCacheUrl());
     $this->assertEquals('www.thomas-graham.co.uk', $result->getDisplayUrl());
     $this->assertEquals('2009-06-21T09:09:36Z', $result->getDateTime());
 }