100) $t = 100; if ($t > 0) $num = $t; } // start with result XXX $start = 0; if (isset($_REQUEST['start'])) { $t = intval($_REQUEST['start']); if ($t > 0) $start = $t; } ////////////////////////////////////////////////////////////////////////// // page header $title = 'Source Search Engine'.($q ? ' - '.htmlentities($q) : ''); header('Content-Type: application/xhtml+xml'); echo << $title

Better get an XSLT capable browser!

ECHOFORM; db_connect(); $stats = array(); $res = mysql_query("SHOW TABLE STATUS"); if ($res) { while ($r = mysql_fetch_array($res)) { $stats[$r['Name']] = $r['Rows']; } } foreach ($stats as $table => $n) { echo('

'.intval($n)." in ".htmlentities($table)."

\n"); } ////////////////////////////////////////////////////////////////////////// // create form fields $ME = $_SERVER['PHP_SELF']; $escaped_q = htmlentities($q); $subword_checked = ($subword ? ' checked="checked" ' : ''); $case_checked = ($case ? ' checked="checked" ' : ''); $hidden_form = ($num != $num_default ? '' : ''); // prettiness hack $ME = preg_replace('/index\.php$/', '', $ME); echo <<
$hidden_form

ECHOFORM; ////////////////////////////////////////////////////////////////////////// // create sql query $sql = ''; while ($q) { $s = split_q($q); if (!count($s)) { break; } if (count($s) == 1) { $where = ($subword ? " w.text LIKE '".db_escape($s[0])."%' " : " w.text='".db_escape($s[0])."' AND w.type='word' " ); } else { $where_parts = array(); foreach ($s as $e) { $where_parts[] = ($subword ? "w.text LIKE '".db_escape($e)."%'" : "w.text='".db_escape($e)."'"); } $where = " (".implode(' OR ', $where_parts).") ". ($subword ? '' : " AND w.type='word' "); } $sql = "SELECT SQL_CALC_FOUND_ROWS COUNT(*)/COUNT(DISTINCT pr.id) AS keywords_cnt, ". " SUM(w.cnt)/COUNT(DISTINCT pr.id) AS cnt, " . " f.path, f.language_id, pr.id AS prid, pr.name AS package_name ". " FROM word AS w, file AS f, package AS p, provider_record AS pr ". " WHERE p.id=pr.package_id AND ".$where. " AND w.file_id=f.id AND f.package_id=p.id ". " AND f.crawler_id=w.crawler_id AND f.crawler_id=p.crawler_id AND pr.crawler_id=f.crawler_id ". " GROUP BY f.crawler_id, f.id ". " ORDER BY keywords_cnt DESC, w.cnt DESC ". " LIMIT ".$start.", ".$num; //echo(htmlentities($sql)); exit; break; } ////////////////////////////////////////////////////////////////////////// // query DB $total = 0; while (isset($sql) and $sql) { $res = mysql_query($sql); if ($res === false) { echo('

'.mysql_errno().': '.mysql_error()."
\n".$sql."

\n"); break; } $res2 = mysql_query("SELECT FOUND_ROWS() AS cnt"); if ($r2 = mysql_fetch_array($res2)) { $total = $r2['cnt']; } //$total = mysql_num_rows($res); break; } $max_page = max(1, ceil($total/$num)); $max_start = ($max_page-1)*$num; // behind last result page //if ($start > $max_start) $start = $max_start; // start not aligned //$start = floor($start/$num)*$num; ////////////////////////////////////////////////////////////////////////// // show results if ($total) { echo('

Results: '.$total."

\n". '\n"); } ////////////////////////////////////////////////////////////////////////// // links if ($max_page > 1) { $l = $ME.'?q='.urlencode($q). ($case ? '&case=1' : ''). ($subword ? '&subword=1' : ''). ($num != $num_default ? '&num='.$num : ''). '&start='; echo('\n"); } echo("\n"); ?>