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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-9 / +9 lines)
Lines 202-222 sub get_elasticsearch_mappings { Link Here
202
                # TODO be aware of date formats, but this requires pre-parsing
202
                # TODO be aware of date formats, but this requires pre-parsing
203
                # as ES will simply reject anything with an invalid date.
203
                # as ES will simply reject anything with an invalid date.
204
                my $es_type = 'text';
204
                my $es_type = 'text';
205
                if ($type eq 'boolean') {
205
                if ( $type eq 'boolean' ) {
206
                    $es_type = 'boolean';
206
                    $es_type = 'boolean';
207
                } elsif ($type eq 'number' || $type eq 'sum') {
207
                } elsif ( $type eq 'number' || $type eq 'sum' ) {
208
                    $es_type = 'integer';
208
                    $es_type = 'integer';
209
                } elsif ($type eq 'isbn' || $type eq 'stdno') {
209
                } elsif ( $type eq 'isbn' || $type eq 'stdno' ) {
210
                    $es_type = 'stdno';
210
                    $es_type = 'stdno';
211
                } elsif ($type eq 'year') {
211
                } elsif ( $type eq 'year' ) {
212
                    $es_type = 'year';
212
                    $es_type = 'year';
213
                } elsif ($type eq 'callnumber') {
213
                } elsif ( $type eq 'callnumber' ) {
214
                    $es_type = 'cn_sort';
214
                    $es_type = 'cn_sort';
215
                } elsif ($type eq 'geo_point') {
215
                } elsif ( $type eq 'geo_point' ) {
216
                    $es_type = 'geo_point';
216
                    $es_type = 'geo_point';
217
                }
217
                }
218
218
219
                if ($type eq 'geo_point') {
219
                if ( $type eq 'geo_point' ) {
220
                    $name =~ s/_(lat|lon)$//;
220
                    $name =~ s/_(lat|lon)$//;
221
                }
221
                }
222
222
Lines 741-753 sub marc_records_to_documents { Link Here
741
            }
741
            }
742
        }
742
        }
743
743
744
        foreach my $field (@{$rules->{geo_point}}) {
744
        foreach my $field ( @{ $rules->{geo_point} } ) {
745
            next unless $record_document->{$field};
745
            next unless $record_document->{$field};
746
            my $geofield = $field;
746
            my $geofield = $field;
747
            $geofield =~ s/_(lat|lon)$//;
747
            $geofield =~ s/_(lat|lon)$//;
748
            my $axis = $1;
748
            my $axis = $1;
749
            my $vals = $record_document->{$field};
749
            my $vals = $record_document->{$field};
750
            for my $i (0 .. @$vals - 1) {
750
            for my $i ( 0 .. @$vals - 1 ) {
751
                my $val = $record_document->{$field}[$i];
751
                my $val = $record_document->{$field}[$i];
752
                $record_document->{$geofield}[$i]{$axis} = $val;
752
                $record_document->{$geofield}[$i]{$axis} = $val;
753
            }
753
            }
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-14 / +10 lines)
Lines 936-945 sub _create_query_string { Link Here
936
    $es_advanced_searches = [];
936
    $es_advanced_searches = [];
937
    my @string_queries;
937
    my @string_queries;
938
    foreach my $q (@queries) {
938
    foreach my $q (@queries) {
939
        if ($q->{field} && $q->{field} eq 'geolocation') {
939
        if ( $q->{field} && $q->{field} eq 'geolocation' ) {
940
            push(@$es_advanced_searches, $q);
940
            push( @$es_advanced_searches, $q );
941
        } else {
941
        } else {
942
            push(@string_queries, $q)
942
            push( @string_queries, $q );
943
        }
943
        }
944
    }
944
    }
945
945
Lines 1428-1454 sub _rebuild_to_es_advanced_query { Link Here
1428
1428
1429
    my %filter;
1429
    my %filter;
1430
    for my $advanced_query (@$es_advanced_searches) {
1430
    for my $advanced_query (@$es_advanced_searches) {
1431
        if ( $advanced_query->{field} eq 'geolocation') {
1431
        if ( $advanced_query->{field} eq 'geolocation' ) {
1432
            my ($lat, $lon, $distance) = map { $_ =~ /:(.*)\*/ } split('\s+', $advanced_query->{operand});
1432
            my ( $lat, $lon, $distance ) = map { $_ =~ /:(.*)\*/ } split( '\s+', $advanced_query->{operand} );
1433
            $filter{geo_distance} = {
1433
            $filter{geo_distance} = {
1434
                distance => $distance,
1434
                distance    => $distance,
1435
                geolocation => {
1435
                geolocation => {
1436
                    lat => $lat,
1436
                    lat => $lat,
1437
                    lon => $lon,
1437
                    lon => $lon,
1438
                }
1438
                }
1439
            };
1439
            };
1440
        }
1440
        } else {
1441
        else {
1441
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1442
            warn "unknown advanced ElasticSearch query: ".join(', ',%$advanced_query);
1443
        }
1442
        }
1444
    }
1443
    }
1445
1444
1446
    $res->{query} = {
1445
    $res->{query} = {
1447
        bool => {
1446
        bool => {
1448
             must => {
1447
            must   => { query_string => $query_string },
1449
                 query_string =>  $query_string
1448
            filter => \%filter,
1450
             },
1451
             filter => \%filter,
1452
        }
1449
        }
1453
    };
1450
    };
1454
1451
1455
- 

Return to bug 36152