-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
75 lines (61 loc) · 1.41 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
require_once("config.php");
require_once("functions.php");
/**
* Prints INFO related to a particular tag 'q' as
* an array.
*
* Currently in format:
* [ url, hits ]
*
*/
function getTagInfo( $q )
{
global $MYSQL_TABLE_REDIRECTIONS;
$db = dbConnect();
$query = "SELECT url, hits FROM " . $MYSQL_TABLE_REDIRECTIONS . " WHERE tag='" . mysql_real_escape_string($q) . "'";
$result = mysql_query($query, $db);
if($result)
{
$row = mysql_fetch_assoc($result);
echo '["' . $row['url'] . '","' . $row['hits'] . '"]';
}
}
/**
* Prints the TAGS which has 'q' in it. Used by Autocompletion
* Tag Search.
*/
function getSearchMatches( $q )
{
global $MYSQL_TABLE_REDIRECTIONS;
$db = dbConnect();
$query = "SELECT tag FROM " . $MYSQL_TABLE_REDIRECTIONS . " WHERE tag LIKE " . "'%" . $q . "%' ORDER BY LOCATE('$q',LCASE(tag)) LIMIT 0, 15;";
$result = mysql_query($query, $db);
if($result)
{
echo "[";
$num_row = mysql_num_rows($result) ;
$i = 0;
while( $row = mysql_fetch_assoc($result) )
{
echo '"' . $row['tag'] . '"';
$i++;
if( $i < $num_row )
echo ",";
}
echo "]";
}
}
/**
* Request Controller
*/
$request = strtolower($_GET["request"]);
$q = strtolower($_GET["term"]);
if( !$request || !$q)
getSearchMatches($q);
else
if( $request == "info" )
getTagInfo($q);
else if( $request == "matches" )
getSearchMatches($q);
?>