日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Solr4.7实现LBS(地理位置搜索)

發(fā)布時間:2025/7/25 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Solr4.7实现LBS(地理位置搜索) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

from:http://mtou.iteye.com/blog/2035280?utm_source=tuicool&utm_medium=referral

olr實現(xiàn)LBS(地理位置搜索)有兩種方式:Cartesian Tiers 笛卡爾層 ?和 ?GeoHash算法,本文主要介紹GeoHash算法實現(xiàn)。

?

實現(xiàn)步驟:

1. 修改schema.xml文件

?

Xml代碼 ?
  • <fieldtype?name="geohash"?class="solr.GeoHashField"/>??
  • <field?name="geohashTest"?type="geohash"?indexed="true"?stored="true"/>??
  • ???

    ?

    2.sorlJ創(chuàng)建索引

    ?

    Java代碼 ?
  • double?latitude?=?39.869664;??
  • double?longitude?=?116.38325;??
  • Collection<SolrInputDocument>?docs?=?new?ArrayList<SolrInputDocument>();????
  • SolrInputDocument?doc1?=?new?SolrInputDocument();???
  • doc1.addField("geohashTest",latitude+","+longitude);??
  • docs.add(doc1);???
  • server.add(docs);??
  • server.commit();??
  • ???? ?注意:經(jīng)緯度格式:緯度,經(jīng)度 ?

    ?

    ?

    3.檢索

    ? ?(1)sorlJ查詢

    ?

    Java代碼 ?
  • SolrQuery?query?=?new?SolrQuery();??
  • query.addFilterQuery("{!geofilt}");???
  • query.set("q",?"*:*");???
  • query.set("d","10");???
  • query.set("sfield","geohashTest");???
  • query.set("pt","40.2323,116.12");???
  • QueryResponse?rsp?=?server.query(query);??
  • ? ?(2)控制臺查詢

    ?

    ? ? ? ?

    ??
    ? ?
    ?
    ? ?(3)檢索字段說明

    ? ? ?sfield:geohash對應(yīng)的域名

    ? ??pt:經(jīng)緯度字符串 (緯度,經(jīng)度)

    ? ??d=球面距離
    ?
    4.其它

    關(guān)于 Cartesian Tiers 笛卡爾層 ?和 ?GeoHash算法? 實現(xiàn)原理可以參考: http://blog.csdn.net/a221133/article/details/14525197

    總結(jié)

    以上是生活随笔為你收集整理的Solr4.7实现LBS(地理位置搜索)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。