proximitySearch method
dynamic
proximitySearch(
- dynamic selectQuery,
- GlobalSearchParameters params,
- LocalSqlDataStore sql
Implementation
proximitySearch(
selectQuery, GlobalSearchParameters params, LocalSqlDataStore sql) {
if (!params.isProximityEnabled) {
return null;
} else if (params.isProximityEnabled) {
selectQuery = super.sql.individual.select().join([
joinIndividualAddress(sql),
leftOuterJoin(
sql.projectBeneficiary,
sql.projectBeneficiary.beneficiaryClientReferenceId
.equalsExp(sql.individual.clientReferenceId))
])
..where(buildAnd([
sql.address.relatedClientReferenceId.isNotNull(),
sql.individual.clientReferenceId.isNotNull(),
if (params.latitude != null &&
params.longitude != null &&
params.maxRadius != null)
CustomExpression<bool>('''
(6371393 * acos(
cos(${params.latitude! * math.pi / 180.0}) * cos((address.latitude * ${math.pi / 180.0}))
* cos((address.longitude * ${math.pi / 180.0}) - ${params.longitude! * math.pi / 180.0})
+ sin(${params.latitude! * math.pi / 180.0}) * sin((address.latitude * ${math.pi / 180.0}))
)) <= ${params.maxRadius!}
'''),
if (params.latitude != null &&
params.longitude != null &&
params.maxRadius != null)
sql.address.longitude.isNotNull(),
sql.address.latitude.isNotNull(),
]))
..orderBy([
if (params.latitude != null &&
params.longitude != null &&
params.maxRadius != null)
OrderingTerm(
expression: CustomExpression<double>('''
(6371393 * acos(
cos(${params.latitude! * math.pi / 180.0}) * cos((address.latitude * ${math.pi / 180.0}))
* cos((address.longitude * ${math.pi / 180.0}) - ${params.longitude! * math.pi / 180.0})
+ sin(${params.latitude! * math.pi / 180.0}) * sin((address.latitude * ${math.pi / 180.0}))
))
'''),
mode: OrderingMode.asc,
),
]);
}
return selectQuery;
}