[英]Solr query to calculate geo distance between two points
我有兩個營業地點的經緯度,想計算它們之間的距離。 我如何使用 solr 查詢來做到這一點。
我得到了從一個點(緯度,經度)獲取所有最近位置的查詢。
但是想要查詢以獲取兩點之間的距離。
下面是從一個點獲取位置的示例代碼片段
// 樣本位置
location = new double[]{lat, long};
SolrQuery query = new SolrQuery("{!func}geodist()");
query.set("fq","query");
query.set("sfield", "location");
query.set("pt", location );
query.setSortField("score", ORDER.asc);
query.setFields("score", "id");
SolrDocumentList list = solrServer.query(query).getResults();
要返回距離,您應該將geodist()
函數添加到fl
字段列表查詢字段,如下所示:
query.set("fl","*,distance:geodist()")
“距離”是要返回geodist()
結果的字段名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.