summaryrefslogtreecommitdiffstats
path: root/www/index.php
diff options
context:
space:
mode:
authorStephan Poehlsen <stephan@poehlsen.net>2005-11-23 02:25:01 +0000
committerStephan Poehlsen <stephan@poehlsen.net>2005-11-23 02:25:01 +0000
commite362e8beb12b18b2ef1988770128fbdaec9e265d (patch)
tree0dcc220d7900c4caf3cfc6adcd57915db0864c9b /www/index.php
parent72af90dbe17e3e0a1534f85e3f7af4e49ec7ac0f (diff)
erste Version vom Webinterface
git-svn-id: file:///home/lennart/svn/public/sse/trunk@34 5fbabb74-0606-0410-a5e4-b5cc6a42724e
Diffstat (limited to 'www/index.php')
-rw-r--r--www/index.php210
1 files changed, 210 insertions, 0 deletions
diff --git a/www/index.php b/www/index.php
new file mode 100644
index 0000000..235266c
--- /dev/null
+++ b/www/index.php
@@ -0,0 +1,210 @@
+<?php
+error_reporting(E_ALL);
+require_once('_main.inc.php');
+
+
+//////////////////////////////////////////////////////////////////////////
+// parse arguments
+
+// text: search field
+$q = (isset($_REQUEST['q']) ? $_REQUEST['q'] : '');
+
+// checkbox: subword
+$subword = ((isset($_REQUEST['subword']) and $_REQUEST['subword'])
+ ? 'checked' : false);
+
+// checkbox: casesensitiv
+$case = ((isset($_REQUEST['case']) and $_REQUEST['case'])
+ ? 'checked' : false);
+$case = false;
+
+// results per page
+$num = $num_default;
+if (isset($_REQUEST['num'])) {
+ $t = intval($_REQUEST['num']);
+ if ($t > 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;
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+// create form fields
+
+$title = 'Source Search Engine'.($q ? ' - '.htmlentities($q) : '');
+
+$ME = $_SERVER['PHP_SELF'];
+$escaped_q = htmlentities($q);
+$subword_checked = ($subword ? ' checked="checked" ' : '');
+$case_checked = ($case ? ' checked="checked" ' : '');
+$hidden_form = ($num != $num_default ? '<input type="hidden" name="num" value="'.$num.'" />' : '');
+
+// prettiness hack
+$ME = preg_replace('/index\.php$/', '', $ME);
+
+echo <<<ECHOFORM
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
+<title>$title</title>
+</head>
+<body>
+
+<div class="formbox">
+<form action="$ME" method="get">$hidden_form
+<p><input type="text" name="q" value="$escaped_q" /> <input type="submit" value="Search" /></p>
+<p><input type="checkbox" id="subword" name="subword" value="1" $subword_checked /> <label for="subword">subwords</label></p>
+</form>
+</div>
+
+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 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 ".
+ " GROUP BY f.crawler_id, f.id ".
+ " ORDER BY w.cnt DESC ";
+
+ break;
+}
+
+
+
+
+//////////////////////////////////////////////////////////////////////////
+// query DB
+
+$total = 0;
+while (isset($sql) and $sql) {
+
+ db_connect();
+
+ // use LIMIT ==> two queries: 1. total count, 2. results
+ // or mysql query cache ==> one query (dump data)
+
+ $res = mysql_query($sql);
+ if ($res === false) {
+ echo('<p class="error">'.mysql_errno().': '.mysql_error()."<br />\n".$sql."</p>\n");
+ break;
+ }
+ $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('<p>Results: '.$total."</p>\n".
+ '<ul class="results">'."\n");
+
+ $i = 0;
+ while ($r = mysql_fetch_array($res)) {
+ //var_dump($r); exit;
+ if ($i == $start+$num) break;
+ $i++;
+ if ($i <= $start) continue;
+
+
+ $r['keywords_cnt'] = intval($r['keywords_cnt']);
+ if ($r['keywords_cnt'] < 2) $r['keywords_cnt'] = '';
+ echo('<li>'.htmlentities($r['package_name']).': '.
+ '<a href="show/'.htmlentities($r['prid']).'/'.htmlentities($r['path']).'?q='.htmlentities($q).'#first">'.
+ htmlentities($r['path']).'</a> '.
+ '('.intval($r['cnt']).' hits'.
+ ($r['keywords_cnt'] ? ' - '.$r['keywords_cnt'].' different words' : '').
+ ')'."</li>\n");
+ }
+
+ echo("</ul>\n");
+}
+
+//////////////////////////////////////////////////////////////////////////
+// links
+if ($max_page > 1) {
+
+ $l = $ME.'?q='.urlencode($q).
+ ($case ? '&amp;case=1' : '').
+ ($subword ? '&amp;subword=1' : '').
+ ($num != $num_default ? '&amp;num='.$num : '').
+ '&amp;start=';
+
+ echo('<ul class="links">'."\n".
+ ($start ? '<li><a href="'.$l.'0">first</a>'."</li>\n" : '').
+ ($start ? '<li><a href="'.$l.max(0, $start-$num).'">previous</a>'."</li>\n" : ''));
+
+ $lnkcnt = 10;
+ for ($i = max(0,$start-($lnkcnt*$num)); $i <= min($max_start, $start+($lnkcnt*$num)); $i+=$num) {
+ echo('<li><a href="'.$l.$i.'"'.($i == $start ? ' class="active" ' : '').'>'.(($i/$num)+1).'</a>'."</li>\n");
+ }
+
+ echo(($start < $max_start ? '<li><a href="'.$l.min($max_start, $start+$num).'">next</a>'."</li>\n" : '').
+ ($start < $max_start ? '<li><a href="'.$l.$max_start.'">last</a>'."</li>\n" : '').
+ "</ul>\n");
+
+}
+
+
+
+
+echo("</body>\n</html>");
+?> \ No newline at end of file