1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17: 18: 19: 20:
21: class SolrSearchModule {
22:
23: 24: 25: 26:
27: private $_searchTerm;
28:
29: 30: 31: 32:
33: private $_page;
34:
35: 36: 37: 38:
39: private $_itemsPerPage;
40:
41: 42: 43: 44:
45: private $_templateName;
46:
47: 48: 49: 50:
51: private $_response = NULL;
52:
53: 54: 55: 56:
57: public function __construct(array $options = NULL) {
58: if (NULL !== $options) {
59: foreach ($options as $name => $value) {
60: $name = '_' . $name;
61: $this->$name = $value;
62: }
63: }
64: $this->_response = $this->_getSearchResults();
65: }
66:
67: 68: 69: 70:
71: private function _getSearchResults() {
72: $searcher = new SolrSearcherSimple();
73: $searcher->setSearchTerm($this->_searchTerm);
74: $searcher->setPage($this->_page);
75: $searcher->setItemsPerPage($this->_itemsPerPage);
76: return $searcher->getSearchResults();
77: }
78:
79: 80: 81:
82: public function render() {
83: $tpl = cSmartyFrontend::getInstance();
84: $tpl->assign('label', $this->_label);
85: $tpl->assign('href', cUri::getInstance()->build(array(
86: 'idart' => cRegistry::getArticleId(),
87: 'lang' => cRegistry::getLanguageId()
88: )));
89: $tpl->assign('searchTerm', $this->_searchTerm);
90: $tpl->assign('page', $this->_page);
91: $tpl->assign('itemsPerPage', $this->_itemsPerPage);
92:
93:
94: $numPages = $this->_response->numFound / $this->_itemsPerPage;
95: if (is_float($numPages)) {
96: $numPages = ceil($numPages);
97: }
98:
99: $tpl->assign('numPages', $numPages);
100: $tpl->assign('numFound', $this->_response->numFound);
101: $tpl->assign('start', $this->_response->start);
102: if (false === $this->_response->docs) {
103: $tpl->assign('results', array());
104: } else {
105: $tpl->assign('results', $this->_response->docs);
106: }
107: $tpl->display($this->_templateName);
108: }
109:
110: }
111:
112: