文档

OpsGeoPoint

更新时间:

简介

OpsGeoPoint对应于opensearch中的GEO_POINT数据类型,用于表示一个点的地理位置坐标。

构造函数

函数原型

函数简介

OpsGeoPoint(double longitude, double latitude)

根据位置的经度和纬度构造OpsGeoPoint

函数列表

函数原型

函数简介

double getLongitude()

获取经度的值

double getLatitude()

获取纬度的值

函数详情

OpsGeoPoint(double longitude, double latitude)

根据位置的精度和维度构造OpsGeoPoint。目前OpsGeoPoint主要用户从doc中获取GEO_POINT字段。

参数列表:

longitude — 经度latitude — 纬度

double getLongitude()

获取位置中的经度。返回值:返回经度值。

代码示例:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.framework.OpsRequest;
import com.aliyun.opensearch.cava.framework.OpsDoc;
import com.aliyun.opensearch.cava.framework.OpsGeoPoint;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return params.getDoc().requireAttribute("location");
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        OpsGeoPoint geopointValue = doc.docFieldGeoPoint("location");
        if (geopointValue == null) {
            doc.trace("geopoint is null");
        } else {
            doc.trace("geopoint longitude: ", geopointValue.getLongitude());
        }
        return 0.0;
    }
}

double getLatitude()

获取位置中的纬度。返回值:返回维度值。

代码示例:

package users.scorer;
import com.aliyun.opensearch.cava.framework.OpsScoreParams;
import com.aliyun.opensearch.cava.framework.OpsScorerInitParams;
import com.aliyun.opensearch.cava.framework.OpsRequest;
import com.aliyun.opensearch.cava.framework.OpsDoc;
import com.aliyun.opensearch.cava.framework.OpsGeoPoint;
class BasicSimilarityScorer {
    boolean init(OpsScorerInitParams params) {
        return params.getDoc().requireAttribute("location");
    }
    double score(OpsScoreParams params) {
        OpsDoc doc = params.getDoc();
        OpsGeoPoint geopointValue = doc.docFieldGeoPoint("location");
        if (geopointValue == null) {
            doc.trace("geopoint is null");
        } else {
            doc.trace("geopoint latitude: ", geopointValue.getLatitude());
        }
        return 0.0;
    }
}
  • 本页导读 (0)
文档反馈