Author: Filip Sergeys
Email: [EMAIL PROTECTED]
Message:
Hi,
I hope we can make suggestion here too.
Current situation:
If you have for example 20 result per page, currently there are 20 calls done to
the database to retrieve url information (title, doctype, text, ...). So one new call
for every url.
(--code: see search.php, starting under init(); --)
Suggestion
I think this can be reduced to one single call, using SELECT ... FROM ... WHERE ... IN
('...', '...', '...') as
the query for $query_url)
I don't know if it is going to make a big difference, but I think it can reduce the
load on a heavely loaded
database. I have only tested this on a MYSQL database, so I don't if it works for
other databases. Maybe
that is the reason why it hasn't been implemented this way.
The changed code:
(-- the changed code is marked with a "-----------------------------" line above and
beneath. --)
IN THE PARSE.INC FILE:
(near the bottom; function last_parse($q))
$query_url="SELECT $sql_small
url.url,
url.title,
url.txt,
url.content_type,
url.docsize,
$last_mod_field,
url.keywords,
url.description,
$crc_field,
url.rec_id
$cat_field
FROM url
-----------------------------------------------------------------------------
WHERE url.rec_id IN (%URL_IN%)";
-----------------------------------------------------------------------------
IN THE SEARCH.PHP FILE:
$data_seek=db_dataseek($res,$from);
if (! $data_seek) {
print_template('notfound');
print_template('bottom');
drop_temp_table(0);
track_query($query_orig,time(),0);
return;
}
//$url_id_array=array();
-------------------------------------------------------------------------------
$url_id_string = "";
$rating_array=array();
for ($i=0; $i<$ps; $i++) {
$row=db_fetchrow($res);
if (!$row) break;
if($url_id_string !=""){$url_id_string .= ", '" . $row[0] . "'";}
else {$url_id_string .= "'" . $row[0] . "'";}
$rating_array[] = $row[1];
}
db_freeresult($res);
drop_temp_table(1);
$query=ereg_replace("%URL_IN%",$url_id_string,$query_url);
if($DEBUG) echo "main(): ",$query,"<BR><HR>";
if (!($res=db_query($query))) print_error_local('Query error:
'.$query."\n<BR>".db_error());
$ndoc=$from+1;
for ($i=0; $i<count($rating_array); $i++) {
$rating=$rating_array[$i];
$data=db_fetchrow($res);
------------------------------------------------------------------------------
$url=$data[0];
$title=$data[1];
$title=($title) ? htmlspecialChars($title):'No title';
$text=ParseDocText(htmlspecialChars($data[2]));
$contype=$data[3];
$docsize=$data[4];
$lastmod=format_lastmod($data[5]);
$keyw=htmlspecialChars($data[6]);
$desc=htmlspecialChars($data[7]);
$crc=$data[8];
$rec_id=0+$data[9];
if ($db_format == '3.1') {
$category=$data[10];
}
if ((ereg("^ftp://", $url)) && ($templates['ftpres'][0] != '')) {
print_template('ftpres');
}
elseif ((ereg("^https?://", $url)) && ($templates['httpres'][0] != '')) {
print_template('httpres');
}
else {
print_template('res');
}
$ndoc++;
}
---------------------------------------------------------------------------
db_freeresult($res);
---------------------------------------------------------------------------
print_template('resbot');
print_template('bottom');
track_query($query_orig,time(),$found);
if ($dbtype == 'oracle7') {
Ora_Close($dbconn); // closing oracle7 cursor
}
</script>
Reply: <http://search.mnogo.ru/board/message.php?id=1715>
___________________________________________
If you want to unsubscribe send "unsubscribe general"
to [EMAIL PROTECTED]