首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何检查Solr中的空间搜索是否有效

如何检查Solr中的空间搜索是否有效
EN

Stack Overflow用户
提问于 2013-06-20 12:19:20
回答 2查看 1.3K关注 0票数 0

我正在尝试Solr中的空间搜索。我所做的是停止服务,然后更新collection1schema.xml文件以包含以下内容:

代码语言:javascript
运行
复制
<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中的文档:

代码语言:javascript
运行
复制
$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响应都是ok的,当我使用以下查询检查结果时:

代码语言:javascript
运行
复制
http://localhost:8080/solr/select?q=ss_type:(business%20OR%20user%20OR%20blog)

它返回结果:

代码语言:javascript
运行
复制
<double name="location_0_coordinate">49.9641523</double>
<double name="location_1_coordinate">10.1378365</double>

现在我的问题是,我真的正确地设置了吗?如果是,当我使用像下面这样的空间查询时,我可以使用什么查询来检查它是否真的返回了什么东西:

代码语言:javascript
运行
复制
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索引中已经存在的记录。

例如,如果我在索引中有以下坐标:

代码语言:javascript
运行
复制
49.9641523,10.1378365

返回具有该坐标的特定记录的空间查询将是什么。我尝试使用d=0,但没有返回任何内容:

代码语言:javascript
运行
复制
<response>
<result name="response" numFound="0" start="0"/>
</response>

有什么想法吗?提前谢谢。

EN

Stack Overflow用户

发布于 2013-06-20 14:08:25

好的,我想出来了,在schema.xml文件中有一个默认的动态字段,它允许你存储坐标,它的字段类型是location。因此,即使我不能访问schema.xml文件,我仍然可以这样定义它:

代码语言:javascript
运行
复制
$doc['locm_store'] = $location['lat'] . ',' . $location['lng'];

xml文档中的等价物是:

代码语言:javascript
运行
复制
<field name="locm_store">123,456</store>

其中123是纬度,456是经度。

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17205189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档