-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-search.php
More file actions
38 lines (31 loc) · 1016 Bytes
/
json-search.php
File metadata and controls
38 lines (31 loc) · 1016 Bytes
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
<?php
require_once('config.php');
require_once('functions.php');
require_once('search-engine.php');
// Get the user request
$q = $search = htmlspecialchars(trim($_GET['q']));
$q = mb_strtolower($q);
$keywords = array_unique(explode(' ', $q));
$domain = clean_domain(htmlspecialchars(trim($_GET['d'])));
// Perform search
// Start domain crawler
$url = 'http://swifteasearch.alwaysdata.net/swiftea-server/start-crawler';
$data = array(
'url' => 'http://' . $domain,
'level' => '0',
// 'target-level' => '1',
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* TODO: Handle error */ }
// Handle results
list($results, $nb_results, $real_nb_results, $pages, $page) = search($keywords, $domain);
echo json_encode($results);
?>