Bugzilla – Attachment 181289 Details for
Bug 23875
Elasticsearch - When sorting by score we should provide a tiebreaker
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23875: Explicitly srt searches by score and provide local-number as tie breaker
Bug-23875-Explicitly-srt-searches-by-score-and-pro.patch (text/plain), 3.07 KB, created by
Martin Renvoize (ashimema)
on 2025-04-22 14:59:51 UTC
(
hide
)
Description:
Bug 23875: Explicitly srt searches by score and provide local-number as tie breaker
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-04-22 14:59:51 UTC
Size:
3.07 KB
patch
obsolete
>From cc2f905f40e08614bc04454863a93619ed787936 Mon Sep 17 00:00:00 2001 >From: Nick <nick@bywatersolutions.com> >Date: Tue, 22 Oct 2019 14:38:58 +0000 >Subject: [PATCH] Bug 23875: Explicitly srt searches by score and provide > local-number as tie breaker > >To test: > 1 - Set search engine to ES > 2 - Search the catalog for "*" > 3 - Note results > 4 - Edit first result > 5 - Repeat search, results are reordered > 6 - Apply patch > 7 - Search for "*" > 8 - Highest biblionumbers are returned first > 9 - Edit first result, repeat search >10 - Order does not change >11 - Confirm sorting by author, title, etc passes the same trials > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> >--- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 8 ++++++++ > .../SearchEngine/Elasticsearch/QueryBuilder.t | 15 +++++++++++++-- > 2 files changed, 21 insertions(+), 2 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 0e9d964727b..c1b54491131 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -227,6 +227,14 @@ sub build_query { > } > } > >+ # If not sorting by anything explicitly search by score >+ if ( !defined $res->{sort} ) { >+ push @{ $res->{sort} }, { _score => { order => 'desc' } }; >+ } >+ >+ # Add a tie breaker in case of equally relevant records >+ push @{ $res->{sort} }, { 'local-number' => { order => 'desc' } }; >+ > unless ( $options{skip_facets} ) { > > # See _convert_facets in Search.pm for how these get turned into >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index b1ed5d1cb67..79380ee7c16 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -228,7 +228,7 @@ subtest 'build_authorities_query_compat() tests' => sub { > }; > > subtest 'build_query tests' => sub { >- plan tests => 68; >+ plan tests => 69; > > my $qb; > >@@ -245,7 +245,7 @@ subtest 'build_query tests' => sub { > > is_deeply( > $query->{sort}, >- [ { 'title__sort' => { 'order' => 'asc' } } ], >+ [ { 'title__sort' => { 'order' => 'asc' } }, { 'local-number' => { 'order' => 'desc' } } ], > "sort parameter properly formed" > ); > >@@ -267,6 +267,17 @@ subtest 'build_query tests' => sub { > $query = $qb->build_query( 'test', %options ); > ok( !defined $query->{aggregations}, 'Skipping facets means we do not have aggregations in the the query' ); > >+ $query = $qb->build_query( 'test', () ); >+ >+ is_deeply( >+ $query->{sort}, >+ [ >+ { '_score' => { 'order' => 'desc' } }, >+ { 'local-number' => { 'order' => 'desc' } } >+ ], >+ "sort parameter properly formed if no sort passed" >+ ); >+ > t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '' ); > > ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] ); >-- >2.49.0
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 23875
:
94579
|
94712
|
108391
|
174227
|
181183
|
181214
| 181289 |
181892