Changeset 1530
- Timestamp:
- Oct 2, 2010, 9:02:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpc/trunk/project/apps/frontend/modules/solr/actions/actions.class.php
r1500 r1530 61 61 if ($tags = $request->getParameter('tag')) { 62 62 foreach(explode(',', $tags) as $tag) { 63 $this->selected['tag'][$tag] = 1;64 $fq .= ' tag:"'.$tag.'"';63 $this->selected['tag'][$tag] = 1; 64 $fq .= ' tag:"'.$tag.'"'; 65 65 } 66 66 } … … 116 116 $this->sort_type = 'date'; 117 117 } 118 if ($from) { 119 $to = $request->getParameter('to', 'NOW'); 120 $query .= ' date:['.$from.' TO '.$to.']'; 121 $params['facet.date.start']=$from; 122 $params['facet.date.end'] = $to; 123 $params['facet.date.gap'] = '+1MONTH'; 124 $this->selected['from'][$from] = $from; 125 $this->selected['to'][$to] = $to; 126 } 118 119 $this->vue = 'par mois'; 120 127 121 if ($date) { 128 122 $this->selected['date'][$date] = $date; 129 if (!$from) { 130 $dates = explode(',', $date); 131 $date = array_pop($dates); 132 $period = 'MONTH'; 133 if (count($dates) == 1) { 134 $period = 'DAY'; 135 $query .= ' date:['.$date.' TO '.$date.']'; 136 } else $query .= ' date:['.$date.' TO '.$date.'+1'.$period.']'; 137 $params['facet.date.start']=$date; 138 $params['facet.date.end'] = $date.'+1'.$period; 139 $params['facet.date.gap'] = '+1DAY'; 140 } 141 } 142 143 $this->date_en_cours = $date; 123 $dates = explode(',', $date); 124 list($from, $to) = $dates; 125 126 $nbjours = round((strtotime($to) - strtotime($from))/(60*60*24)-1); 127 128 $comp_date_from = explode("T", $from); 129 $comp_date_from = explode("-", $comp_date_from[0]); 130 $comp_date_from = mktime(0, 0, 0, $comp_date_from[1] + 1, $comp_date_from[2], $comp_date_from[0]); 131 $comp_date_from = date("Y-m-d", $comp_date_from); 132 133 $period = 'DAY'; 134 $this->vue = 'par jour'; 135 $this->limit = $to; 136 137 // Affichage d'un mois 138 if($comp_date_from.'T00:00:00Z' == $to) { 139 $period = 'DAY'; 140 $this->vue = 'le mois de'; 141 } 142 // Affichage d'une période 143 else if(($nbjours > 90) and ($from != $to)) { 144 $period = 'MONTH'; 145 $this->vue = 'par mois'; 146 } 147 // Affichage d'un jour 148 if($from == $to) { 149 $period = 'DAY'; 150 $this->vue = 'ce jour'; 151 } 152 153 $query .= ' date:['.$from.' TO '.$to.']'; 154 $params['facet.date.start'] = $from; 155 $params['facet.date.end'] = $to; 156 $params['facet.date.gap'] = '+1'.$period; 157 } 158 144 159 $this->start = $params['facet.date.start']; 145 160 $this->end = $params['facet.date.end']; 146 $this->interval = $params['facet.date.gap'];147 161 148 162 try { 149 163 $s = new SolrConnector(); 150 164 $results = $s->search($query, $params, $deb, $nb); 151 }catch(Exception $e) { 165 } 166 catch(Exception $e) { 152 167 $results = array('response' => array('docs' => array(), 'numFound' => 0)); 153 168 $this->getUser()->setFlash('error', 'Désolé, le moteur de recherche est indisponible pour le moment'); 154 169 } 170 155 171 //Reconstitut les résultats 156 172 $this->results = $results['response']; … … 163 179 $this->results['docs'][$i]['personne'] = $obj->getPersonne(); 164 180 if (isset($results['highlighting'][$res['id']]['text'])) { 165 $high_res = array(); 166 foreach($results['highlighting'][$res['id']]['text'] as $h) { 167 $h = preg_replace('/.*=/', '', $h); 168 array_push($high_res, $h); 169 } 170 $this->results['docs'][$i]['highlighting'] = preg_replace('/^'."$this->results['docs'][$i]['personne']".'/', '', implode('...', $high_res)); 171 }else 172 $this->results['docs'][$i]['highlighting'] = ''; 173 } 181 $high_res = array(); 182 foreach($results['highlighting'][$res['id']]['text'] as $h) { 183 $h = preg_replace('/.*=/', '', $h); 184 array_push($high_res, $h); 185 } 186 $this->results['docs'][$i]['highlighting'] = preg_replace('/^'."$this->results['docs'][$i]['personne']".'/', '', implode('...', $high_res)); 187 } 188 else $this->results['docs'][$i]['highlighting'] = ''; 189 } 190 174 191 $this->results['end'] = $deb + $nb; 175 192 $this->results['page'] = $deb/$nb + 1; … … 194 211 $this->facet['tag']['name'] = 'Tags'; 195 212 foreach($tags as $tag => $nb ) { 196 if (!$nb) 197 continue; 198 if (!preg_match('/=/', $tag)) 199 $this->facet['tag']['values'][$tag] = $nb; 200 if (preg_match('/^parlementaire=(.*)/', $tag, $matches)) { 201 $this->facet['parlementaire']['values'][$matches[1]] = $nb; 202 } 203 } 204 } 213 if (!$nb) 214 continue; 215 if (!preg_match('/=/', $tag)) 216 $this->facet['tag']['values'][$tag] = $nb; 217 if (preg_match('/^parlementaire=(.*)/', $tag, $matches)) { 218 $this->facet['parlementaire']['values'][$matches[1]] = $nb; 219 } 220 } 221 } 222 205 223 if (!$results['response']['numFound']) { 206 224 if ($format) 207 return ;225 return ; 208 226 return $this->setTemplate('noresults'); 209 227 } … … 212 230 foreach($results['facet_counts']['facet_dates']['date'] as $date => $nb) { 213 231 if (preg_match('/^20/', $date)) { 214 $pc = $nb/$results['response']['numFound'];215 $this->fdates['values'][$date] = array('nb' => $nb, 'pc' => $pc);216 if ($this->fdates['max'] < $pc) {217 $this->fdates['max'] = $pc;218 }232 $pc = $nb/$results['response']['numFound']; 233 $this->fdates['values'][$date] = array('nb' => $nb, 'pc' => $pc); 234 if ($this->fdates['max'] < $pc) { 235 $this->fdates['max'] = $pc; 236 } 219 237 } 220 238 } 221 239 } 240 222 241 public function executeRedirect(sfWebRequest $request) 223 242 {
Note: See TracChangeset
for help on using the changeset viewer.