Show
Ignore:
Timestamp:
07/04/10 10:50:08 (3 years ago)
Author:
d0nut
Message:

finished solr RC 1

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • solr/files/lib/page/SolrSearchPage.class.php

    r1183 r1190  
    99 */ 
    1010class SolrSearchPage extends SearchResultPage { 
     11        public $templateName = 'solr'; 
    1112        protected $total = 0; 
    1213         
     
    2425         * @return      string 
    2526         */ 
    26         protected static function convertSingleWhitespace($string) { 
     27        protected function convertSingleWhitespace($string) { 
    2728                $string = str_replace(array("\t", " ", "\r", "\n", "-", urldecode("%C2%A0")), " ", $string); 
    2829                while(strpos($string, '  ') !== false) { 
     
    3132                return $string; 
    3233        } 
     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        } 
    3345         
    3446        /** 
     
    3648         */ 
    3749        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 
    3870                $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); 
    4172                $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                 
    4692                        //  set solr defaults 
    47                         if(empty($row->messageType)) { 
    48                                 $row->messageType = 'solr'; 
     93                        if(!empty($row->messageType)) { 
     94                                $data['messageType'] = $row->messageType; 
    4995                        } 
    50                         if(empty($row->messageID)) { 
    51                                 $row->messageID = $i; 
     96                        if(!empty($row->type)) { 
     97                                $data['type'] = $row->type; 
    5298                        } 
    53                  
     99                        if(!empty($row->messageID)) { 
     100                                $data['messageID'] = $row->messageID; 
     101                        } 
     102         
    54103                        // increment message key position 
    55                         $this->result[$i++] = $row; 
     104                        $this->result[$i++] = $data; 
    56105                } 
    57106        }