|
Lines 137-142
our %index_field_convert = (
Link Here
|
| 137 |
); |
137 |
); |
| 138 |
my $field_name_pattern = '[\w\-]+'; |
138 |
my $field_name_pattern = '[\w\-]+'; |
| 139 |
my $multi_field_pattern = "(?:\\.$field_name_pattern)*"; |
139 |
my $multi_field_pattern = "(?:\\.$field_name_pattern)*"; |
|
|
140 |
my $es_advanced_searches = []; |
| 140 |
|
141 |
|
| 141 |
=head2 get_index_field_convert |
142 |
=head2 get_index_field_convert |
| 142 |
|
143 |
|
|
Lines 245-250
sub build_query {
Link Here
|
| 245 |
or $display_library_facets eq 'holding' ) { |
246 |
or $display_library_facets eq 'holding' ) { |
| 246 |
$res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } }; |
247 |
$res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } }; |
| 247 |
} |
248 |
} |
|
|
249 |
|
| 250 |
$res = _rebuild_to_es_advanced_query($res) if @$es_advanced_searches ; |
| 248 |
return $res; |
251 |
return $res; |
| 249 |
} |
252 |
} |
| 250 |
|
253 |
|
|
Lines 930-935
operand.
Link Here
|
| 930 |
|
933 |
|
| 931 |
sub _create_query_string { |
934 |
sub _create_query_string { |
| 932 |
my ( $self, @queries ) = @_; |
935 |
my ( $self, @queries ) = @_; |
|
|
936 |
$es_advanced_searches = []; |
| 937 |
my @string_queries; |
| 938 |
foreach my $q (@queries) { |
| 939 |
if ($q->{field} && $q->{field} eq 'geolocation') { |
| 940 |
push(@$es_advanced_searches, $q); |
| 941 |
} else { |
| 942 |
push(@string_queries, $q) |
| 943 |
} |
| 944 |
} |
| 945 |
|
| 946 |
@queries = @string_queries; |
| 933 |
|
947 |
|
| 934 |
map { |
948 |
map { |
| 935 |
my $otor = $_->{operator} ? $_->{operator} . ' ' : ''; |
949 |
my $otor = $_->{operator} ? $_->{operator} . ' ' : ''; |
|
Lines 1083-1089
sub _fix_limit_special_cases {
Link Here
|
| 1083 |
|
1097 |
|
| 1084 |
my @new_lim; |
1098 |
my @new_lim; |
| 1085 |
foreach my $l (@$limits) { |
1099 |
foreach my $l (@$limits) { |
| 1086 |
|
|
|
| 1087 |
# This is set up by opac-search.pl |
1100 |
# This is set up by opac-search.pl |
| 1088 |
if ( $l =~ /^yr,st-numeric,ge[=:]/ ) { |
1101 |
if ( $l =~ /^yr,st-numeric,ge[=:]/ ) { |
| 1089 |
my ( $start, $end ) = |
1102 |
my ( $start, $end ) = |
|
Lines 1407-1410
sub _is_safe_to_auto_truncate {
Link Here
|
| 1407 |
return 1; |
1420 |
return 1; |
| 1408 |
} |
1421 |
} |
| 1409 |
|
1422 |
|
|
|
1423 |
sub _rebuild_to_es_advanced_query { |
| 1424 |
my ($res) = @_; |
| 1425 |
my $query_string = $res->{query}->{query_string}; |
| 1426 |
$query_string->{query} = '*' unless $query_string->{query}; |
| 1427 |
delete $res->{query}->{query_string}; |
| 1428 |
|
| 1429 |
my %filter; |
| 1430 |
for my $advanced_query (@$es_advanced_searches) { |
| 1431 |
if ( $advanced_query->{field} eq 'geolocation') { |
| 1432 |
my ($lat, $lon, $distance) = map { $_ =~ /:(.*)\*/ } split('\s+', $advanced_query->{operand}); |
| 1433 |
$filter{geo_distance} = { |
| 1434 |
distance => $distance, |
| 1435 |
geolocation => { |
| 1436 |
lat => $lat, |
| 1437 |
lon => $lon, |
| 1438 |
} |
| 1439 |
}; |
| 1440 |
} |
| 1441 |
else { |
| 1442 |
warn "unknown advanced ElasticSearch query: ".join(', ',%$advanced_query); |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
$res->{query} = { |
| 1447 |
bool => { |
| 1448 |
must => { |
| 1449 |
query_string => $query_string |
| 1450 |
}, |
| 1451 |
filter => \%filter, |
| 1452 |
} |
| 1453 |
}; |
| 1454 |
|
| 1455 |
return $res; |
| 1456 |
} |
| 1457 |
|
| 1458 |
|
| 1410 |
1; |
1459 |
1; |