View | Details | Raw Unified | Return to bug 37537
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-8 / +26 lines)
Lines 1418-1431 sub _rebuild_to_es_advanced_query { Link Here
1418
    my %filter;
1418
    my %filter;
1419
    for my $advanced_query (@$es_advanced_searches) {
1419
    for my $advanced_query (@$es_advanced_searches) {
1420
        if ( $advanced_query->{field} eq 'geolocation' ) {
1420
        if ( $advanced_query->{field} eq 'geolocation' ) {
1421
            my ( $lat, $lon, $distance ) = map { $_ =~ /:(.*)\*/ } split( '\s+', $advanced_query->{operand} );
1421
            my %args = map { split ':' } map { s/\*$//r } split /\s+/, $advanced_query->{operand};
1422
            $filter{geo_distance} = {
1422
            if ($args{lat} and $args{lng} and $args{distance}) {
1423
                distance    => $distance,
1423
                $filter{geo_distance} = {
1424
                geolocation => {
1424
                    distance    => $args{distance},
1425
                    lat => $lat,
1425
                    geolocation => {
1426
                    lon => $lon,
1426
                        lat => $args{lat},
1427
                }
1427
                        lon => $args{lng},
1428
            };
1428
                    }
1429
                };
1430
            } elsif ($args{boundingbox}) {
1431
                my ($top_left_lat, $top_left_lon, $bottom_right_lat, $bottom_right_lon) = split ',', $args{boundingbox};
1432
                $filter{geo_bounding_box} = {
1433
                    'geolocation' => {
1434
                        'top_left' => {
1435
                          'lat' => $top_left_lat,
1436
                          'lon' => $top_left_lon,
1437
                        },
1438
                        'bottom_right' => {
1439
                          'lat' => $bottom_right_lat,
1440
                          'lon' => $bottom_right_lon,
1441
                        }
1442
                    },
1443
                };
1444
            } else {
1445
                warn "Unrecognized parameter set for geolocation queries: " . join(', ', keys %args);
1446
            }
1429
        } else {
1447
        } else {
1430
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1448
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1431
        }
1449
        }
(-)a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-1 / +32 lines)
Lines 369-373 subtest '_create_query_string' => sub { Link Here
369
369
370
};
370
};
371
371
372
subtest 'geolocation queries' => sub {
373
    my $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({
374
        index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX,
375
    });
376
377
    $qb->_create_query_string({
378
            'field'    => 'geolocation',
379
            'operand'  => 'lat:48.25* lng:16.35* distance:100km*'
380
    });
381
    my $query = $qb->build_query();
382
    is_deeply $query->{query}{bool}{filter}, {
383
        geo_distance => {
384
            distance => '100km',
385
            geolocation => { lat => 48.25, lon => 16.35 },
386
        }
387
    }, 'should be able to create "distance from a point" queries';
388
389
    $qb->_create_query_string({
390
        'field'    => 'geolocation',
391
        'operand'  => 'boundingbox:1,2,3,4*'
392
    });
393
    $query = $qb->build_query();
394
    is_deeply $query->{query}{bool}{filter}, {
395
        geo_bounding_box => {
396
            geolocation => {
397
                top_left => { lat => 1, lon => 2 },
398
                bottom_right => { lat => 3, lon => 4 },
399
            },
400
        }
401
    }, 'should be able to create "within a bounding box" queries';
402
};
403
372
404
373
1;
405
1;
374
- 

Return to bug 37537