-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleSearch.php
34 lines (34 loc) · 1.2 KB
/
GoogleSearch.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
<?php
function getGoogleSearchScore($query) {
include "AlchInt.php";
include_once "lib.php";
$query = urlencode($query);
$searchResults = json_decode(file_get_contents("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$query"), true);
if($searchResults != null && array_key_exists("responseData", $searchResults)) {
$searchResults = $searchResults["responseData"];
if($searchResults != null && array_key_exists("results", $searchResults)) {
$searchResults = $searchResults["results"];
}
else {
return 2;
}
}
else {
return 2;
}
$sentiments = array();
if(sizeof($searchResults) > 0) {
foreach($searchResults as $result) {
try {
array_push($sentiments, floatval(json_decode($AlchemyObj->URLGetTextSentiment($result["url"], AlchemyAPI::JSON_OUTPUT_MODE), true)["docSentiment"]["score"]));
}
catch(Exception $e) {
}
}
return scoreCalc($sentiments);
}
else {
return 0;
}
}
?>