Ниже представлен кусочек ядра текстового поиска в файлах. Каким образом можно провести оптимизацию? Файлов может быть более 100, средний размер файла с html кодом более 10 кбСсылка на работоспособный вариант поиска по данному алгоритму: http://www.da7.ru/Код | // поиск mainpage $path = $_SERVER['DOCUMENT_ROOT']."/content/mainpage/"; $dir_handle = @opendir($path) or die("Поиск не возможен");
while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || strstr($file,'BAK')) continue; $count=0; // счетчик кол-ва повторений if (is_file($path.$file)) { if (strstr($file,'mp')) { // открытие файла для чтения @$fg=fopen($path.$file, 'rb', true); if (!$fg) { echo '<br /><font color=red size=+2>В данный момент услуги нашего сервиса не доступны, попробуйте еще раз спустя несколько секунд.</font>'; exit; } flock($fg, LOCK_SH); while ( !feof($fg) ) { $code_for_seach=fgets($fg, 550); // ищем в файле текст if (stristr($code_for_seach,$seach_user) ) { // полное совпадение if (strchr($seach_user, ' ')) $count=$count+$max_seach_fraza; else $count=$count+$min_seach_word; } // модель неполного совпадения for ($i=0; $i<count($ar_seach_words); $i++) { if (stristr($code_for_seach,$ar_seach_words[$i]) ) $count=$count+$min_seach_word; } // конец модели неполного совпадения } flock($fg, LOCK_UN); fclose($fg); // конец поиска // вывод информации о поиске с поступенчатым условием if ($count_out_pages<3 && $count>=$for_out_ball1) { out("/mainpage/".$file,$count); $count_out_pages++; } elseif ($count_out_pages>=3 && $count_out_pages<=6 && $count>=$for_out_ball2){ out("/mainpage/".$file,$count); $count_out_pages++; } elseif ($count_out_pages>6 && $count_out_pages<=9 && $count>=$for_out_ball3){ out("/mainpage/".$file,$count); $count_out_pages++; } elseif ($count_out_pages>9 && $count>=$for_out_ball4){ out("/mainpage/".$file,$count); $count_out_pages++; } } // конец вывода } } closedir($dir_handle); //конец процедуры
|
|