Changeset 12934
- Timestamp:
- 10/22/07 07:57:44 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/MidCOM_2_8/midcom.helper.search/viewer.php
r12925 r12934 83 83 midcom_show_style('search_form'); 84 84 } 85 85 86 /** 87 * Appends language to search terms 88 * 89 * @param $final_query reference to the query string to be passed on to the indexer. 90 */ 91 function add_multilang_terms(&$final_query) 92 { 93 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 94 { 95 $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 96 } 97 } 98 86 99 /** 87 100 * Queries the information from the index and prepares to display the result page. … … 94 107 function _handler_result($handler_id, $args, &$data) 95 108 { 96 $indexer =& $GLOBALS['midcom']->get_service('indexer'); 97 109 debug_push_class(__CLASS__, __FUNCTION__); 110 $indexer =& $_MIDCOM->get_service('indexer'); 111 112 // Sane defaults for REQUEST vars 113 if (!isset($_REQUEST['type'])) 114 { 115 $_REQUEST['type'] = 'basic'; 116 } 117 if (!isset($_REQUEST['page'])) 118 { 119 $_REQUEST['page'] = 1; 120 } 121 if (!isset($_REQUEST['component'])) 122 { 123 $_REQUEST['component'] = ''; 124 } 125 if (!isset($_REQUEST['topic'])) 126 { 127 $_REQUEST['topic'] = ''; 128 } 129 if (!isset($_REQUEST['lastmodified'])) 130 { 131 $_REQUEST['lastmodified'] = 0; 132 } 133 // If we don't have a query string, relocate to empty search form 134 if (!isset($_REQUEST['query'])) 135 { 136 debug_add('$_REQUEST["query"] is not set, relocating back to form', MIDCOM_LOG_INFO); 137 debug_pop(); 138 if ($data['type'] == 'basic') 139 { 140 $_MIDCOM->relocate(''); 141 } 142 $_MIDCOM->relocate('advanced/'); 143 } 144 98 145 $data['type'] = $_REQUEST['type']; 99 146 $data['query'] = trim($_REQUEST['query']); 147 100 148 if ( $GLOBALS['midcom_config']['indexer_backend'] != 'solr' 101 149 && count(explode(' ', $data['query'])) == 1 102 150 && strpos($data['query'], '*') === false) 103 151 { 152 /** 153 * If there is only one search term AND the backend is not Solr 154 * Append * to the query (Solr does this wilcard automagically) 155 */ 104 156 $data['query'] .= '*'; 105 157 } 106 158 107 108 159 switch ($data['type']) 109 160 { 110 161 case 'basic': 111 112 162 $final_query = $data['query']; 113 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 114 { 115 $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 116 } 163 $this->add_multilang_terms($final_query); 164 debug_add("Final query: {$final_query}"); 117 165 $result = $indexer->query($final_query); 118 166 break; 119 167 120 168 case 'advanced': 121 122 169 $data['request_topic'] = trim($_REQUEST['topic']); 123 170 $data['component'] = trim($_REQUEST['component']); … … 159 206 } 160 207 161 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 162 { 163 $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 164 } 208 $this->add_multilang_terms($final_query); 165 209 debug_add("Final query: {$final_query}"); 166 210 … … 171 215 $this->errstr = "Wrong handler ID {$handler_id} for searchform handler"; 172 216 $this->errcode = MIDCOM_ERRCRIT; 217 debug_pop(); 173 218 return false; 174 219 } … … 180 225 // the indexer backend though (what would I give for a decent exectpion 181 226 // handling here...) 227 debug_add('Got boolean false as resultset (likely broken query), casting to empty array', MIDCOM_LOG_WARN); 182 228 $result = Array(); 183 229 } … … 202 248 $data['result'] = array_slice($result, $first_document_id, $results_per_page); 203 249 } 250 debug_pop(); 204 251 return true; 205 252 }
