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