Project

General

Profile

« Previous | Next » 

Revision 761

Added by thorn about 16 years ago

search: great speed-up with large pages - requires PHP >= 4.3.3; small speed-up for PHP < 4.3.3.
FCK-Editor: loads large pages faster

View differences:

search.php
23 23

  
24 24
*/
25 25

  
26
// most of this is still the same code as in 2.6.7, but rearranged heavily
26
// we have to do some cleanup here, ASAP!
27 27

  
28
// this is for testing only
29
$overall_start_time = microtime(true);
30
//xdebug_start_trace();
31
//xdebug_enable();
32

  
28 33
if(!defined('WB_URL')) { 
29 34
	header('Location: index.php');
30 35
	exit(0);
......
39 44
	return;
40 45
}
41 46

  
42
// this is for timing-tests only
43
//$overall_start_time = microtime(true);
44

  
45 47
// search-module-extension: get helper-functions
46 48
require_once(WB_PATH.'/search/search_modext.php');
47 49
// search-module-extension: Get "search.php" for each module, if present
......
115 117
//   in wb/modules/wysiwyg/save.php anymore, too. Change that back to $text=strip_tags($content);
116 118

  
117 119
// Get search string
118
$search_normal_string = 'unset';
119
$search_entities_string = 'unset';
120
$search_display_string = '';
120
$search_normal_string = 'unset'; // for regex
121
$search_entities_string = 'unset'; // for SQL's LIKE
122
$search_display_string = ''; // for displaying
121 123
$string = '';
122 124
if(isset($_REQUEST['string'])) {
123 125
	if ($match!='exact') {
......
127 129
	}
128 130
	// redo possible magic quotes
129 131
	$string = $wb->strip_slashes($string);
130
	$string = htmlspecialchars($string);
131
	$search_display_string = $string;
132
	$string = addslashes($string);
132
	$string = trim($string);
133 133
	// remove some bad chars
134
	$string = preg_replace("/(^|\s+)([.])+(?=\s+|$)/", "", $string);
134
	$string = preg_replace('/(^|\s+)[|.]+(?=\s+|$)/', '', $string);
135
	$search_display_string = htmlspecialchars($string);
136
	// convert string to utf-8
137
	$string = entities_to_umlauts($string, 'UTF-8');
138
	$search_entities_string = addslashes(umlauts_to_entities(htmlspecialchars($string)));
135 139
	// mySQL needs four backslashes to match one in LIKE comparisons)
136
	$string = str_replace('\\\\', '\\\\\\\\', $string);
137
	$string = trim($string);
138
	// convert a copy of $string to HTML-ENTITIES
139
	$string_entities = umlauts_to_entities($string);
140
	$search_normal_string = $string;
141
	$search_entities_string = $string_entities;
140
	$search_entities_string = str_replace('\\\\', '\\\\\\\\', $search_entities_string);
141
	// quote ' " and /  -we need quoted / for regex
142
	$search_url_string = $string;
143
	$string = preg_quote($string);
144
	$search_normal_string = str_replace(array('\'','"','/'), array('\\\'','\"','\/'), $string);
142 145
}
143 146

  
144 147
// Get list of usernames and display names
......
190 193
} else { $fetch_cfg_enable_old_search['value'] = 'true'; }
191 194
if($fetch_cfg_enable_old_search['value'] == 'false') { $cfg_enable_old_search = false;
192 195
} else { $cfg_enable_old_search = true; }
196
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'cfg_enable_flush' LIMIT 1");
197
if($query->numRows() > 0) { $fetch_cfg_enable_flush = $query->fetchRow();
198
} else { $fetch_cfg_enable_flush['value'] = 'false'; }
199
if($fetch_cfg_enable_flush['value'] == 'false') { $cfg_enable_flush = false;
200
} else { $cfg_enable_flush = true; }
193 201
// Replace vars in search settings with values
194 202
$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_RESULTS_FOR]');
195 203
$values = array($search_display_string, WB_URL, PAGE_EXTENSION, $TEXT['RESULTS_FOR']);
......
240 248
	$exact_string=$search_entities_string;
241 249
	$search_entities_array[]=$exact_string;
