-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
88 lines (78 loc) · 2.34 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require "config.php";
require "lib/utils.php";
?>
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>groka</title>
</head>
<body>
<div class="page">
<h1><a href="/">groka</a> <small>your own personal google</small></h1>
<form>
<input type="search" name="q" placeholder="holy grail, amber room" <?php if (isset($_GET['q'])) echo 'value="' . $_GET['q'] . '"'; ?> >
<button>grok!</button>
<?php if (isset($_GET['site'])) { ?>
/ only from site: <input name="site" placeholder="ss64.com" <?php if (isset($_GET['site'])) echo 'value="' . $_GET['site'] . '"'; ?>>
<?php } ?>
</form>
<?php
if (!empty($_GET['q'])) {
require "lib/groonga.php";
$Q = cleantext($_GET['q']);
$g = new groonga(GROONGA_URL);
$grokaQuery = [
'table'=>'groka',
'output_columns'=>'title,description,snippet_html(text),_key,_score',
'query'=>$Q,
'match_columns'=>'title||text',
'sort_keys'=>'-_score',
'limit'=>20 // todo - pagination of results
];
$fromSite = false;
if (isset($_GET['site'])) {
$fromSite = $_GET['site'];
}
if ($fromSite) {
$fromSite = str_replace([], [], $fromSite);
$grokaQuery['filter'] = '_key @^ "https://'. $fromSite . '" || _key @^ "http://'. $fromSite . '"';
}
$results = $g->select($grokaQuery);
if (isset($results[0])) {
$count = array_shift($results[0]);
$schema = array_shift($results[0]);
echo '<p>' . $count[0] . ' results</p>';
foreach ($results[0] as $found) {
echo '<h2><a href="'.$found[3].'">'.$found[0].'</a></h2>';
// echo '<p>'.$found[1].'</p>';
foreach ($found[2] as $matchedText) {
echo '<p>'.$matchedText.'</p>';
}
echo '<a href="'.$found[3].'">'.$found[3].'</a>';
echo '<!-- <p>' . $found[4] . '</p> -->';
echo '<br><br>';
}
} else {
if (!$g->status()) {
echo '<p class="error">error - server is dead</p>';
}
}
}
?>
<hr>
<small><a href="https://github.com/severak/groka">about project</a> * this instance is run by <?php echo GROKA_PROVIDER; ?> * <a href="add.php">add to index</a></small>
</div>
<style>
body { font-family: sans-serif; }
.page { max-width: 50em; margin: 1em auto; }
h1, h2, hr, a { color: green; }
h1 small { font-size: 50%; }
h1 a, h2 a { text-decoration: none; }
input, button { border: 1px solid green; }
.keyword { background-color: yellow; }
.error { color: red; }
</style>
</body>
</html>