@@ -, +, @@ --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 12 ++++++++++++ catalogue/search.pl | 5 ++++- .../intranet-tmpl/prog/en/modules/catalogue/advsearch.tt | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -92,6 +92,8 @@ sub build_query { default_operator => 'AND', default_field => '_all', lenient => JSON::true, + fields => $options{fields}, + use_dis_max => JSON::true, } }; @@ -226,9 +228,19 @@ sub build_query_compat { join( ' ', $self->_create_query_string(@search_params) ) || (), $self->_join_queries( $self->_convert_index_strings(@$limits) ) || () ); + my @weights = $params->{weight}; + my @w_fields = $params->{w_fields}; + my @fields = '_all'; + if ( defined $weights[0] ) { + for (my $i = 0 ; $i < (scalar @weights) ; $i++ ){ + push @fields, "$w_fields[$i]^$weights[$i]"; + } + } + # If there's no query on the left, let's remove the junk left behind $query_str =~ s/^ AND //; my %options; + $options{fields} = \@fields; $options{sort} = \@sort_params; $options{expanded_facet} = $params->{expanded_facet}; my $query = $self->build_query( $query_str, %options ); --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -381,6 +381,9 @@ my @operators = map uri_unescape($_), $cgi->multi_param('op'); # can be single or multiple parameters separated by comma: kw,right-Truncation my @indexes = map uri_unescape($_), $cgi->multi_param('idx'); +my @w_fields = map $_, $cgi->multi_param('field'); +my @weight = map $_, $cgi->multi_param('weight'); + # if a simple index (only one) display the index used in the top search box if ($indexes[0] && (!$indexes[1] || $params->{'scan'})) { my $idx = "ms_".$indexes[0]; @@ -468,7 +471,7 @@ my $searcher = Koha::SearchEngine::Search->new( $query_type ) = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits, - \@sort_by, $scan, $lang ); + \@sort_by, $scan, $lang, { w_fields => @w_fields, weight => @weight } ); ## parse the query_cgi string and put it into a form suitable for s my @query_inputs; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -112,6 +112,17 @@ + +
+
+ + + +
+
--