Bugzilla – Attachment 195476 Details for
Bug 42107
Add score to staff search results
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 42107: Add search scores to staff results page
Bug-42107-Add-search-scores-to-staff-results-page.patch (text/plain), 3.91 KB, created by
Nick Clemens (kidclamp)
on 2026-03-16 13:01:14 UTC
(
hide
)
Description:
Bug 42107: Add search scores to staff results page
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2026-03-16 13:01:14 UTC
Size:
3.91 KB
patch
obsolete
>From 40b7bd13c14ce0da761fbc2a9546f14339a64aba Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 16 Mar 2026 12:57:35 +0000 >Subject: [PATCH] Bug 42107: Add search scores to staff results page > >This patch ensures the scores from ES are passed through and added to the >search results in the staff side. > >Initially hidden, the scores can be shown by entering the line below into the >JS console in developer tools in the browser, or added to IntranetUserJS to >make them always show: >$(".search_score").toggle(); > >To test: >1 - Have Koha using ES >2 - Do some searches, note results >3 - Apply patch, restart all >4 - Confirm results don't change >5 - Enter code from description into IntranetUserJS >6 - Do more searches >7 - Note the score is visible > >To really note scores, you will need to add some weights to the ES config: >Set weights like: >title 32 >author 16 >subject 8 >--- > Koha/SearchEngine/Elasticsearch/Search.pm | 5 ++++- > catalogue/search.pl | 1 + > koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt | 5 ++++- > 3 files changed, 9 insertions(+), 2 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index ccf502c96c0..fea16dd0800 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -174,13 +174,15 @@ sub search_compat { > > # Convert each result into a MARC::Record > my @records; >+ my @scores; > > # opac-search expects results to be put in the > # right place in the array, according to $offset > my $index = $offset; > my $hits = $results->{'hits'}; > foreach my $es_record ( @{ $hits->{'hits'} } ) { >- $records[ $index++ ] = $self->decode_record_from_result( $es_record->{'_source'} ); >+ $records[$index] = $self->decode_record_from_result( $es_record->{'_source'} ); >+ $scores[ $index++ ] = $es_record->{'_score'}; > } > > # consumers of this expect a name-spaced result, we provide the default >@@ -188,6 +190,7 @@ sub search_compat { > my %result; > $result{biblioserver}{hits} = $hits->{'total'}; > $result{biblioserver}{RECORDS} = \@records; >+ $result{biblioserver}{scores} = \@scores; > > my $facets = $self->_convert_facets( $results->{aggregations} ); > if ( C4::Context->interface eq 'opac' ) { >diff --git a/catalogue/search.pl b/catalogue/search.pl >index 957a9f9dcfc..a0974f3d69d 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -710,6 +710,7 @@ if ($hits) { > ); > $template->param( hits_to_paginate => $hits_to_paginate ); > $template->param( SEARCH_RESULTS => \@newresults ); >+ $template->param( SCORES => $results_hashref->{$server}->{"scores"} ); > > # FIXME: no previous_page_offset when pages < 2 > $template->param( >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >index 75796aad548..7645de90eda 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >@@ -680,7 +680,10 @@ > > [% SEARCH_RESULT.result_number | html %]. > [% SEARCH_RESULT.XSLTResultsRecord | $raw %] >- >+ [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %] >+ [% SET score_index = loop().index %] >+ <span class="search_score" style="display:none;">Score: [% SCORES.$score_index | html %]</span> >+ [% END %] > <p class="hold"> > [% IF ( SEARCH_RESULT.norequests ) %] > <span class="noholdstext">No holds allowed</span> >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 42107
: 195476