php - Google Books API: phrase-search hits differ from Google Books (browser) -
i want embed google books api app written in php. have couple of strings (phrases) , want them on google books, precice verbatim phrases (no proximity search or semantic word-distance). on of these phrases know manually querying google books, results should appear , yet api version shows me different hits browser version.
in browser restrict language english, in api-version, too. here php:
<?php function getbooks($query, $howmany, $startindex = 0) { $booksneeded = $howmany; $url = "https://www.googleapis.com/books/v1/volumes?q=".urlencode($query)."&startindex=$startindex&maxresults=$booksneeded&langrestrict=en&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $agents = array( 'mozilla/5.0 (windows nt 10.0; wow64; rv:54.0) gecko/20100101 firefox/54.0' /*'mozilla/5.0 (macintosh; intel mac os x 10.7; rv:7.0.1) gecko/20100101 firefox/7.0.1', 'mozilla/5.0 (x11; u; linux i686; en-us; rv:1.9.1.9) gecko/20100508 seamonkey/2.0.4', 'mozilla/5.0 (windows; u; msie 7.0; windows nt 6.0; en-us)', 'mozilla/5.0 (macintosh; u; intel mac os x 10_6_7; da-dk) applewebkit/533.21.1 (khtml, gecko) version/5.0.5 safari/533.21.1'*/ ); // data curl $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch,curlopt_useragent,$agents[array_rand($agents)]); $bookbatch = curl_exec($ch); curl_close($ch); // convert json array , print books $bookbatch = json_decode($bookbatch, true); echo "<b>number of hits: ".$bookbatch['totalitems']."</b> --- "; echo "<b>search query:</b> <span style='color:green'>".$query."</span><br/>"; foreach ($bookbatch['items'] $key => $value){ echo "{$key},{$value['id']},{$value['volumeinfo']['title']},"; if(array_key_exists('authors', $value['volumeinfo'])){ echo "["; foreach ($value['volumeinfo']['authors'] $schlu => $val){ echo $val.";"; } echo "]<br/>"; }else echo "<br/>"; } } getbooks(""the golden city be"", 20); ?>
i played around user agents bit , set curl user agent 1 of browser, doesn't affect api. api version responds "4 hits" ($bookbatch['totalitems']) string "the golden city be" (including quotations phrase-search), of 1 hit returned. browser version (settings-> languages -> english) says "about 3 results (0,19 seconds)" , shows four, of 1 true positive looking (a book mccabe). can me same results in browser , in api-version? 1 hit in api version, not in browser , vice versa browser hits better (not given string).
also: in browser can filter time period (e.g. 1800-1940), work when querying api somehow? massively reduce contingent usage.
thanks lot.
**edit:**noone idea? also, no matther how encode quotationmarks achieve phrase search, hits not contain searched phrase, when check manually in browser version. doing wrong or api documentation wrong, claims quotation marks around- , url-endoding of search string produce phrase search.
Comments
Post a Comment