242 250
}	
243
// make an extra copy of $string_entities for use in a regex
251
// make an extra copy of search-string for use in a regex and another one for url
244 252
require_once(WB_PATH.'/search/search_convert.php');
245 253
$search_words = array();
246
foreach ($search_entities_array AS $str) {
247
	$str = entities_to_umlauts($str, 'UTF-8');
248
	$str = preg_quote($str, '/');
254
foreach ($search_normal_array AS $str) {
249 255
	$str = strtr($str, $string_ul_umlauts);
250 256
	// special-feature: '|' means word-boundary (\b). Searching for 'the|' will find the, but not thema.
251 257
	// this doesn't work correctly for unicode-chars: '|test' will work, but '|über' not.
252 258
	$str = strtr($str, array('\\|'=>'\b'));
253 259
	$search_words[] = $str;
254 260
}
261
$search_url_array=explode(' ', $search_url_string);
255 262

  
256 263
// Do extra vars/values replacement
257 264
$vars = array('[SEARCH_STRING]', '[WB_URL]', '[PAGE_EXTENSION]', '[TEXT_SEARCH]', '[TEXT_ALL_WORDS]', '[TEXT_ANY_WORDS]', '[TEXT_EXACT_MATCH]', '[TEXT_MATCH]', '[TEXT_MATCHING]', '[ALL_CHECKED]', '[ANY_CHECKED]', '[EXACT_CHECKED]', '[REFERRER_ID]', '[SEARCH_PATH]');
......
304 311
	// and even if setlocale() is set, it won't work for multi-linguale sites.
305 312
	// Use the search-module-extension instead.
306 313
	// This is somewhat slower than the orginial method.
307
	// CHANGES WITH V1.3: before V1.3 we called [module]-search() for a given page only once and searched in all [module]-sections on this page;
308
	// since V1.3 we call [module]-search() for very single section.
309 314
	$seen_pages = array(); // seen pages per module.
310 315
	$pages_listed = array(); // seen pages.
311 316
	foreach($sorted_modules AS $module_name) {
......
326 331
		");
327 332
		if($sections_query->numRows() > 0) {
328 333
			while($res = $sections_query->fetchRow()) {
329
				// TODO: add a "section is searchable: yes/no" config-element into "Manage Sections" - ???
330
				//       and show this section only if section is searchable
331 334
				// Only show this section if it is not "out of publication-date"
332 335
				$now = time();
333 336
				if( !( $now<$res['publ_end'] && ($now>$res['publ_start'] || $res['publ_start']==0) ||
......
348 351
					'users' => $users,
349 352
					'search_words' => $search_words, // needed for preg_match_all
350 353
					'search_match' => $match,
351
					'search_url_array' => $search_normal_array, // needed for url-string only
354
					'search_url_array' => $search_url_array, // needed for url-string only
352 355
					'results_loop_string' => $fetch_results_loop['value'],
353
					'default_max_excerpt' => $search_max_excerpt
356
					'default_max_excerpt' => $search_max_excerpt,
357
					'enable_flush' => $cfg_enable_flush
354 358
				);
355 359
				// Only show this page if we are allowed to see it
356 360
				if($admin->page_is_visible($res) == false) {
......
400 404
				'users' => $users,
401 405
				'search_words' => $search_words, // needed for preg_match_all
402 406
				'search_match' => $match,
403
				'search_url_array' => $search_normal_array, // needed for url-string only
407
				'search_url_array' => $search_url_array, // needed for url-string only
404 408
				'results_loop_string' => $fetch_results_loop['value'],
405
				'default_max_excerpt' => $max_excerpt_num
409
				'default_max_excerpt' => $max_excerpt_num,
410
				'enable_flush' => $cfg_enable_flush
406 411
			);
407 412
			// Only show this page if we are allowed to see it
408 413
			if($admin->page_is_visible($page) == false) {
......
630 635
// Show search footer
631 636
echo $search_footer;
632 637

  
633
//$overall_end_time = microtime(true); // for testing only
634
//$time=$overall_end_time-$overall_start_time; print "<br />Timings - Overall: $time<br />";
638
$overall_end_time = microtime(true); // for testing only
639
$time=$overall_end_time-$overall_start_time; print "<br />Timings - Overall: $time<br />";
640
//xdebug_stop_trace();
641
//echo "<hr />"."peak memory-usage: ".xdebug_peak_memory_usage()."<br />"."time: ".xdebug_time_index()."<br />";
635 642

  
636 643
?>

Also available in: Unified diff