Solr で空間検索を試しています。私がしたことは、サービスを停止してから、schema.xml
ファイルを更新しcollection1
て次の内容を含めることでした。
<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);
}
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>
何か案は?前もって感謝します。