1 | <?php |
||
7 | class LaravelGoogleCustomSearchEngine |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Custom search engine ID |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $engineId; |
||
16 | |||
17 | /** |
||
18 | * Google console API key |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $apiKey; |
||
23 | |||
24 | /** |
||
25 | * Original response converted to array |
||
26 | * |
||
27 | * @var \stdClass |
||
28 | */ |
||
29 | protected $originalResponse; |
||
30 | |||
31 | /** |
||
32 | * Constructor |
||
33 | * |
||
34 | * LaravelGoogleCustomSearchEngine constructor. |
||
35 | * @param $engineId |
||
36 | * @param $apiKey |
||
37 | */ |
||
38 | public function __construct() |
||
43 | |||
44 | /** |
||
45 | * Setter for engineId, overrides the value from config |
||
46 | * |
||
47 | * @param $engineId |
||
48 | */ |
||
49 | public function setEngineId($engineId){ |
||
52 | |||
53 | /** |
||
54 | * Setter for apiKey, overrides the value from config |
||
55 | * |
||
56 | * @param $engineId |
||
57 | */ |
||
58 | public function setApiKey($apiKey){ |
||
61 | |||
62 | /** |
||
63 | * Get search results |
||
64 | * |
||
65 | * Gets results from CSE only as array of objects where the most important variables are |
||
66 | * [title] - page title |
||
67 | * [htmlTitle] - page title with HTML tags |
||
68 | * [link] - page URL |
||
69 | * [displayLink] - displayed part of page URL |
||
70 | * [snippet] - short text from page with the searched phrase |
||
71 | * [htmlSnippet] - short text from page with the searched phrase with HTML tags |
||
72 | * complete list of parameters with description is located at |
||
73 | * https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response |
||
74 | * |
||
75 | * Input parameters are available here |
||
76 | * https://developers.google.com/custom-search/json-api/v1/reference/cse/list#parameters |
||
77 | * |
||
78 | * @param $phrase |
||
79 | * @return array |
||
80 | * @throws Exception |
||
81 | * @link https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response |
||
82 | * @link https://developers.google.com/custom-search/json-api/v1/reference/cse/list#parameters |
||
83 | */ |
||
84 | public function getResults($phrase, $parameters = array()) |
||
158 | |||
159 | /** |
||
160 | * Get full original response |
||
161 | * |
||
162 | * Gets full originated response converted from JSON to StdClass |
||
163 | * Full list of parameters is located at |
||
164 | * complete list of parameters with description is located at |
||
165 | * https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response |
||
166 | * |
||
167 | * @return \stdClass |
||
168 | * @url https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response |
||
169 | */ |
||
170 | public function getRawResult(){ |
||
173 | |||
174 | /** |
||
175 | * Get search information |
||
176 | * |
||
177 | * Gets basic information about search |
||
178 | * [searchTime] - time costs of the search |
||
179 | * [formattedSearchTime] - time costs of the search formatted according to locale style |
||
180 | * [totalResults] - number of results |
||
181 | * [formattedTotalResults] - number of results formatted according to locale style |
||
182 | * |
||
183 | * @return \stdClass |
||
184 | */ |
||
185 | public function getSearchInformation(){ |
||
188 | |||
189 | /** |
||
190 | * Get the total number of pages where the search phrase is located |
||
191 | * |
||
192 | * @return integer |
||
193 | */ |
||
194 | public function getTotalNumberOfpages(){ |
||
197 | |||
198 | } |
||
199 |