예제 #1
0
파일: Query.php 프로젝트: navtis/xerxes
 /** 
  * Extract query, limit and target params from the URL 
  * @return array 
  */
 public function getAllSearchParams()
 {
     $lq = parent::getAllSearchParams();
     $lq['target'] = $this->targetnames;
     //Debug::Dump($lq);
     return $lq;
 }
 /**
  * Check spelling, reset search refinements and redirect to results
  * 
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function searchAction()
 {
     // set the url params for where we are gong to redirect,
     // usually to the results action, but can be overriden
     $base = $this->helper->searchRedirectParams();
     $params = $this->query->getAllSearchParams();
     $params = array_merge($base, $params);
     // check spelling
     $this->checkSpelling();
     // remove default values
     foreach ($params as $id => $value) {
         if (strstr($id, 'field')) {
             if ($value == 'keyword') {
                 unset($params[$id]);
             }
         }
     }
     // keep search refinements if user says so
     if ($this->request->getParam('clear-facets') != '') {
         $this->request->setSessionData('clear_facets', $this->request->getParam('clear-facets'));
     }
     // redirect
     return $this->redirectTo($params);
 }
 /**
  * Extract the search params as a url
  * @param Query $query
  */
 protected function getSearchQuery(Query $query)
 {
     $url = '';
     $params = $query->getAllSearchParams();
     foreach ($params as $key => $value) {
         $url .= ';' . $key . '=' . urlencode($value);
     }
     return $url;
 }
예제 #4
0
 /**
  * Add links to facets
  * 
  * @param ResultSet $results
  */
 public function addFacetLinks(ResultSet &$results)
 {
     // facets
     $facets = $results->getFacets();
     if ($facets != "") {
         $group_id = 0;
         foreach ($facets->getGroups() as $group) {
             // this is used for javascript selecting
             $group_id++;
             $facet_id = 0;
             // group identifiers
             $group->group_id = 'facet-' . $group_id;
             $group->param_name = 'facet.' . $group->name;
             // link to multi-select facet page
             $group_params = $this->query->getAllSearchParams();
             $group_params['controller'] = $this->request->getParam('controller');
             $group_params['action'] = 'facet';
             $group_params['group'] = $group->param_name;
             $group->url = $this->request->url_for($group_params);
             // print_r($group->getFacets());
             foreach ($group->getFacets() as $facet) {
                 $facet_id++;
                 $param_name = Query::getParamFromParts($group->name, urlencode($facet->key), $facet->is_excluded);
                 // link
                 $url = $this->facetParams();
                 if ($facet->is_excluded == true) {
                     // selecting this option removes our exclude param
                     foreach ($url as $key => $value) {
                         if ($key == $param_name) {
                             // if we have multiple values, only remove the matching one
                             if (is_array($value)) {
                                 $new_array = array();
                                 foreach ($value as $entry) {
                                     if ($entry != $facet->name) {
                                         $new_array[] = $entry;
                                     }
                                 }
                                 $url[$key] = $new_array;
                             } else {
                                 $url[$key] = '';
                             }
                         }
                     }
                 } else {
                     // selecting this option adds our param
                     $url[$param_name] = $facet->name;
                 }
                 $facet->url = $this->request->url_for($url);
                 // facet identifiers
                 $facet->input_id = $group->group_id . '-' . $facet_id;
                 // add the name of the param as well
                 $facet->param_name = $param_name;
                 // see if this facet is selected (for multi-select facets)
                 if ($this->request->hasParamValue($param_name, $facet->name)) {
                     $facet->selected = true;
                 }
                 // exclude facet param
                 $facet->param_exclude = str_replace('facet.', 'facet.remove.', $param_name);
             }
         }
     }
 }