Project

General

Profile

« Previous | Next » 

Revision 777

Added by thorn about 16 years ago

search: further speed improvment

View differences:

search_modext.php
66 66
function is_all_matched($text, $search_words) {
67 67
	$all_matched = true;
68 68
	foreach ($search_words AS $word) {
69
		if(!preg_match('/'.$word.'/iu', $text)) {
69
		if(!preg_match('/'.$word.'/i', $text)) {
70 70
			$all_matched = false;
71 71
			break;
72 72
		}
......
78 78
function is_any_matched($text, $search_words) {
79 79
	$any_matched = false;
80 80
	$word = '('.implode('|', $search_words).')';
81
	if(preg_match('/'.$word.'/iu', $text)) {
81
	if(preg_match('/'.$word.'/i', $text)) {
82 82
		$any_matched = true;
83 83
	}
84 84
	return $any_matched;
......
163 163
	// 4. $page_link_target=="" - do nothing
164 164
	if(version_compare(PHP_VERSION, '4.3.3', ">=") && substr($page_link_target,0,12)=='#wb_section_') {
165 165
		$word = '('.implode('|', $search_words).')';
166
		preg_match('/'.$word.'/iu', $text, $match, PREG_OFFSET_CAPTURE);
166
		preg_match('/'.$word.'/i', $text, $match, PREG_OFFSET_CAPTURE);
167 167
		if($match && is_array($match[0])) {
168 168
			$x=$match[0][1]; // position of first match
169 169
			// is there an anchor nearby?
......
237 237
	$mod_text = preg_replace('#<(!--.*--|style.*</style|script.*</script)>#SiU', ' ', $mod_text);
238 238
	$mod_text = preg_replace('#<(br( /)?|dt|/dd|/?(h[1-6]|tr|table|p|li|ul|pre|code|div|hr))[^>]*>#Si', '.', $mod_text);
239 239
	$mod_text = entities_to_umlauts($mod_text, 'UTF-8');
240
	// search for an better anchor - this have to be done before strip_tags() (may fail if search-string contains <, &, amp, gt, lt, ...)
241
	$anchor =  make_url_target($mod_page_link_target, $mod_text, $func_search_words);
240
	$anchor_text = $mod_text; // make an copy containing html-tags
242 241
	$mod_text = strip_tags($mod_text);
243 242
	$mod_text = str_replace(array('&gt;','&lt;','&amp;','&quot;','&#39;','&apos;','&nbsp;'), array('>','<','&','"','\'','\'',"\xC2\xA0"), $mod_text);
244 243
	// Do a fast scan over $mod_text first. This will speedup things a lot.
......
249 248
	elseif(!is_any_matched($mod_text, $func_search_words)) {
250 249
		return false;
251 250
	}
251
	// search for an better anchor - this have to be done before strip_tags() (may fail if search-string contains <, &, amp, gt, lt, ...)
252
	$anchor =  make_url_target($mod_page_link_target, $anchor_text, $func_search_words);
252 253

  
253 254
	// make the link from $mod_page_link, add anchor
254 255
	$link = "";

Also available in: Unified diff