All Products
Search
Document Center

:OpsGeoPoint

Last Updated:Feb 06, 2023

Overview

The OpsGeoPoint class is equivalent to the GEO_POINT data type that is supported by OpenSearch. An OpsGeoPoint object represents the geographic coordinates of a point.

Constructor

Function

Description

OpsGeoPoint(double longitude, double latitude)

Creates an OpsGeoPoint object based on a specific longitude and latitude.

Functions

Function

Description

double getLongitude()

Obtains the longitude of a point.

double getLatitude()

Obtains the latitude of a point.

Function details

OpsGeoPoint(double longitude, double latitude)

Creates an OpsGeoPoint object based on a specific longitude and latitude. The OpsGeoPoint class allows you to obtain a field of the GEO_POINT type from a document.

Parameters:

longitude: the longitude of the point. latitude: the latitude of the point.

double getLongitude()

Obtains the longitude of a point. Return value: the longitude of the point.

Sample code:

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()

Obtains the latitude of a point. Return value: the latitude of the point.

Sample code:

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;
    }
}