Format verbatim mode in Google Custom Search

Can I force Google Custom Search to use the default verbatim mode?

For this I use it, verbatim mode will give the most relevant results, but users may not know what to look for in quotes.

I have an idea that I can add quotes with Javascript before the string is sent to Google, but I cannot figure out how to do this.

Any help would be greatly appreciated!

+7
google-custom-search
source share
1 answer

It is best to use a PHP proxy or something similar to editing a request to add % 22 , which converts the request to a "request" before disabling the request.

header('Content-type: application/json'); # Setup Base URL and array for Parameters $host = 'https://www.googleapis.com/customsearch/v1?'; $queries = array(); $queries['cx'] = "CSEKey"; $queries['key'] = "YourAPIKey"; # Setup possible incoming params if (isset($_GET['search_term'])) $queries['q'] = "%22"+ $_GET['search_term']+ "%22"; if (isset($_GET['result_count'])) $queries['result_count'] = $_GET['result_count']; if (isset($_GET['callback'])) $queries['callback'] = $_GET['callback']; # Build query and Final URL $queriesURL = http_build_query($queries); $finalURL = $host.$queriesURL; /* DEBUG generated URL echo $finalURL; */ $response = file_get_contents($finalURL); echo $response; ?> 

I believe this method forced Verbatim mode because the new JSON answer did not have the usual weird supposed spelling of the name:

  "spelling": { "correctedQuery": "Deo Vandski", "htmlCorrectedQuery": "\u003cb\u003e\u003ci\u003eDeo Vandski\u003c/i\u003e\u003c/b\u003e" }, 

I also saw something about adding &tbs=li:1 , but I didn't see any difference when I tried to use my searches ...

0
source share

All Articles