Beispiel #1
0
 /**
  * 
  * @return \Library\ManagerBundle\Libraries\ResultSet 
  */
 public function getSearchResults()
 {
     $url = $this->_getBaseUrl() . $this->_query->encode();
     $results = array();
     if ($url !== $this->_getBaseUrl()) {
         $cacheFile = __DIR__ . '/../../../../app/cache/' . $this->_config['search_cache']['directory'] . '/' . md5($url);
         if ($this->_isCached($cacheFile)) {
             $results = $this->_getFromCache($cacheFile);
         } else {
             $results = (array) array_unique($this->_getParser()->parse($this->_curl->getPage($url)), SORT_REGULAR);
             $this->_cache($results, $cacheFile);
         }
         $resultSet = new ResultSet(count($results) > 0);
     } else {
         $resultSet = new ResultSet(false);
     }
     return $resultSet->setResults((array) $results);
 }
Beispiel #2
0
 /**
  * @test 
  */
 public function encodeWithLanguageAndQuery()
 {
     $this->_query->setQuery('q', 'symfony')->setLanguage('label:', 'PHP');
     $this->assertEquals('q=label%3APHP+symfony', $this->_query->encode());
 }
Beispiel #3
0
 /**
  * @test 
  * @dataProvider queryParamsProvider
  */
 public function setParamsAndEncodeQuery($langParam, $lang, $queryParam, $query, $expected)
 {
     $this->_query->setLanguage($langParam, $lang)->setQuery($queryParam, $query);
     $this->assertEquals($expected, $this->_query->encode());
 }
Beispiel #4
0
 /**
  * @test
  */
 public function getQuery()
 {
     $query = new Query();
     $query->setLanguage('language', 'php')->setQuery('q', 'mock-query-123456');
     $this->assertEquals($query, $this->_manager->getQuery());
 }
Beispiel #5
0
 /**
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  * @param \Library\ManagerBundle\Interfaces\UrlParamsMapper $urlParamsMapper
  * @return \Library\ManagerBundle\Libraries\Query 
  */
 public function decorate(Request $request, UrlParamsMapperInterface $urlParamsMapper)
 {
     $params = array();
     parse_str(urldecode($request->get('query_string')), $params);
     return $this->_query->setQuery($urlParamsMapper->getQueryParamName(), isset($params['query']) ? $params['query'] : '')->setLanguage($urlParamsMapper->getLanguageParamName(), isset($params['lang']) ? $urlParamsMapper->mapLanguage($params['lang']) : '');
 }