Bugzilla – Attachment 187500 Details for
Bug 40853
ElasticsearchBoostFieldMatch - needs to boost results more
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40853: Add ElasticsearchBoostFieldMatchAmount system preference
Bug-40853-Add-ElasticsearchBoostFieldMatchAmount-s.patch (text/plain), 5.36 KB, created by
Jason Robb
on 2025-10-06 20:32:28 UTC
(
hide
)
Description:
Bug 40853: Add ElasticsearchBoostFieldMatchAmount system preference
Filename:
MIME Type:
Creator:
Jason Robb
Created:
2025-10-06 20:32:28 UTC
Size:
5.36 KB
patch
obsolete
>From 99667551cf837310938347438f6cf80f6d99c90b Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 3 Oct 2025 19:22:06 +0000 >Subject: [PATCH] Bug 40853: Add ElasticsearchBoostFieldMatchAmount system > preference > >This adds a new system preference to control the amount of boost. The default of 0 will act as before this patch. >You can add any positive number, or a number between 0 and 1 for negative boost > >To test: >1 - Add a record with > 245 $a novel >2 - Add a record with > 245 $a A novel : $b about things / $c by me >3 - Search for: novel >4 - Search for: a novel >5 - Apply patch, restart all >6 - Repeat searches, note exact titles are boosted >7 - Test with more titles as you are able > >Signed-off-by: Jason Robb <jrobb@sekls.org> >--- > .../Elasticsearch/QueryBuilder.pm | 6 +++++- > .../data/mysql/atomicupdate/bug_40853.pl | 20 +++++++++++++++++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../modules/admin/preferences/searching.pref | 4 +++- > 4 files changed, 29 insertions(+), 2 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_40853.pl > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 8ee830c6498..265b59b3be5 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -389,13 +389,17 @@ sub _build_field_match_boost_query { > my $indexes = $params->{indexes}; > my $operands = $params->{operands}; > >+ my $boost_amount = C4::Context->preference('ElasticsearchBoostFieldMatchAmount'); > my @boost_query; >+ my $built_boost; > my $ea = each_array( @$operands, @$indexes ); > while ( my ( $operand, $index ) = $ea->() ) { > next unless $operand; > $index = $index->{field} if ref $index eq 'HASH'; > $index = 'title-cover' if ( !$index || $index eq 'kw' || $index eq 'ti' || $index eq 'title' ); >- push @boost_query, { match => { $index => { query => $operand } } }; >+ $built_boost = { match => { $index => { query => $operand } } }; >+ $built_boost->{match}->{$index}->{boost} = $boost_amount if $boost_amount; >+ push @boost_query, $built_boost; > } > return \@boost_query; > } >diff --git a/installer/data/mysql/atomicupdate/bug_40853.pl b/installer/data/mysql/atomicupdate/bug_40853.pl >new file mode 100755 >index 00000000000..0b12e1b3ee0 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_40853.pl >@@ -0,0 +1,20 @@ >+use Modern::Perl; >+use Koha::Installer::Output qw(say_warning say_success say_info); >+ >+return { >+ bug_number => "BUG_NUMBER", >+ description => "A single line description", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ $dbh->do( >+ q{ >+ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+ ('ElasticsearchBoostFieldMatchAmount', '0', NULL, 'A numeric rank for the boost of field matches', 'Integer') >+ } >+ ); >+ >+ say $out "Added new system preference 'ElasticsearchBoostFieldMatchAmount'"; >+ }, >+}; >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 0d77d5ba947..d02af13fc93 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -237,6 +237,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('EdifactInvoiceImport', 'automatic', 'automatic|manual', "If on, don't auto-import EDI invoices, just keep them in the database with the status 'new'", 'Choice'), > ('EdifactLSQ', 'location', 'location|ccode', 'Map EDI sequence code (GIR+LSQ) to Koha Item field', 'Choice'), > ('ElasticsearchBoostFieldMatch', '0', NULL, 'Add a "match" query to es when searching, will follow indexes chosen in advanced search, or use title-cover for generic keyword or title index search', 'YesNo'), >+('ElasticsearchBoostFieldMatchAmount', '1', NULL, 'A numeric rank for the boost of field matches', 'Integer'), > ('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'), > ('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL), > ('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >index 6c7e8d0e78a..e096801ae74 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >@@ -101,7 +101,9 @@ Searching: > choices: > 1: Enable > 0: Disable >- - "adding a second 'match' field search to the ES query to boost relevancy. Keyword and title fields will be boosted with title-cover, other fields will boost directly." >+ - "adding a second 'match' field search to the ES query to boost relevancy by" >+ - pref: ElasticsearchBoostFieldMatchAmount >+ - "Keyword and title fields will be boosted with title-cover, other fields will boost directly." > - "This will not boost CCL style searches, only standard or advanced searches." > - > - pref: SavedSearchFilters >-- >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 40853
:
187422
|
187425
| 187500 |
187501
|
187582