/**
  * Check for mispelled terms
  * 
  * @param Query $query
  * @return Suggestion
  */
 protected function checkSpelling()
 {
     // advanced search?  no thanks!
     if ($this->request->getParam('advanced') != null) {
         return new Suggestion();
     }
     $id = $this->query->getHash();
     // have we checked it already?
     $suggestion = $this->request->getSessionData("spelling_{$id}");
     if ($suggestion == null) {
         $suggestion = $this->query->checkSpelling();
         // check it
         $this->request->setSessionData("spelling_{$id}", serialize($suggestion));
         // save for later
     } else {
         $suggestion = unserialize($suggestion);
         // resurrect it, like shane
     }
     return $suggestion;
 }
Example #2
0
 /**
  * Add links to the query object limits
  * 
  * @param Query $query
  */
 public function addQueryLinks(Query $query)
 {
     // we have to pass in the query object here rather than take
     // the property above because adding the links doesn't seem
     // to reflect back in the main object, even though they should
     // be references, maybe because limit objects are in an array?
     // search option links
     $search = $this->registry->getConfig('search');
     if ($search instanceof \SimpleXMLElement) {
         $controller_map = $this->request->getControllerMap();
         foreach ($search->xpath("//option") as $option) {
             // format the number
             // is this the current tab?
             if ($controller_map->getControllerName() == (string) $option["id"] && ($this->request->getParam('source') == (string) $option["source"] || (string) $option["source"] == '')) {
                 $option->addAttribute('current', "1");
             }
             // url
             $params = $query->extractSearchParams();
             $params['controller'] = $controller_map->getUrlAlias((string) $option["id"]);
             $params['action'] = "results";
             $params['source'] = (string) $option["source"];
             $url = $this->request->url_for($params);
             $option->addAttribute('url', $url);
             // cached search hit count?
             foreach ($this->request->getAllSessionData() as $session_id => $session_value) {
                 // does this value in the cache have the save id as our tab?
                 $id = str_replace("_" . $query->getHash(), "", $session_id);
                 if ($id == (string) $option["id"]) {
                     // yup, so add it
                     $option->addAttribute('hits', Parser::number_format($session_value));
                 }
             }
         }
         $this->registry->setConfig('search', $search);
     }
     // links to remove facets
     foreach ($query->getLimits() as $limit) {
         $params = $this->currentParams();
         $params = Parser::removeFromArray($params, $limit->field, $limit->value);
         $limit->remove_url = $this->request->url_for($params);
     }
 }
Example #3
0
 /**
  * Return identifier for this query = search ID + query hash
  * 
  * @return string
  */
 public function getQueryID()
 {
     return $this->id . "_" . $this->query->getHash();
 }