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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-3 / +35 lines)
Lines 215-224 sub get_elasticsearch_mappings { Link Here
215
                    $es_type = 'cn_sort';
215
                    $es_type = 'cn_sort';
216
                } elsif ($type eq 'geo_point') {
216
                } elsif ($type eq 'geo_point') {
217
                    $es_type = 'geo_point';
217
                    $es_type = 'geo_point';
218
                }
219
220
                if ($type eq 'geo_point') {
221
                    $name =~ s/_(lat|lon)$//;
218
                    $name =~ s/_(lat|lon)$//;
219
                } elsif ($type eq 'geo_shape') {
220
                    $es_type = 'geo_shape';
221
                    $name =~ s/_(north|south|east|west)ernmost$/_area/;
222
                }
222
                }
223
223
224
                if ($search) {
224
                if ($search) {
Lines 789-794 sub marc_records_to_documents { Link Here
789
            delete $record_document->{$field};
789
            delete $record_document->{$field};
790
        }
790
        }
791
791
792
        my %shape_bounds;
793
        foreach my $field ( @{ $rules->{geo_shape} } ) {
794
            next unless $record_document->{$field};
795
            $field =~ /([^_]+)_(north|south|east|west)ernmost$/;
796
            my $geofield = $1;
797
            my $direction = $2;
798
            $shape_bounds{$geofield}{$direction} = $record_document->{$field};
799
            delete $record_document->{$field};
800
        }
801
        for my $geofield (keys %shape_bounds) {
802
            my %bounds = %{$shape_bounds{$geofield}};
803
            if (%bounds == 4) {
804
                my @shapes;
805
                for my $i (0..scalar($bounds{north}->@*) - 1) {
806
                    $shapes[$i] = [
807
                        [ 0+$bounds{west}[$i], 0+$bounds{north}[$i] ],
808
                        [ 0+$bounds{east}[$i], 0+$bounds{south}[$i] ],
809
                    ];
810
                }
811
                my $es_field = $geofield . '_area';
812
                $record_document->{$es_field} = [map {
813
                    +{
814
                        type => 'envelope',
815
                        coordinates => $_,
816
                    }
817
                } @shapes];
818
            }
819
        }
820
792
        # Remove duplicate values and collapse sort fields
821
        # Remove duplicate values and collapse sort fields
793
        foreach my $field (keys %{$record_document}) {
822
        foreach my $field (keys %{$record_document}) {
794
            if (ref($record_document->{$field}) eq 'ARRAY') {
823
            if (ref($record_document->{$field}) eq 'ARRAY') {
Lines 1127-1132 sub _get_marc_mapping_rules { Link Here
1127
        elsif ($type eq 'geo_point') {
1156
        elsif ($type eq 'geo_point') {
1128
            push @{$rules->{geo_point}}, $name;
1157
            push @{$rules->{geo_point}}, $name;
1129
        }
1158
        }
1159
        elsif ($type eq 'geo_shape') {
1160
            push @{$rules->{geo_shape}}, $name;
1161
        }
1130
        elsif ($type eq 'boolean') {
1162
        elsif ($type eq 'boolean') {
1131
            # boolean gets special handling, if value doesn't exist for a field,
1163
            # boolean gets special handling, if value doesn't exist for a field,
1132
            # it is set to false
1164
            # it is set to false
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-9 / +22 lines)
Lines 1417-1433 sub _rebuild_to_es_advanced_query { Link Here
1417
    $query_string->{query} = '*' unless $query_string->{query};
1417
    $query_string->{query} = '*' unless $query_string->{query};
1418
    delete $res->{query}->{query_string};
1418
    delete $res->{query}->{query_string};
1419
1419
1420
    my %filter;
1420
    my @should;
1421
    for my $advanced_query (@$es_advanced_searches) {
1421
    for my $advanced_query (@$es_advanced_searches) {
1422
        if ( $advanced_query->{field} eq 'geolocation' ) {
1422
        if ( $advanced_query->{field} eq 'geolocation' ) {
1423
            my ( $lat, $lon, $distance ) = map { $_ =~ /:(.*)\*/ } split( '\s+', $advanced_query->{operand} );
1423
            my ( $lat, $lon, $distance ) = map { $_ =~ /:(.*)\*/ } split( '\s+', $advanced_query->{operand} );
1424
            $filter{geo_distance} = {
1424
            push @should,
1425
                distance    => $distance,
1425
                {
1426
                geolocation => {
1426
                    geo_distance => {
1427
                    lat => $lat,
1427
                        distance    => $distance,
1428
                    lon => $lon,
1428
                        geolocation => {
1429
                }
1429
                            lat => $lat,
1430
            };
1430
                            lon => $lon,
1431
                        }
1432
                    }
1433
                },
1434
                {
1435
                    geo_distance => {
1436
                        distance    => $distance,
1437
                        geolocation_area => {
1438
                            lat => $lat,
1439
                            lon => $lon,
1440
                        }
1441
                    }
1442
                };
1431
        } else {
1443
        } else {
1432
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1444
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1433
        }
1445
        }
Lines 1436-1442 sub _rebuild_to_es_advanced_query { Link Here
1436
    $res->{query} = {
1448
    $res->{query} = {
1437
        bool => {
1449
        bool => {
1438
            must   => { query_string => $query_string },
1450
            must   => { query_string => $query_string },
1439
            filter => \%filter,
1451
            should => \@should,
1452
            minimum_should_match => 1,
1440
        }
1453
        }
1441
    };
1454
    };
1442
1455
(-)a/admin/searchengine/elasticsearch/field_config.yaml (+2 lines)
Lines 43-48 search: Link Here
43
        normalizer: icu_folding_normalizer
43
        normalizer: icu_folding_normalizer
44
  geo_point:
44
  geo_point:
45
     type: geo_point
45
     type: geo_point
46
  geo_shape:
47
     type: geo_shape
46
  default:
48
  default:
47
    type: text
49
    type: text
48
    analyzer: analyzer_standard
50
    analyzer: analyzer_standard
(-)a/admin/searchengine/elasticsearch/mappings.yaml (+36 lines)
Lines 1916-1921 biblios: Link Here
1916
    opac: 1
1916
    opac: 1
1917
    staff_client: 1
1917
    staff_client: 1
1918
    type: ''
1918
    type: ''
1919
  geolocation_westernmost:
1920
    label: geolocation_westernmost
1921
    mappings:
1922
      - facet: ''
1923
        marc_field: 034d
1924
        marc_type: marc21
1925
        sort: 0
1926
        suggestible: ''
1927
    type: geo_shape
1928
  geolocation_easternmost:
1929
    label: geolocation_easternmost
1930
    mappings:
1931
      - facet: ''
1932
        marc_field: 034e
1933
        marc_type: marc21
1934
        sort: 0
1935
        suggestible: ''
1936
    type: geo_shape
1937
  geolocation_northernmost:
1938
    label: geolocation_northernmost
1939
    mappings:
1940
      - facet: ''
1941
        marc_field: 034f
1942
        marc_type: marc21
1943
        sort: 0
1944
        suggestible: ''
1945
    type: geo_shape
1946
  geolocation_southernmost:
1947
    label: geolocation_southernmost
1948
    mappings:
1949
      - facet: ''
1950
        marc_field: 034g
1951
        marc_type: marc21
1952
        sort: 0
1953
        suggestible: ''
1954
    type: geo_shape
1919
  geolocation_lat:
1955
  geolocation_lat:
1920
    label: geolocation_lat
1956
    label: geolocation_lat
1921
    mappings:
1957
    mappings:
(-)a/installer/data/mysql/kohastructure.sql (-2 / +1 lines)
Lines 5660-5666 CREATE TABLE `search_field` ( Link Here
5660
  `id` int(11) NOT NULL AUTO_INCREMENT,
5660
  `id` int(11) NOT NULL AUTO_INCREMENT,
5661
  `name` varchar(255) NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
5661
  `name` varchar(255) NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
5662
  `label` varchar(255) NOT NULL COMMENT 'the human readable name of the field, for display',
5662
  `label` varchar(255) NOT NULL COMMENT 'the human readable name of the field, for display',
5663
  `type` enum('','string','date','number','boolean','sum','isbn','stdno','year','callnumber','geo_point') NOT NULL COMMENT 'what type of data this holds, relevant when storing it in the search engine',
5663
  `type` enum('','string','date','number','boolean','sum','isbn','stdno','year','callnumber','geo_point','geo_shape') NOT NULL COMMENT 'what type of data this holds, relevant when storing it in the search engine',
5664
  `weight` decimal(5,2) DEFAULT NULL,
5664
  `weight` decimal(5,2) DEFAULT NULL,
5665
  `facet_order` tinyint(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
5665
  `facet_order` tinyint(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
5666
  `staff_client` tinyint(1) NOT NULL DEFAULT 1,
5666
  `staff_client` tinyint(1) NOT NULL DEFAULT 1,
5667
- 

Return to bug 37985