Bugzilla – Attachment 73139 Details for
Bug 18316
Add weighting/relevancy options to ElasticSearch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18316 - Add weighting/relevancy options to ElasticSearch
Bug-18316---Add-weightingrelevancy-options-to-Elas.patch (text/plain), 4.02 KB, created by
Alex Arnaud
on 2018-03-21 13:38:31 UTC
(
hide
)
Description:
Bug 18316 - Add weighting/relevancy options to ElasticSearch
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2018-03-21 13:38:31 UTC
Size:
4.02 KB
patch
obsolete
>From 18369671a4fad83c3346eba1de9ddfb53f163551 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 21 Mar 2018 13:27:12 +0000 >Subject: [PATCH] Bug 18316 - Add weighting/relevancy options to ElasticSearch > >These are proof of concept that we can add weighting simply at time of >search query. Testable but not suitable for pushing. > >To test: >Apply patch >Use the advanced search page in the intranet >Choose a field and enter a number to weight >Note diffrently ordered results than without any weighing > >To DO: >1 - Add a config page for default wieghting to be used >2 - Allow addition of any indexed field to wieghting at search >3 - All more than one fields to be weighted >4 - Better code/variables >--- > 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(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 95cc86a..e237097 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/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, > } > }; > >@@ -228,9 +230,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 ); >diff --git a/catalogue/search.pl b/catalogue/search.pl >index 79ba83f..aeadd57 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -379,6 +379,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]; >@@ -467,7 +470,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 <input>s > my @query_inputs; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt >index 51b5e34..9d3855c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt >@@ -96,6 +96,17 @@ > <!-- /BOOLEAN SEARCH OPTIONS --> > > </div> >+ >+<div> >+ <fieldset> >+ <select name="field"> >+ <option value='title'>Title</option> >+ <option value='subject'>Subject</option> >+ </select> >+ <label for='weight'>Weight</label> >+ <input name='weight' type='text' value="" /> >+ </fieldset> >+</div> > <!-- MC-TYPE LIMITS --> > <div id="advsearches" class="toptabs"> > <ul> >-- >2.7.4
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 18316
:
61472
|
73139
|
73140
|
73492
|
73493
|
73600
|
73601
|
74112
|
74115
|
74116
|
74117
|
74714
|
74720
|
74751
|
74752
|
74753
|
74754
|
75073
|
75074
|
75075
|
75076
|
75458
|
75490
|
75519
|
75520
|
75521
|
75522
|
75523
|
75524
|
75525
|
75526
|
75527
|
75528
|
75529
|
75530
|
75531
|
75536
|
75537
|
75538
|
75539
|
75540
|
75541
|
75699
|
75730
|
77661
|
77662
|
77663
|
77664
|
77665
|
77666
|
77667
|
78396
|
78397
|
78398
|
78399
|
78400
|
78401
|
78402
|
78403
|
80278
|
80335
|
81004
|
81005
|
81006
|
81007
|
81008
|
81009
|
81010
|
81011
|
81012
|
81507
|
81508
|
81509
|
81510
|
81511
|
81512
|
81513
|
81514
|
81515
|
81516
|
82050