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 929-934
operand.
Link Here
|
929 |
|
932 |
|
930 |
sub _create_query_string { |
933 |
sub _create_query_string { |
931 |
my ( $self, @queries ) = @_; |
934 |
my ( $self, @queries ) = @_; |
|
|
935 |
$es_advanced_searches = []; |
936 |
my @string_queries; |
937 |
foreach my $q (@queries) { |
938 |
if ($q->{field} && $q->{field} eq 'geolocation') { |
939 |
push(@$es_advanced_searches, $q); |
940 |
} else { |
941 |
push(@string_queries, $q) |
942 |
} |
943 |
} |
944 |
|
945 |
@queries = @string_queries; |
932 |
|
946 |
|
933 |
map { |
947 |
map { |
934 |
my $otor = $_->{operator} ? $_->{operator} . ' ' : ''; |
948 |
my $otor = $_->{operator} ? $_->{operator} . ' ' : ''; |
Lines 1082-1088
sub _fix_limit_special_cases {
Link Here
|
1082 |
|
1096 |
|
1083 |
my @new_lim; |
1097 |
my @new_lim; |
1084 |
foreach my $l (@$limits) { |
1098 |
foreach my $l (@$limits) { |
1085 |
|
|
|
1086 |
# This is set up by opac-search.pl |
1099 |
# This is set up by opac-search.pl |
1087 |
if ( $l =~ /^yr,st-numeric,ge[=:]/ ) { |
1100 |
if ( $l =~ /^yr,st-numeric,ge[=:]/ ) { |
1088 |
my ( $start, $end ) = |
1101 |
my ( $start, $end ) = |
Lines 1338-1341
sub _search_fields {
Link Here
|
1338 |
} |
1351 |
} |
1339 |
} |
1352 |
} |
1340 |
|
1353 |
|
|
|
1354 |
sub _rebuild_to_es_advanced_query { |
1355 |
my ($res) = @_; |
1356 |
my $query_string = $res->{query}->{query_string}; |
1357 |
$query_string->{query} = '*' unless $query_string->{query}; |
1358 |
delete $res->{query}->{query_string}; |
1359 |
|
1360 |
my %filter; |
1361 |
for my $advanced_query (@$es_advanced_searches) { |
1362 |
if ( $advanced_query->{field} eq 'geolocation') { |
1363 |
my ($lat, $lon, $distance) = map { $_ =~ /:(.*)\*/ } split('\s+', $advanced_query->{operand}); |
1364 |
$filter{geo_distance} = { |
1365 |
distance => $distance, |
1366 |
geolocation => { |
1367 |
lat => $lat, |
1368 |
lon => $lon, |
1369 |
} |
1370 |
}; |
1371 |
} |
1372 |
else { |
1373 |
warn "unknown advanced ElasticSearch query: ".join(', ',%$advanced_query); |
1374 |
} |
1375 |
} |
1376 |
|
1377 |
$res->{query} = { |
1378 |
bool => { |
1379 |
must => { |
1380 |
query_string => $query_string |
1381 |
}, |
1382 |
filter => \%filter, |
1383 |
} |
1384 |
}; |
1385 |
|
1386 |
return $res; |
1387 |
} |
1388 |
|
1389 |
|
1341 |
1; |
1390 |
1; |