-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_results.php
128 lines (102 loc) · 3.41 KB
/
get_results.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
function getResults($query)
{
//account for Boolean NOT queries
$query = str_replace('NOT+', '-', $query);
//-------------------Google---------------------------
//set index to start results at
$start = 1;
$url ="https://www.googleapis.com/customsearch/v1?key=AIzaSyAzEcu1Wpcvjq5pAG5wRLAj6FL9f7x_u_8&cx=003313570654257649885:ihrkhui8va4&start=$start&q=$query";
//loop through each set of 10 results
for($i=0;$i<1;$i++)
{
//initiate cURL
$ch = curl_init($url);
//set options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// get the web page source into $data
$data = curl_exec($ch);
curl_close($ch);
$js = json_decode($data);
//if API limit is reached
if (isset($js->error->message))
{
$_SESSION['results']['Google'][] = array(NULL, NULL, '$js->error->message'); ;
break;
}
//if no results are returned
elseif(!isset($js->items))
{
$_SESSION['results']['Google'][] = array(NULL, NULL, 'No results returned...');
//turn off query expansion module
$_SESSION['suggestions'] = NULL;
break;
}
else
{
//put each result in the Google array
foreach($js->items as $value)
{
if(isset($value->snippet))
$_SESSION['results']['Google'][] = array($value->link, $value->title, $value->snippet);
else $_SESSION['results']['Google'][] = array($value->link, $value->title, 'No description available...');
}
}
//reset url to get next 10 results
$start += 10;
$url ="https://www.googleapis.com/customsearch/v1?key=AIzaSyAzEcu1Wpcvjq5pAG5wRLAj6FL9f7x_u_8&cx=003313570654257649885:ihrkhui8va4&start=$start&q=$query";
}
//-----------------Bing--------------------
$url= "https://api.datamarket.azure.com/Bing/SearchWeb/Web?\$format=json&Query=$query";
//set credentials to send in header
$credentials = "username:VNkr2xsPpCfgWwRBlU6eKITEwz99rnAzQ53Qcanf3QE=";
$headers = array(
"Authorization: Basic " . base64_encode($credentials)
);
//loop through 2 sets of 50 results
for ($i=0;$i<1;$i++)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
$js = json_decode($data);
foreach($js->d->results as $value)
{
//put each result in the Bing array
$_SESSION['results']['Bing'][] = array($value->Url, $value->Title, $value->Description);
}
//get next 50 results
$url = $url.'&$skip=50';
}
//----------------Blekko-----------------
$query = str_replace('+OR+', '', $query);
$url ="http://blekko.com/ws/?q=$query+/ps=50+/json&auth=f4c8acf3/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
$js = json_decode($data);
if(!isset($js->RESULT))
{
}
else
{
foreach($js->RESULT as $value)
{
//put each result in the Blekko array
if (isset($value->snippet))
{
$_SESSION['results']['Blekko'][] = array($value->url, $value->url_title, $value->snippet);
}
else $_SESSION['results']['Blekko'][] = array($value->url, $value->url_title, 'No description available ...');
}
}
//array to hold all results
return $doc_list = array_merge($_SESSION['results']['Google'], $_SESSION['results']['Bing'], $_SESSION['results']['Blekko']);
}
?>