概要
OpsGeoPoint クラスは、OpenSearch でサポートされている GEO_POINT データ型に相当します。OpsGeoPoint オブジェクトは、点の地理座標を表します。
コンストラクター
関数 | 説明 |
OpsGeoPoint(double longitude, double latitude) | 特定の経度と緯度に基づいて OpsGeoPoint オブジェクトを作成します。 |
関数
関数 | 説明 |
double getLongitude() | 点の経度を取得します。 |
double getLatitude() | 点の緯度を取得します。 |
関数の詳細
OpsGeoPoint(double longitude, double latitude)
特定の経度と緯度に基づいて OpsGeoPoint オブジェクトを作成します。OpsGeoPoint クラスを使用すると、ドキュメントから 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) {
// location 属性が必須であることを確認します。
return params.getDoc().requireAttribute("location");
}
double score(OpsScoreParams params) {
OpsDoc doc = params.getDoc();
OpsGeoPoint geopointValue = doc.docFieldGeoPoint("location");
if (geopointValue == null) {
// geopoint が null の場合の処理
doc.trace("geopoint is null");
} else {
// geopoint の経度を出力
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) {
// location 属性が必須であることを確認します。
return params.getDoc().requireAttribute("location");
}
double score(OpsScoreParams params) {
OpsDoc doc = params.getDoc();
OpsGeoPoint geopointValue = doc.docFieldGeoPoint("location");
if (geopointValue == null) {
// geopoint が null の場合の処理
doc.trace("geopoint is null");
} else {
// geopoint の緯度を出力
doc.trace("geopoint latitude: ", geopointValue.getLatitude());
}
return 0.0;
}
}