我正在尝试Solr中的空间搜索。 我所做的就是要停止该服务,然后更新了schema.xml
文件collection1
包括以下内容:如何检查空间搜索是否在Solr中工作
<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
<dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="true"/>
<field name="location" type="location" indexed="true" stored="true"/>
<field name="location_0_coordinate" type="double" indexed="true" stored="true"/>
<field name="location_1_coordinate" type="double" indexed="true" stored="true"/>
然后,我又开始了服务更新Solr的文档:
$local_select = 'http://localhost:8080/solr/select?q=ss_type:(business%20OR%20user%20OR%20blog)&wt=json';
$url = $local_select;
$data = file_get_contents($url);
$r_data = json_decode($data, true);
$docs = $r_data['response']['docs'];
if(!empty($docs)){
foreach($docs as $doc){
if(!empty($doc['tm_field_business_address:postal_code'][0])){
$postal_code = urlencode($doc['tm_field_business_address:postal_code'][0]);
$api = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $postal_code . '&sensor=false';
$api_results = file_get_contents($api);
$data = json_decode($api_results, true);
if($data['status'] == 'OK'){
$location = $data['results'][0]['geometry']['location'];
unset($doc['_version_']);
$doc['location_0_coordinate'] = $location['lat'];
$doc['location_1_coordinate'] = $location['lng'];
$new_docs[] = $doc;
}
}
}
}
$local_update = 'http://localhost:8080/solr/update/json';
$local_commit = 'http://localhost:8080/solr/update?commit=true';
//update the solr index
if(!empty($new_docs)){
$json_doc = json_encode($new_docs);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array("Content-type:application/json"),
CURLOPT_URL => $local_update,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $json_doc,
));
$update_response = curl_exec($curl);
curl_close($curl);
//commit the changes
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $local_commit
));
$commit_response = curl_exec($curl);
}
卷曲反应都是好的,当我用这个查询检查结果时:
http://localhost:8080/solr/select?q=ss_type:(business%20OR%20user%20OR%20blog)
它返回结果:
<double name="location_0_coordinate">49.9641523</double>
<double name="location_1_coordinate">10.1378365</double>
现在我的问题是我真的设置好了吗?如果是,会是怎样,我可以用它来检查,如果它真的回来的东西,一旦我使用了一个空间查询类似下面的查询:
http://localhost:8080/solr/select/?q=ss_type:(business%20OR%20user%20OR%20blog)&fq={!geofilt}&sfield=location&pt=49.9641523,10.1378365&d=0
我这里主要的问题是,我真的不知道要为参考点提供什么,以便它返回已经存在于Solr索引中的记录。
因此,举例来说,如果我有在索引中的坐标如下:
49.9641523,10.1378365
会是怎样,将返回其具有协调特定记录空间查询。 我试图用d=0
但什么都不会返回:
<response>
<result name="response" numFound="0" start="0"/>
</response>
任何想法?提前致谢。
所以像这样:'$ doc ['location_coordinate'] = $ location ['lat']。 ','。 $ location ['lng']'? – user225269
我收到一个错误,如果我做了上面的一个:'错误添加字段'location_coordinate'='51.3223777,-0.1358427'msg =对于输入字符串:\“51.3223777,-0.1358427 \”“,”code“:400} }' – user225269
字段类型必须是'location' – Stanley