2013-06-20 2 views
0

Solr에서 공간 검색을 시도하고 있습니다. 다음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); 
} 

을 내가했던 것은 서비스를 중지 한 후 다음을 포함하는 collection1에 대한 schema.xml 파일 업데이트 컬 응답이 좋았으며이 쿼리를 사용하여 결과를 확인할 때 다음과 같이 나타났습니다.

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> 

어떤 아이디어? 미리 감사드립니다.

답변

1

위도와 경도는 동일한 필드에 쉼표로 구분하여 저장해야합니다. 예 : <latitude>,<longitude>

필드 유형은 location이어야합니다. 쿼리에서 다음 매개 변수에

<dynamicField name="*_coordinate" type="location" indexed="true" stored="true"/> 

패스 :

pt - 포인트는 필터의 중심지로 사용할 수 있습니다. 쉼표로 구분 된 복식 목록으로 지정됩니다. 그것은 위도, 경도이다.

d

- 좌표를 갖는 필드 -

sfield 필터링하는 데 사용되는 최 외주의 점에서 (KM)에 거리.

지정된 점 49.9641523의 5km 내의 모든 위치를 반환합니다 다음 예제 gespatial 쿼리 10.1378365

http://localhost:8080/solr/select?q=*:*&fq={!geofilt}&pt=49.9641523,10.1378365&sfield=location_coordinate&d=5 
+0

이렇게 :'$ doc [ 'location_coordinate'] = $ location [ 'lat']. ','. $ location [ 'lng']'? – user225269

+0

입력란에 \ "51.3223777, -0.1358427 \" ","code ": 400}을 입력하면 위의 작업을 수행 할 때 오류가 발생합니다. 'Error adding field'location_coordinate '='51.3223777, -0.1358427 'msg = } ' – user225269

+0

필드 유형은'location'이어야합니다 – Stanley

0

확인 당신이 저장할 수있는 schema.xml 파일의 기본 동적 필드가 실제로있다, 그것을 알아 냈다 좌표의 필드 유형은 location입니다.그래서 나는 schema.xml 파일에 액세스 할 수없는 경우에도 나는 아직도 이런 식으로 정의 할 수 있습니다 :

$doc['locm_store'] = $location['lat'] . ',' . $location['lng']; 

는 XML 문서에서 이에 해당하는은 다음과 같습니다

<field name="locm_store">123,456</store> 

123는 위도와 456이 경우 경도.

관련 문제