Bugzilla – Attachment 146585 Details for
Bug 23649
Elasticsearch offer an option to weight search results by type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[Do not push] - Experimental support for function_score
0001-Support-for-function-scores-in-ES-search.-Define-yam.patch (text/plain), 2.27 KB, created by
Björn Nylén
on 2023-02-13 15:43:35 UTC
(
hide
)
Description:
[Do not push] - Experimental support for function_score
Filename:
MIME Type:
Creator:
Björn Nylén
Created:
2023-02-13 15:43:35 UTC
Size:
2.27 KB
patch
obsolete
>From ce5d8541811c3f2a0a76f6dd28a1578910e51336 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Bj=C3=B6rn=20Nyl=C3=A9n?= <bjorn.nylen@ub.lu.se> >Date: Tue, 31 Jan 2023 11:59:20 +0100 >Subject: [PATCH] Support for function scores in ES search. Define yaml array > of valid functions in syspref ElasticsearchFunctionScore > >--- > .../Elasticsearch/QueryBuilder.pm | 19 +++++++++++++++++-- > 1 file changed, 17 insertions(+), 2 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index dba475eb3c..e579eb3470 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -44,10 +44,12 @@ use JSON; > use List::MoreUtils qw( each_array ); > use Modern::Perl; > use URI::Escape qw( uri_escape_utf8 ); >+use YAML::XS; > > use C4::Context; > use Koha::Exceptions; > use Koha::Caches; >+use Koha::Logger; > > our %index_field_convert = ( > 'kw' => '', >@@ -197,7 +199,7 @@ sub build_query { > if ($options{whole_record}) { > push @$fields, 'marc_data_array.*'; > } >- $res->{query} = { >+ $res->{query}->{function_score}->{query} = { > query_string => { > query => $query, > fuzziness => $fuzzy_enabled ? 'auto' : '0', >@@ -207,7 +209,20 @@ sub build_query { > analyze_wildcard => JSON::true, > } > }; >- $res->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); >+ >+ # Trying to get the scoring functions from the syspref or set as empty arrayref >+ my $scoring_functions = []; >+ eval { >+ $scoring_functions = YAML::XS::Load( C4::Context->preference('ElasticsearchFunctionScore') ) >+ if ( $options{weighted_fields} && C4::Context->preference('ElasticsearchFunctionScore') ); >+ 1; >+ } or do { >+ my $e = $@; >+ Koha::Logger->get->warn("Malformed yaml in ElasticsearchFunctionScore $e/n"); >+ }; >+ $res->{query}->{function_score}->{functions} = $scoring_functions; >+ >+ $res->{query}->{function_score}->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); > > if ( $options{sort} ) { > foreach my $sort ( @{ $options{sort} } ) { >-- >2.34.1 >
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 23649
: 146585