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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-3 / +36 lines)
Lines 221-230 sub get_elasticsearch_mappings { Link Here
221
                    $es_type = 'cn_sort';
221
                    $es_type = 'cn_sort';
222
                } elsif ( $type eq 'geo_point' ) {
222
                } elsif ( $type eq 'geo_point' ) {
223
                    $es_type = 'geo_point';
223
                    $es_type = 'geo_point';
224
                }
225
226
                if ( $type eq 'geo_point' ) {
227
                    $name =~ s/_(lat|lon)$//;
224
                    $name =~ s/_(lat|lon)$//;
225
                } elsif ( $type eq 'geo_shape' ) {
226
                    $es_type = 'geo_shape';
227
                    $name =~ s/_(north|south|east|west)ernmost$/_area/;
228
                }
228
                }
229
229
230
                if ($search) {
230
                if ($search) {
Lines 878-883 sub marc_records_to_documents { Link Here
878
            delete $record_document->{$field};
878
            delete $record_document->{$field};
879
        }
879
        }
880
880
881
        my %shape_bounds;
882
        foreach my $field ( @{ $rules->{geo_shape} } ) {
883
            next unless $record_document->{$field};
884
            $field =~ /([^_]+)_(north|south|east|west)ernmost$/;
885
            my $geofield  = $1;
886
            my $direction = $2;
887
            $shape_bounds{$geofield}{$direction} = $record_document->{$field};
888
            delete $record_document->{$field};
889
        }
890
        for my $geofield ( keys %shape_bounds ) {
891
            my %bounds = %{ $shape_bounds{$geofield} };
892
            if ( %bounds == 4 ) {
893
                my @shapes;
894
                for my $i ( 0 .. scalar( $bounds{north}->@* ) - 1 ) {
895
                    $shapes[$i] = [
896
                        [ 0 + $bounds{west}[$i], 0 + $bounds{north}[$i] ],
897
                        [ 0 + $bounds{east}[$i], 0 + $bounds{south}[$i] ],
898
                    ];
899
                }
900
                my $es_field = $geofield . '_area';
901
                $record_document->{$es_field} = [
902
                    map {
903
                        +{
904
                            type        => 'envelope',
905
                            coordinates => $_,
906
                        }
907
                    } @shapes
908
                ];
909
            }
910
        }
911
881
        # Remove duplicate values and collapse sort fields
912
        # Remove duplicate values and collapse sort fields
882
        foreach my $field ( keys %{$record_document} ) {
913
        foreach my $field ( keys %{$record_document} ) {
883
            if ( ref( $record_document->{$field} ) eq 'ARRAY' ) {
914
            if ( ref( $record_document->{$field} ) eq 'ARRAY' ) {
Lines 1255-1260 sub _get_marc_mapping_rules { Link Here
1255
                push @{ $rules->{isbn} }, $name;
1286
                push @{ $rules->{isbn} }, $name;
1256
            } elsif ( $type eq 'geo_point' ) {
1287
            } elsif ( $type eq 'geo_point' ) {
1257
                push @{ $rules->{geo_point} }, $name;
1288
                push @{ $rules->{geo_point} }, $name;
1289
            } elsif ( $type eq 'geo_shape' ) {
1290
                push @{ $rules->{geo_shape} }, $name;
1258
            } elsif ( $type eq 'boolean' ) {
1291
            } elsif ( $type eq 'boolean' ) {
1259
1292
1260
                # boolean gets special handling, if value doesn't exist for a field,
1293
                # boolean gets special handling, if value doesn't exist for a field,
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-9 / +22 lines)
Lines 1492-1508 sub _rebuild_to_es_advanced_query { Link Here
1492
    $query_string->{query} = '*' unless $query_string->{query};
1492
    $query_string->{query} = '*' unless $query_string->{query};
1493
    delete $res->{query}->{query_string};
1493
    delete $res->{query}->{query_string};
1494
1494
1495
    my %filter;
1495
    my @should;
1496
    for my $advanced_query (@$es_advanced_searches) {
1496
    for my $advanced_query (@$es_advanced_searches) {
1497
        if ( $advanced_query->{field} eq 'geolocation' ) {
1497
        if ( $advanced_query->{field} eq 'geolocation' ) {
1498
            my ( $lat, $lon, $distance ) = map { $_ =~ /:(.*)\*/ } split( '\s+', $advanced_query->{operand} );
1498
            my ( $lat, $lon, $distance ) = map { $_ =~ /:(.*)\*/ } split( '\s+', $advanced_query->{operand} );
1499
            $filter{geo_distance} = {
1499
            push @should,
1500
                distance    => $distance,
1500
                {
1501
                geolocation => {
1501
                    geo_distance => {
1502
                    lat => $lat,
1502
                        distance    => $distance,
1503
                    lon => $lon,
1503
                        geolocation => {
1504
                }
1504
                            lat => $lat,
1505
            };
1505
                            lon => $lon,
1506
                        }
1507
                    }
1508
                },
1509
                {
1510
                    geo_distance => {
1511
                        distance    => $distance,
1512
                        geolocation_area => {
1513
                            lat => $lat,
1514
                            lon => $lon,
1515
                        }
1516
                    }
1517
                };
1506
        } else {
1518
        } else {
1507
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1519
            warn "unknown advanced ElasticSearch query: " . join( ', ', %$advanced_query );
1508
        }
1520
        }
Lines 1511-1517 sub _rebuild_to_es_advanced_query { Link Here
1511
    $res->{query} = {
1523
    $res->{query} = {
1512
        bool => {
1524
        bool => {
1513
            must   => { query_string => $query_string },
1525
            must   => { query_string => $query_string },
1514
            filter => \%filter,
1526
            should => \@should,
1527
            minimum_should_match => 1,
1515
        }
1528
        }
1516
    };
1529
    };
1517
1530
(-)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 5812-5818 CREATE TABLE `search_field` ( Link Here
5812
  `id` int(11) NOT NULL AUTO_INCREMENT,
5812
  `id` int(11) NOT NULL AUTO_INCREMENT,
5813
  `name` varchar(255) NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
5813
  `name` varchar(255) NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
5814
  `label` varchar(255) NOT NULL COMMENT 'the human readable name of the field, for display',
5814
  `label` varchar(255) NOT NULL COMMENT 'the human readable name of the field, for display',
5815
  `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',
5815
  `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',
5816
  `weight` decimal(5,2) DEFAULT NULL,
5816
  `weight` decimal(5,2) DEFAULT NULL,
5817
  `facet_order` tinyint(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
5817
  `facet_order` tinyint(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
5818
  `staff_client` tinyint(1) NOT NULL DEFAULT 1,
5818
  `staff_client` tinyint(1) NOT NULL DEFAULT 1,
5819
- 

Return to bug 37985