Ignore:
Timestamp:
Sep 5, 2010, 1:25:07 AM (10 years ago)
Author:
teymour
Message:

Presentation des résultats de recherche solr

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpc/trunk/project/apps/frontend/modules/solr/actions/actions.class.php

    r1274 r1317  
    1111class solrActions extends sfActions
    1212{
     13
     14  private function getLink($obj) {
     15    sfProjectConfiguration::getActive()->loadHelpers(array('Url'));
     16    switch(get_class($obj)) {
     17    case 'Intervention':
     18      return url_for('@interventions_seance?seance='.$obj->getSeance()->id).'#inter_'.$obj->getMd5();
     19    case 'QuestionEcrite':
     20      return url_for('@question_numero?numero='.$obj->numero);
     21    case 'Amendement':
     22      return url_for('@amendement?loi='.$obj->loi.'&numero='.$obj->numero);
     23    case 'Parlementaire':
     24      return url_for('@parlementaire?slug='.$obj->slug);
     25    case 'Commentaire':
     26      return $obj->lien;
     27    }
     28  }
     29  private function getPersonne($obj) {
     30    sfProjectConfiguration::getActive()->loadHelpers(array('Url'));
     31    switch(get_class($obj)) {
     32    case 'Intervention':
     33      return $obj->getIntervenant()->getNom();
     34    case 'QuestionEcrite':
     35      return $obj->getParlementaire()->getNom();
     36    case 'Amendement':
     37      return '';
     38    case 'Parlementaire':
     39      return '';
     40    case 'Commentaire':
     41      return $obj->getCitoyen()->getLogin();
     42    }
     43  }
     44  private function getPhoto($obj) {
     45    sfProjectConfiguration::getActive()->loadHelpers(array('Url'));
     46    switch(get_class($obj)) {
     47    case 'Intervention':
     48      if ($obj->getParlementaire())
     49        return url_for('@resized_photo_parlementaire?height=70&slug='.$obj->getIntervenant()->getSlug());
     50      return '';
     51    case 'QuestionEcrite':
     52      return url_for('@resized_photo_parlementaire?height=70&slug='.$obj->getParlementaire()->getSlug());
     53    case 'Amendement':
     54      return '';
     55    case 'Parlementaire':
     56      return url_for('@resized_photo_parlementaire?height=70&slug='.$obj->getSlug());
     57    case 'Commentaire':
     58      return url_for('@photo_citoyen?slug='.$obj->getCitoyen()->getSlug());
     59    }
     60  }
    1361 /**
    1462  * Executes index action
     
    4896    $s = new SolrConnector();
    4997    $params = array('hl'=>'true', 'fl' => 'id,object_id,object_name', 'hl.fragsize'=>500, "facet"=>"true", "facet.field"=>array("object_name","tag"), "facet.date" => "date", "facet.date.start"=>"2007-05-01T00:00:00Z", "facet.date.end"=>"NOW", "facet.date.gap"=>"+1MONTH", 'fq' => $fq);
     98    $this->sort_type = 'pertinence';
     99    if ($request->getParameter('sort')) {
     100      $params['sort'] = "date desc";
     101      $this->sort_type = 'date';
     102    }
    50103    if ($date = $request->getParameter('date')) {
    51104      $dates = explode(',', $date);
     
    65118    for($i = 0 ; $i < count($this->results['docs']) ; $i++) {
    66119      $res = $this->results['docs'][$i];
    67       $this->results['docs'][$i]['highlighting'] = implode('...', $results['highlighting'][$res['id']]['text']);
    68       //      $this->results['docs'][$i]['object'] = Doctrine::getTable($res['object_name'])->find($res['object_id']);
     120      $obj = Doctrine::getTable($res['object_name'])->find($res['object_id']);
     121      $this->results['docs'][$i]['link'] = $this->getLink($obj);
     122      $this->results['docs'][$i]['photo'] = $this->getPhoto($obj);
     123      $this->results['docs'][$i]['titre'] = $obj->getTitre();
     124      $this->results['docs'][$i]['personne'] = $this->getPersonne($obj);
     125      $this->results['docs'][$i]['highlighting'] = preg_replace('/^'.$this->results['docs'][$i]['personne'].'/', '', implode('...', $results['highlighting'][$res['id']]['text']));
     126     
    69127    }
    70128    $this->results['end'] = $deb + $nb;
     
    75133
    76134    //Prépare les facets
     135    $this->facet['parlementaire']['prefix'] = 'parlementaire=';
     136    $this->facet['parlementaire']['facet_field'] = 'tag';
     137    $this->facet['parlementaire']['name'] = 'Parlementaire';
     138
    77139    $this->facet['type']['prefix'] = '';
    78140    $this->facet['type']['facet_field'] = 'object_name';
     
    84146    $this->facet['tag']['facet_field'] = 'tag';
    85147    $this->facet['tag']['name'] = 'Tags';
    86     $this->facet['parlementaire']['prefix'] = 'parlementaire=';
    87     $this->facet['parlementaire']['facet_field'] = 'tag';
    88     $this->facet['parlementaire']['name'] = 'Parlementaire';
    89148    foreach($tags as $tag => $nb ) {
    90149      if (!$nb)
     
    96155      }
    97156    }
    98     if ($results['response']['numFound']) {
     157    if (!$results['response']['numFound']) {
     158      $this->setTemplate('noresults');
     159    }else{
    99160      $this->fdates = array();
    100161      $this->fdates['max'] = 1;
Note: See TracChangeset for help on using the changeset viewer.