4
4
package com.jillesvangurp.ktsearch
5
5
6
6
import com.jillesvangurp.ktsearch.repository.ModelSerializationStrategy
7
+ import com.jillesvangurp.searchdsls.querydsl.GeoTileGridAgg
8
+ import com.jillesvangurp.searchdsls.querydsl.Shape
7
9
import com.jillesvangurp.serializationext.DEFAULT_JSON
8
10
import kotlinx.coroutines.flow.Flow
9
11
import kotlinx.coroutines.flow.map
@@ -131,14 +133,15 @@ inline fun <reified T> Flow<SearchResponse.Hit>.parseHits(
131
133
): Flow <T > = map {
132
134
it.parseHit<T >()
133
135
}
136
+
134
137
fun <T > Flow<SearchResponse.Hit>.parseHits (
135
138
deserializationStrategy : DeserializationStrategy <T >,
136
139
json : Json = DEFAULT_JSON
137
140
): Flow <T > = map {
138
141
it.parseHit(deserializationStrategy, json)
139
142
}
140
143
141
- fun <T : Any > Flow<SearchResponse.Hit>.parseHits (deserializationStrategy : ModelSerializationStrategy <T >): Flow <T > =
144
+ fun <T : Any > Flow<SearchResponse.Hit>.parseHits (deserializationStrategy : ModelSerializationStrategy <T >): Flow <T > =
142
145
mapNotNull { hit ->
143
146
hit.source?.let { deserializationStrategy.deSerialize(it) }
144
147
}
@@ -381,51 +384,51 @@ data class ExtendedStatsBucketResult(
381
384
@EncodeDefault
382
385
val max : Double = 0.0 ,
383
386
@EncodeDefault
384
- val avg : Double = 0.0 ,
387
+ val avg : Double = 0.0 ,
385
388
@EncodeDefault
386
- val sum : Double = 0.0 ,
389
+ val sum : Double = 0.0 ,
387
390
@SerialName(" sum_of_squares" )
388
391
@EncodeDefault
389
- val sumOfSquares : Double = 0.0 ,
392
+ val sumOfSquares : Double = 0.0 ,
390
393
@EncodeDefault
391
- val variance : Double = 0.0 ,
394
+ val variance : Double = 0.0 ,
392
395
@SerialName(" variance_population" )
393
396
@EncodeDefault
394
- val variancePopulation : Double = 0.0 ,
397
+ val variancePopulation : Double = 0.0 ,
395
398
@SerialName(" variance_sampling" )
396
399
@EncodeDefault
397
- val varianceSampling : Double = 0.0 ,
400
+ val varianceSampling : Double = 0.0 ,
398
401
@SerialName(" std_deviation" )
399
402
@EncodeDefault
400
- val stdDeviation : Double = 0.0 ,
403
+ val stdDeviation : Double = 0.0 ,
401
404
@SerialName(" std_deviation_population" )
402
405
@EncodeDefault
403
- val stdDeviationPopulation : Double = 0.0 ,
406
+ val stdDeviationPopulation : Double = 0.0 ,
404
407
@SerialName(" std_deviation_sampling" )
405
408
@EncodeDefault
406
- val stdDeviationSampling : Double = 0.0 ,
409
+ val stdDeviationSampling : Double = 0.0 ,
407
410
@SerialName(" std_deviation_bounds" )
408
411
@EncodeDefault
409
412
val stdDeviationBounds : Bounds = Bounds ()
410
413
) {
411
414
@Serializable
412
415
data class Bounds (
413
416
@EncodeDefault
414
- val upper : Double = 0.0 ,
417
+ val upper : Double = 0.0 ,
415
418
@EncodeDefault
416
- val lower : Double = 0.0 ,
419
+ val lower : Double = 0.0 ,
417
420
@SerialName(" upper_population" )
418
421
@EncodeDefault
419
- val upperPopulation : Double = 0.0 ,
422
+ val upperPopulation : Double = 0.0 ,
420
423
@SerialName(" lower_population" )
421
424
@EncodeDefault
422
- val lowerPopulation : Double = 0.0 ,
425
+ val lowerPopulation : Double = 0.0 ,
423
426
@SerialName(" upper_sampling" )
424
427
@EncodeDefault
425
- val upperSampling : Double = 0.0 ,
428
+ val upperSampling : Double = 0.0 ,
426
429
@SerialName(" lower_sampling" )
427
430
@EncodeDefault
428
- val lowerSampling : Double = 0.0 ,
431
+ val lowerSampling : Double = 0.0 ,
429
432
)
430
433
}
431
434
@@ -446,6 +449,42 @@ fun Aggregations?.topHitResult(name: String, json: Json = DEFAULT_JSON): TopHits
446
449
fun Aggregations?.topHitResult (name : Enum <* >, json : Json = DEFAULT_JSON ): TopHitsAggregationResult =
447
450
getAggResult(name.name, json)
448
451
452
+ @Serializable
453
+ data class GeoTileGridBucket (
454
+ val key : String ,
455
+ @SerialName(" doc_count" )
456
+ val docCount : Long ,
457
+ )
458
+
459
+ @Serializable
460
+ data class GeoTileGridResult (
461
+ override val buckets : List <JsonObject >
462
+ ) : BucketAggregationResult<GeoTileGridBucket>
463
+
464
+ val GeoTileGridResult .parsedBuckets get() = buckets.map { Bucket (it, GeoTileGridBucket .serializer()) }
465
+
466
+ fun Aggregations?.geoTileGridResult (name : String , json : Json = DEFAULT_JSON ): GeoTileGridResult =
467
+ getAggResult(name, json)
468
+
469
+ fun Aggregations?.geoTileGridResult (name : Enum <* >, json : Json = DEFAULT_JSON ): GeoTileGridResult =
470
+ getAggResult(name, json)
471
+
472
+
473
+ @Serializable
474
+ data class GeoCentroidResult (
475
+ val location : Point ,
476
+ val count : Long ,
477
+
478
+ ) {
479
+ val pointCoordinate get() = doubleArrayOf(location.lon, location.lat)
480
+
481
+ @Serializable
482
+ data class Point (val lat : Double , val lon : Double )
483
+ }
484
+
485
+ fun Aggregations?.geoCentroid (name : String ) = getAggResult<GeoCentroidResult >(name)
486
+ fun Aggregations?.geoCentroid (name : Enum <* >) = getAggResult<GeoCentroidResult >(name)
487
+
449
488
@Serializable
450
489
data class SumAggregationResult (
451
490
val value : Double ,
0 commit comments