Changeset 1190 for solr/files/lib/page/SolrSearchPage.class.php
- Timestamp:
- 07/04/10 10:50:08 (3 years ago)
- Files:
-
- 1 modified
-
solr/files/lib/page/SolrSearchPage.class.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
solr/files/lib/page/SolrSearchPage.class.php
r1183 r1190 9 9 */ 10 10 class SolrSearchPage extends SearchResultPage { 11 public $templateName = 'solr'; 11 12 protected $total = 0; 12 13 … … 24 25 * @return string 25 26 */ 26 protected staticfunction convertSingleWhitespace($string) {27 protected function convertSingleWhitespace($string) { 27 28 $string = str_replace(array("\t", " ", "\r", "\n", "-", urldecode("%C2%A0")), " ", $string); 28 29 while(strpos($string, ' ') !== false) { … … 31 32 return $string; 32 33 } 34 35 /** 36 * if the client is (or claims to be) connected via HTTPS 37 * @return boolean 38 */ 39 protected function isHTTPS() { 40 return isset($_SERVER["HTTP_X_PROTO"]) || 41 (isset($_SERVER['HTTPS']) && 42 !empty($_SERVER['HTTPS']) && 43 $_SERVER['HTTPS'] !== 'off'); 44 } 33 45 34 46 /** … … 36 48 */ 37 49 protected function readSearch() { 50 51 // seo friendly redirect of page 1 52 if(isset($_GET['pageNo']) && $_GET['pageNo'] == 1) { 53 $url = ($this->isHTTPS() ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].str_replace("&pageNo=1", "", $_SERVER['REQUEST_URI']); 54 HeaderUtil::redirect($url, false, true); 55 exit; 56 } 57 58 // get search query 59 if (isset($_REQUEST['q'])) $this->query = $_REQUEST['q']; 60 61 if(!$this->query) { 62 return; 63 } 64 65 // param 66 $offset = (max($this->pageNo,1) - 1) * $this->itemsPerPage; 67 $i = $offset; 68 69 // query search 38 70 $solr = new SolrService(SOLR_URL); 39 40 $tmp = $solr->search($this->query, ($this->pageNo - 1) * $this->itemsPerPage, $this->itemsPerPage); 71 $tmp = $solr->search($this->query, $offset, $this->itemsPerPage); 41 72 $this->total = intval($tmp->response->numFound); 42 43 $i = 0; 44 foreach($tmp->highlighting as $row) { 45 73 74 if(!$tmp || !$tmp->highlighting) { 75 return; 76 } 77 78 // transform data in wcf compatible format 79 foreach($tmp->highlighting as $url => $row) { 80 // press first dimension of stdobject into clean array 81 $data = array(); 82 $data['messageID'] = $i; 83 $data['message'] = $this->convertSingleWhitespace($row->content[0]); 84 $data['subject'] = $row->title[0]; 85 $data['url'] = $url; 86 $data['displayurl'] = $row->url[0]; 87 $data['image'] = 'http://image.browsershots.de/'.parse_url($data['url'], PHP_URL_HOST); 88 $data['time'] = time(); // TODO: time 89 $data['messageType'] = 'solr'; 90 $data['type'] = 'solr'; 91 46 92 // set solr defaults 47 if( empty($row->messageType)) {48 $ row->messageType = 'solr';93 if(!empty($row->messageType)) { 94 $data['messageType'] = $row->messageType; 49 95 } 50 if( empty($row->messageID)) {51 $ row->messageID = $i;96 if(!empty($row->type)) { 97 $data['type'] = $row->type; 52 98 } 53 99 if(!empty($row->messageID)) { 100 $data['messageID'] = $row->messageID; 101 } 102 54 103 // increment message key position 55 $this->result[$i++] = $ row;104 $this->result[$i++] = $data; 56 105 } 57 106 }
