Changeset 12925
- Timestamp:
- 10/21/07 18:26:35 (1 year ago)
- Files:
-
- branches/MidCOM_2_8/midcom.core/midcom/services/indexer/backend/solr.php (modified) (9 diffs)
- branches/MidCOM_2_8/midcom.core/midcom/services/indexer/document.php (modified) (5 diffs)
- branches/MidCOM_2_8/midcom.core/midcom/services/indexer/document/midcom.php (modified) (2 diffs)
- branches/MidCOM_2_8/midcom.helper.search/viewer.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/MidCOM_2_8/midcom.core/midcom/services/indexer/backend/solr.php
r11087 r12925 108 108 function query ($query, $filter) 109 109 { 110 debug_push_class(__CLASS__, __FUNCTION__); 110 111 if ($filter !== null) 111 112 { … … 119 120 } 120 121 } 122 /* In fact this is probably best left for midcom.helper.search to decide 123 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 124 { 125 $query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 126 } 127 */ 121 128 122 129 $url = "http://" . $GLOBALS['midcom_config']['indexer_xmltcp_host'] . … … 136 143 $msg = (is_object($err)) ? $err->getMessage() : ""; 137 144 debug_add("Failed to execute Request {$url}:{$this->code} {$msg}", MIDCOM_LOG_WARN); 145 debug_pop(); 138 146 return false; 139 147 } 140 141 $response = DomDocument::loadXML($request->getResponseBody()); 148 $body = $request->getResponseBody(); 149 debug_add("Got response\n===\n{$body}\n===\n"); 150 $response = DomDocument::loadXML($body); 142 151 $xquery = new DomXPath($response); 143 152 $result = array(); … … 148 157 } 149 158 150 foreach ($xquery->query('/response/result/doc') as $res) {151 159 foreach ($xquery->query('/response/result/doc') as $res) 160 { 152 161 $doc = new midcom_services_indexer_document(); 153 162 foreach ($res->childNodes as $str) { … … 163 172 164 173 } 165 $result[$doc->RI] = $doc; 166 } 174 $result[] = $doc; 175 } 176 debug_add(sprintf('Returning %d results', count($result)), MIDCOM_LOG_INFO); 177 debug_pop(); 167 178 return $result; 168 179 } … … 283 294 * posts the xml to the suggested url using HTTP_Request. 284 295 * */ 285 function do_post($xml) { 286 296 function do_post($xml) 297 { 298 debug_push_class(__CLASS__, __FUNCTION__); 287 299 $options = array(); 288 300 $options['method'] = HTTP_REQUEST_METHOD_POST ; … … 295 307 $this->request->addHeader('Accept-Charset', 'UTF-8'); 296 308 $this->request->addHeader('Content-type', 'text/xml; charset=utf-8'); 309 debug_add("POSTing XML to {$url}\n===\n{$xml}\n===\n"); 297 310 $err = $this->request->sendRequest(true); 298 311 … … 301 314 if ($this->code != 200 || PEAR :: isError($err)) { 302 315 debug_add("Failed to execute Request {$url}:{$this->code} {$err}", MIDCOM_LOG_WARN); 303 debug_add("Request content: \n$xml", MIDCOM_LOG_DEBUG); 316 debug_add("Request content: \n$xml", MIDCOM_LOG_DEBUG); 317 debug_pop(); 304 318 return false; 305 319 } … … 312 326 debug_add("Failed to execute Request {$url}: {$err->getMessage()}", MIDCOM_LOG_WARN); 313 327 debug_add("Request content: \n$xml", MIDCOM_LOG_INFO); 328 debug_pop(); 314 329 return false; 315 330 } 331 debug_add('POST ok'); 332 debug_pop(); 316 333 return true; 317 334 branches/MidCOM_2_8/midcom.core/midcom/services/indexer/document.php
r11079 r12925 88 88 89 89 /** 90 * Two letter language code of the document contnet 91 * 92 * This field is optional. 93 * 94 * @var string 95 */ 96 var $lang = ''; 97 98 /** 90 99 * The GUID of the topic the document is assigned to. May be empty for 91 100 * non-midgard resources. … … 444 453 445 454 // __RI does not need to be populated, this is done by backends. 455 $this->add_unindexed('__LANG', $this->lang); 446 456 $this->add_text('__TOPIC_GUID', $this->topic_guid); 447 457 $this->add_text('__COMPONENT', $this->component); … … 493 503 { 494 504 $this->RI = $this->get_field('__RI'); 505 $this->lang = $this->get_field('__LANG'); 495 506 $this->topic_guid = $this->get_field('__TOPIC_GUID'); 496 507 $this->component = $this->get_field('__COMPONENT'); … … 517 528 $this->type = $this->get_field('__TYPE'); 518 529 $this->security = $this->get_field('__SECURITY'); 530 531 // Strip language code from end of RI if it looks like "<GUID>_<LANG>" (because *many* places suppose it's plain GUID) 532 $this->RI = preg_replace('/^([0-9a-f]{32,80})_[a-z]{2}$/', '\\1', $this->RI); 519 533 } 520 534 … … 568 582 debug_add("Editor: " . (! is_object($this->editor) ? 'none' : $this->editor->name), $loglevel); 569 583 debug_add("RI: {$this->RI}", $loglevel); 584 debug_add("Language: {$this->lang}", $loglevel); 570 585 debug_add("Score: {$this->score}", $loglevel); 571 586 debug_add("Source: {$this->source}", $loglevel); branches/MidCOM_2_8/midcom.core/midcom/services/indexer/document/midcom.php
r5072 r12925 71 71 72 72 $this->source = $this->_metadata->object->guid(); 73 $this->RI = $this->source; 73 $this->lang = $_MIDCOM->i18n->get_content_language(); 74 $this->RI = "{$this->source}_{$this->lang}"; 74 75 $this->document_url = $_MIDCOM->permalinks->create_permalink($this->source); 75 76 … … 77 78 $this->_process_topic(); 78 79 } 79 80 81 /* To simplify life wt indexer results we do this at master class level 82 function fields_to_members() 83 { 84 parent::fields_to_members(); 85 // Strip language code from end of RI if it looks like "<GUID>_<LANG>" (because *many* places suppose it's plain GUID) 86 $this->RI = preg_replace('/^([0-9a-f]{32,80})_[a-z]{2}$/', '\\1', $this->RI); 87 } 88 */ 80 89 81 90 /** branches/MidCOM_2_8/midcom.helper.search/viewer.php
r6141 r12925 97 97 98 98 $data['type'] = $_REQUEST['type']; 99 $data['query'] = trim($_REQUEST['query']); 100 if ( $GLOBALS['midcom_config']['indexer_backend'] != 'solr' 101 && count(explode(' ', $data['query'])) == 1 102 && strpos($data['query'], '*') === false) 103 { 104 $data['query'] .= '*'; 105 } 106 99 107 100 108 switch ($data['type']) 101 109 { 102 110 case 'basic': 103 $data['query'] = trim($_REQUEST['query']);104 105 if ( count(explode(' ', $data['query'])) == 1106 && !strstr($data['query'], '*'))107 {108 // Single search term, append *109 if ($GLOBALS['midcom_config']['indexer_backend'] != 'solr')110 {111 $data['query'] .= '*';112 }113 }114 111 115 $result = $indexer->query($data['query']); 112 $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 } 117 $result = $indexer->query($final_query); 116 118 break; 117 119 118 120 case 'advanced': 119 $data['query'] = trim($_REQUEST['query']); 120 121 if ( count(explode(' ', $data['query'])) == 1 122 && !strstr($data['query'], '*') && $GLOBALS['midcom_config']['indexer_backend'] != 'solr' ) 123 { 124 // Single search term, append * 125 $data['query'] .= '*'; 126 } 127 121 128 122 $data['request_topic'] = trim($_REQUEST['topic']); 129 123 $data['component'] = trim($_REQUEST['component']); … … 163 157 } 164 158 $final_query .= "__COMPONENT:{$data['component']}"; 159 } 160 161 if ($GLOBALS['midcom_config']['i18n_multilang_strict']) 162 { 163 $final_query .= ' AND (__LANG:"' . $_MIDCOM->i18n->get_current_language() . '" OR __LANG:"")'; 165 164 } 166 165 debug_add("Final query: {$final_query}");
