|
Lines 85-99
sub build_query {
Link Here
|
| 85 |
$query = '*' unless defined $query; |
85 |
$query = '*' unless defined $query; |
| 86 |
|
86 |
|
| 87 |
my $res; |
87 |
my $res; |
|
|
88 |
my $fields = $self->_search_fields({ |
| 89 |
is_opac => $options{is_opac}, |
| 90 |
weighted_fields => $options{weighted_fields}, |
| 91 |
}); |
| 92 |
if ($options{whole_record}) { |
| 93 |
push @$fields, 'marc_data_array.*'; |
| 94 |
} |
| 88 |
$res->{query} = { |
95 |
$res->{query} = { |
| 89 |
query_string => { |
96 |
query_string => { |
| 90 |
query => $query, |
97 |
query => $query, |
| 91 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
98 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
| 92 |
default_operator => 'AND', |
99 |
default_operator => 'AND', |
| 93 |
fields => $self->_search_fields({ is_opac => $options{is_opac}, weighted_fields => $options{weighted_fields} }), |
100 |
fields => $fields, |
| 94 |
lenient => JSON::true, |
101 |
lenient => JSON::true, |
| 95 |
analyze_wildcard => JSON::true, |
102 |
analyze_wildcard => JSON::true, |
| 96 |
fields => $options{fields} || [], |
|
|
| 97 |
} |
103 |
} |
| 98 |
}; |
104 |
}; |
| 99 |
|
105 |
|
|
Lines 182-188
sub build_browse_query {
Link Here
|
| 182 |
$stopwords_removed, $query_type |
188 |
$stopwords_removed, $query_type |
| 183 |
) |
189 |
) |
| 184 |
= $builder->build_query_compat( \@operators, \@operands, \@indexes, |
190 |
= $builder->build_query_compat( \@operators, \@operands, \@indexes, |
| 185 |
\@limits, \@sort_by, $scan, $lang ); |
191 |
\@limits, \@sort_by, $scan, $lang, $params ); |
| 186 |
|
192 |
|
| 187 |
This handles a search using the same api as L<C4::Search::buildQuery> does. |
193 |
This handles a search using the same api as L<C4::Search::buildQuery> does. |
| 188 |
|
194 |
|
|
Lines 204-210
sub build_query_compat {
Link Here
|
| 204 |
my @index_params = $self->_convert_index_fields(@$indexes); |
210 |
my @index_params = $self->_convert_index_fields(@$indexes); |
| 205 |
my $limits = $self->_fix_limit_special_cases($orig_limits); |
211 |
my $limits = $self->_fix_limit_special_cases($orig_limits); |
| 206 |
if ( $params->{suppress} ) { push @$limits, "suppress:0"; } |
212 |
if ( $params->{suppress} ) { push @$limits, "suppress:0"; } |
| 207 |
|
|
|
| 208 |
# Merge the indexes in with the search terms and the operands so that |
213 |
# Merge the indexes in with the search terms and the operands so that |
| 209 |
# each search thing is a handy unit. |
214 |
# each search thing is a handy unit. |
| 210 |
unshift @$operators, undef; # The first one can't have an op |
215 |
unshift @$operators, undef; # The first one can't have an op |
|
Lines 237-242
sub build_query_compat {
Link Here
|
| 237 |
$options{sort} = \@sort_params; |
242 |
$options{sort} = \@sort_params; |
| 238 |
$options{is_opac} = $params->{is_opac}; |
243 |
$options{is_opac} = $params->{is_opac}; |
| 239 |
$options{weighted_fields} = $params->{weighted_fields}; |
244 |
$options{weighted_fields} = $params->{weighted_fields}; |
|
|
245 |
$options{whole_record} = $params->{whole_record}; |
| 240 |
my $query = $self->build_query( $query_str, %options ); |
246 |
my $query = $self->build_query( $query_str, %options ); |
| 241 |
|
247 |
|
| 242 |
# We roughly emulate the CGI parameters of the zebra query builder |
248 |
# We roughly emulate the CGI parameters of the zebra query builder |
|
Lines 1040-1054
sub _search_fields {
Link Here
|
| 1040 |
$params //= { |
1046 |
$params //= { |
| 1041 |
is_opac => 0, |
1047 |
is_opac => 0, |
| 1042 |
weighted_fields => 0, |
1048 |
weighted_fields => 0, |
|
|
1049 |
whole_record => 0, |
| 1043 |
# This is a hack for authorities build_authorities_query |
1050 |
# This is a hack for authorities build_authorities_query |
| 1044 |
# can hopefully be removed in the future |
1051 |
# can hopefully be removed in the future |
| 1045 |
subfield => undef, |
1052 |
subfield => undef, |
| 1046 |
}; |
1053 |
}; |
| 1047 |
|
|
|
| 1048 |
my $cache = Koha::Caches->get_instance(); |
1054 |
my $cache = Koha::Caches->get_instance(); |
| 1049 |
my $cache_key = 'elasticsearch_search_fields' . ($params->{is_opac} ? '_opac' : '_staff_client'); |
1055 |
my $cache_key = 'elasticsearch_search_fields' . ($params->{is_opac} ? '_opac' : '_staff_client'); |
| 1050 |
my $search_fields = $cache->get_from_cache($cache_key, { unsafe => 1 }); |
1056 |
my $search_fields = $cache->get_from_cache($cache_key, { unsafe => 1 }); |
| 1051 |
|
|
|
| 1052 |
if (!$search_fields) { |
1057 |
if (!$search_fields) { |
| 1053 |
# The reason we don't use Koha::SearchFields->search here is we don't |
1058 |
# The reason we don't use Koha::SearchFields->search here is we don't |
| 1054 |
# want or need resultset wrapped as Koha::SearchField object. |
1059 |
# want or need resultset wrapped as Koha::SearchField object. |
|
Lines 1096-1102
sub _search_fields {
Link Here
|
| 1096 |
} @{$search_fields} |
1101 |
} @{$search_fields} |
| 1097 |
]; |
1102 |
]; |
| 1098 |
} |
1103 |
} |
| 1099 |
|
|
|
| 1100 |
if ($params->{weighted_fields}) { |
1104 |
if ($params->{weighted_fields}) { |
| 1101 |
return [map { join('^', @{$_}) } @{$search_fields}]; |
1105 |
return [map { join('^', @{$_}) } @{$search_fields}]; |
| 1102 |
} |
1106 |
} |