目前我尝试 Azure 搜索。
我设法在索引中插入文档,现在我想解析我的结果。
我的代码如下所示:
<?php
$url ="";
$url .="https://mywebsite.search.windows.net/indexes/test/docs";
$url .= "?search=";
$url .= $keyword;
$url .= "&api-version=2014-07-31-Preview";
print $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'api-key: mytoken',
'Accept: application/json',
));
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
} else
{
// Show me the result
print var_dump($data);
curl_close($ch);
}
?>
我的程序运行良好,但我无法解析如下所示的结果:
string(633) "{"@odata.context":" https://mywebsite.search.windows.net/indexes ('adventurehotel')/$metadata#docs(hotelId,baseRate,description,hotelName,category,tags,停车包括,吸烟允许,lastRenovationDate,rating,location)","value":[{"@search.score":0.16137227,"hotelId":"1","baseRate":199.0,"description":"镇上最好的酒店","hotelName":"Fancy Stay","category":"Luxury","tags":["pool","view","wifi","concierge"],"parkingIncluded":false,"SmokingAllowed" :false,"lastRenovationDate":"2010-06-27T00:00:00Z","rating":5,"location":{"type":"Point","坐标":[-122.131577,47.678581],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}]}"
提前致谢。