root/solr/files/lib/page/SolrSearchPage.class.php @ 1183

Revision 1183, 1.9 kB (checked in by d0nut, 3 years ago)

solr search engine for woltlab community framework, wbb, burning board, etc

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/page/SearchResultPage.class.php');
4require_once(WCF_DIR.'lib/data/solr/SolrService.php');
5
6/**
7 * SearchForm handles given search request and shows the extended search form.
8 *
9 */
10class SolrSearchPage extends SearchResultPage {
11        protected $total = 0;
12       
13        /**
14         * Creates a new SearchResultPage object. without searchid
15         */
16        public function __construct() {
17                parent::__construct(0);
18        }
19
20        /**
21         * removes all duplicate whitespaces
22         *
23         * @param       string          $string
24         * @return      string
25         */
26        protected static function convertSingleWhitespace($string) {
27                $string = str_replace(array("\t", "&nbsp;", "\r", "\n", "-", urldecode("%C2%A0")), " ", $string);
28                while(strpos($string, '  ') !== false) {
29                        $string = str_replace('  ', ' ', $string);
30                }
31                return $string;
32        }
33       
34        /**
35         * Gets the data of the selected search from database.
36         */
37        protected function readSearch() {
38                $solr = new SolrService(SOLR_URL);
39
40                $tmp = $solr->search($this->query, ($this->pageNo - 1) * $this->itemsPerPage, $this->itemsPerPage);
41                $this->total = intval($tmp->response->numFound);
42
43                $i = 0;
44                foreach($tmp->highlighting as $row) {
45                                       
46                        //  set solr defaults
47                        if(empty($row->messageType)) {
48                                $row->messageType = 'solr';
49                        }
50                        if(empty($row->messageID)) {
51                                $row->messageID = $i;
52                        }
53               
54                        // increment message key position
55                        $this->result[$i++] = $row;
56                }
57        }
58       
59        /**
60         * Caches the message data.
61         */
62        protected function cacheMessageData() {
63                parent::cacheMessageData();
64               
65                $messageCache = array();
66                foreach($this->result as $key => $row) {
67                        if($row['messageType'] == 'solr') {
68                                $messageCache[$key] = $row;
69                        }
70                }
71               
72                if(count($messageCache)) {
73                        $object = SearchEngine::getSearchTypeObject('solr');
74                        $object->cacheMessageData(null, $messageCache);
75                }
76        }
77       
78        /**
79         * @see MultipleLinkPage::countItems()
80         */
81        public function countItems() {
82                parent::countItems();
83               
84                return $this->total;
85        }
86}
87?>
Note: See TracBrowser for help on using the browser.