Bugzilla – Attachment 132945 Details for
Bug 27113
Elasticsearch: Autocomplete in search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27113: Removes items in OPACHiddenItems from autocomplete
Bug-27113-Removes-items-in-OPACHiddenItems-from-au.patch (text/plain), 5.77 KB, created by
Shi Yao Wang
on 2022-04-04 16:10:50 UTC
(
hide
)
Description:
Bug 27113: Removes items in OPACHiddenItems from autocomplete
Filename:
MIME Type:
Creator:
Shi Yao Wang
Created:
2022-04-04 16:10:50 UTC
Size:
5.77 KB
patch
obsolete
>From 22bf3b95635042492c0fa9ecaffea063b3d95f68 Mon Sep 17 00:00:00 2001 >From: Shi Yao Wang <shiyao@inlibro.com> >Date: Mon, 4 Apr 2022 11:46:25 -0400 >Subject: [PATCH] Bug 27113: Removes items in OPACHiddenItems from autocomplete > >Items specified in OPACHiddenItems preference are removed from search >suggestions in OPAC. > >Test plan: >1- Search for an item. Notice that the autocomplete functionnality is not available. (See "Result" attachment) >2- Make sure that you are using Elasticsearch as your searching engine. (Preference->SearchEngine->ElasticSearch) >3- Apply the patch. >4- Run ./installer/data/mysql/updatedatabase.pl >5- Looks for the following preferences : > - IntranetAutocompleteElasticSearch > - OPACAutocompleteElasticSearch >6- Set their value to show. >7- Rebuild the OPAC and staff client CSS (This step is important because the autocomplete CSS is moved to the main SCSS file): > Instructions here: https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client >8- Search for an item and notice that the autocomplete functionnality is now available. >9- In the staff interface, go in "Search the catalog". >10- Notice that the buggy behavior is now fixed. >11- Search for an item with basic search and click on one of the >options. >12- Notice it automatically sends you to the selected items page. >13- This time, search an item using the advanced search and click on one >of the options. >14- Notice it just writes the chosen option in the input instead. >15- Go to Administration -> system preferences -> OPACHiddenItems. >16- Define a rule that applies to an existing item. >17- Search that item in OPAC and notice it doesn't give you the >suggestion for that item. >--- > opac/svc/elasticsearch/opac-elasticsearch.pl | 91 ++++++++++++++++++++ > 1 file changed, 91 insertions(+) > >diff --git a/opac/svc/elasticsearch/opac-elasticsearch.pl b/opac/svc/elasticsearch/opac-elasticsearch.pl >index 812b458855..245b0bbd94 100755 >--- a/opac/svc/elasticsearch/opac-elasticsearch.pl >+++ b/opac/svc/elasticsearch/opac-elasticsearch.pl >@@ -9,6 +9,9 @@ use Unicode::Normalize; > use CGI::Session; > use Koha::SearchEngine::Elasticsearch::Browse; > >+use Koha::Items; >+use C4::Context; >+ > my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } ); > my $cgi = CGI->new; > my $session = CGI::Session->load() or die CGI::Session->errstr(); >@@ -33,12 +36,100 @@ if ($session->param("key") eq "autocomplete") { > #search by many prefix fields > if ($length > 1){ > my $res = $browser->autocomplete_idx($ses, \@prefix, $session->param("analyzer"), $session->param("token_counter")); >+ >+ if (C4::Context->yaml_preference('OpacHiddenItems')) { >+ my @prefix = $res->{ "prefix" }; >+ @prefix = split(',', $prefix[0]); >+ >+ my %biblionumbers; >+ for (my $i = 0; $i < scalar @prefix; $i++) { >+ my @hits = @{$res->{ "$i" }->{ "hits" }->{ "hits" }}; >+ if (@hits) { >+ for (my $j = 0; $j < scalar @hits; $j++) { >+ # biblionumber->prefix position = hit position within prefix >+ $biblionumbers{ $hits[$j]->{ "_id" } }{ $i } = $j; >+ } >+ } >+ } >+ >+ if (%biblionumbers) { >+ my @biblionumbers = keys %biblionumbers; >+ my $autocomplete_items = Koha::Items->search({ >+ biblionumber => { -in => \@biblionumbers } >+ }); >+ my $filtered_items = $autocomplete_items->filter_by_visible_in_opac({ >+ patron => undef >+ }); >+ >+ foreach (@biblionumbers) { >+ my $biblionumber = $_; >+ my $item = $filtered_items->find({ >+ biblionumber => $biblionumber >+ }); >+ if (!$item) { >+ my %removelist = %{$biblionumbers{ $biblionumber }}; >+ foreach (keys %removelist) { >+ my $hits = $res->{ $_ }->{ "hits" }->{ "hits" }; >+ splice(@{$hits}, $removelist{ $_ }, 1); >+ $res->{ $_ }->{ "hits" }->{ "total" }--; >+ } >+ } >+ } >+ for (my $i = 0; $i < scalar @prefix; $i++) { >+ if ($res->{ $i }->{ "hits" }->{ "max_score" }) { >+ my $hits = $res->{ $i }->{ "hits" }->{ "hits" }; >+ my $maxscore = 0; >+ foreach ( @{$hits} ) { >+ my $score = $_->{"_score"}; >+ $maxscore = $score if ($maxscore < $score); >+ } >+ $res->{ $i }->{ "hits" }->{ "max_score" } = $maxscore; >+ } >+ } >+ } >+ } >+ > print $cgi->header("application/json"); > print to_json($res); > } > #search by one prefix field > elsif ($length == 1) { > my $res = $browser->autocomplete_one_idx($ses, $prefix[0], $session->param("analyzer"), $session->param("token_counter")); >+ >+ if (C4::Context->yaml_preference('OpacHiddenItems')) { >+ my $hits = $res->{ "hits" }->{ "hits" }; >+ if (@{$hits}) { >+ my @biblionumbers; >+ foreach ( @{$hits} ) { >+ push(@biblionumbers, $_->{"_id"}); >+ } >+ >+ my $autocomplete_items = Koha::Items->search({ >+ biblionumber => { -in => \@biblionumbers } >+ }); >+ my $filtered_items = $autocomplete_items->filter_by_visible_in_opac({ >+ patron => undef >+ }); >+ >+ for ( my $i = 0; $i < scalar @biblionumbers; $i++ ) { >+ my $item = $filtered_items->find({ >+ biblionumber => $biblionumbers[$i] >+ }); >+ if (!$item) { >+ splice(@{$hits}, $i, 1); >+ $res->{ "hits" }->{ "total" }--; >+ } >+ } >+ my $maxscore = 0; >+ foreach ( @{$hits} ) { >+ my $score = $_->{"_score"}; >+ $maxscore = $score if ($maxscore < $score); >+ } >+ $res->{ "hits" }->{ "max_score" } = $maxscore; >+ warn Data::Dumper->Dumper($res); >+ } >+ } >+ > print $cgi->header("application/json"); > print to_json($res); > } >-- >2.25.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 27113
:
114168
|
114169
|
114945
|
115117
|
116293
|
119979
|
120028
|
120029
|
120084
|
120088
|
120109
|
120140
|
120141
|
120806
|
121497
|
121498
|
121555
|
121556
|
121557
|
121558
|
131207
|
131208
|
131209
|
131210
|
131211
|
132360
|
132361
|
132362
|
132363
|
132364
|
132808
|
132945
|
132946
|
133042
|
133045
|
133407
|
133409
|
133410
|
136312
|
136456
|
136457
|
136464
|
136465
|
136653
|
136657
|
136658
|
136659
|
136660
|
137436
|
137437
|
137438
|
137439
|
137780
|
137781
|
137782
|
137783
|
139624
|
141466
|
145167
|
146015
|
159769
|
159770
|
159771
|
159772
|
159773
|
159774
|
159775
|
160134
|
160135
|
160136
|
160137
|
160138
|
160139
|
160140
|
160141
|
160142
|
161076
|
161077
|
163826
|
165895
|
165896
|
165897
|
165898
|
165899
|
165900
|
165901
|
165902
|
165903
|
165904
|
165913
|
165922
|
177537
|
177538
|
177539
|
177540
|
177541
|
177542
|
177543
|
177544
|
177545
|
177546
|
177547
|
177548
|
177657
|
178822
|
178823
|
178824
|
178825
|
178826
|
178827
|
178828
|
178829
|
178830
|
178831
|
178832
|
178833
|
179868
|
179869
|
179870
|
179871
|
179872
|
179873
|
179874
|
179875
|
179876
|
179877
|
179878
|
179879