View | Details | Raw Unified | Return to bug 27428
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/Browse.pm (+42 lines)
Lines 48-53 as "suggestible" in the database when indexing takes place. Link Here
48
48
49
use base qw(Koha::SearchEngine::Elasticsearch);
49
use base qw(Koha::SearchEngine::Elasticsearch);
50
use Modern::Perl;
50
use Modern::Perl;
51
use JSON;
51
52
52
=head2 browse
53
=head2 browse
53
54
Lines 162-167 sub _build_query { Link Here
162
    return $query;
163
    return $query;
163
}
164
}
164
165
166
sub _build_query_count_record {
167
    my ($self, $cgi_q, $key, $item) = @_;
168
    my $query = {
169
        query => {
170
            match_phrase => {
171
                $key  => $item
172
            }
173
        }
174
    };
175
    return $query;
176
}
177
178
sub count_record {
179
    my ($self, $cgi_q) = @_;
180
    my @results_return;
181
    my $decoded;
182
    $cgi_q =~ s/\{\'/\{\"/g;
183
    $cgi_q =~ s/\'\}/\"\}/g;
184
    #$cgi_q =~ s/\'\:\'/\"\:\"}/g;
185
    eval {
186
        $decoded = JSON::XS::decode_json($cgi_q);
187
    };
188
    if ($@) {
189
        warn "Caught JSON::XS decode error: $_";
190
    }
191
192
    foreach my $item (@$decoded)
193
    {
194
        for my $key ( keys %$item ){
195
            my $elasticsearch = $self->get_elasticsearch();
196
            my $query = $self->_build_query_count_record($cgi_q, $key, $$item{$key});
197
            my $res = $elasticsearch->search(
198
                index => $self->index_name,
199
                body => $query
200
            );
201
        push(@results_return, $res->{'hits'}->{'total'});
202
        }
203
    }
204
    return \@results_return;
205
}
206
165
1;
207
1;
166
208
167
__END__
209
__END__
(-)a/installer/data/mysql/atomicupdate/bug_27428-number_records_next_to_search_links_opac.perl (+8 lines)
Line 0 Link Here
1
$DBversion = 'XXX'; # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    # you can use $dbh here like:
4
    $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('OPACDisplayRecordCount', '0', NULL, 'If enabled, show the number of records next to search links in the bibliographic record detail page in the OPAC.', 'YesNo')});
5
6
    # Always end with this (adjust the bug info)
7
    NewVersion( $DBversion, 27428, "Show the number of records in the detail page in the OPAC");
8
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 427-432 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
427
('OPACdefaultSortOrder','dsc','asc|dsc|za|az','Specify the default sort order','Choice'),
427
('OPACdefaultSortOrder','dsc','asc|dsc|za|az','Specify the default sort order','Choice'),
428
('OPACdidyoumean','',NULL,'Did you mean? configuration for the OPAC. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'),
428
('OPACdidyoumean','',NULL,'Did you mean? configuration for the OPAC. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'),
429
('OPACDisplay856uAsImage','OFF','OFF|Details|Results|Both','Display the URI in the 856u field as an image, the corresponding OPACXSLT option must be on','Choice'),
429
('OPACDisplay856uAsImage','OFF','OFF|Details|Results|Both','Display the URI in the 856u field as an image, the corresponding OPACXSLT option must be on','Choice'),
430
('OPACDisplayRecordCount','0',NULL,'If enabled, show the number of records next to search links in the bibliographic record detail page in the OPAC.','YesNo'),
430
('OpacExportOptions','bibtex,dc,marcxml,marc8,utf8,marcstd,mods,ris,isbd','','Define export options available on OPAC detail page.','multiple'),
431
('OpacExportOptions','bibtex,dc,marcxml,marc8,utf8,marcstd,mods,ris,isbd','','Define export options available on OPAC detail page.','multiple'),
431
('OPACFallback', 'prog', 'bootstrap|prog', 'Define the fallback theme for the OPAC interface.', 'Themes'),
432
('OPACFallback', 'prog', 'bootstrap|prog', 'Define the fallback theme for the OPAC interface.', 'Themes'),
432
('OpacFavicon','','','Enter a complete URL to an image to replace the default Koha favicon on the OPAC','free'),
433
('OpacFavicon','','','Enter a complete URL to an image to replace the default Koha favicon on the OPAC','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+8 lines)
Lines 306-308 Searching: Link Here
306
            - LIBRIS base URL
306
            - LIBRIS base URL
307
            - pref: LibrisURL
307
            - pref: LibrisURL
308
            - "Please only change this if you are sure it needs changing."
308
            - "Please only change this if you are sure it needs changing."
309
        -
310
            - pref: OPACDisplayRecordCount
311
              type: boolean
312
              default: 0
313
              choices:
314
                  1: Show
315
                  0: "Don't show"
316
            - the number of records next to search links in the bibliographic record detail page in the OPAC.
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc (+3 lines)
Lines 47-52 Link Here
47
[% IF ( Koha.Preference('OPACUserCSS') ) %]
47
[% IF ( Koha.Preference('OPACUserCSS') ) %]
48
    <style>[% Koha.Preference('OPACUserCSS') | $raw %]</style>
48
    <style>[% Koha.Preference('OPACUserCSS') | $raw %]</style>
49
[% END %]
49
[% END %]
50
[% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
51
    [% Asset.js("js/opac-display-record-count.js") %]
52
[% END %]
50
[% IF SCO_login %]
53
[% IF SCO_login %]
51
    [% SET SCOUserCSS = Koha.Preference('SCOUserCSS') %]
54
    [% SET SCOUserCSS = Koha.Preference('SCOUserCSS') %]
52
    [% IF SCOUserCSS %]
55
    [% IF SCOUserCSS %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-1 / +3 lines)
Lines 1454-1459 Link Here
1454
    [% END %]
1454
    [% END %]
1455
1455
1456
    <script>
1456
    <script>
1457
        [% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
1458
            NumberResultsRecord();
1459
        [% END %]
1457
        window.emojiPicker = new EmojiPicker({
1460
        window.emojiPicker = new EmojiPicker({
1458
        emojiable_selector: '[data-emojiable=true]',
1461
        emojiable_selector: '[data-emojiable=true]',
1459
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
1462
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
Lines 1883-1889 Link Here
1883
                    });
1886
                    });
1884
                }());
1887
                }());
1885
            [% END # /IF ( OPACShelfBrowser ) %]
1888
            [% END # /IF ( OPACShelfBrowser ) %]
1886
1887
            [% IF ( OpacStarRatings != 'disable' ) %]
1889
            [% IF ( OpacStarRatings != 'disable' ) %]
1888
                // -----------------------------------------------------
1890
                // -----------------------------------------------------
1889
                // star-ratings code
1891
                // star-ratings code
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/opac-display-record-count.js (+88 lines)
Line 0 Link Here
1
var url_request = '/cgi-bin/koha/svc/elasticsearch/opac-elasticsearch.pl?q=';
2
3
//const url_param = '_search?filter_path=hits.total&source_content_type=application/json'
4
/* Regex pour tous les URL avec un recherche */
5
var regex_es_link = "/cgi-bin/koha/opac-search.pl?q=";
6
/* key API */
7
var key_display = 'nb_notice';
8
/* idx de recherche */
9
var es_builder = {
10
    'an' : 'koha-auth-number',
11
    'Provider' : 'provider',
12
    'se,phr' : 'title-series',
13
    'au' : 'author',
14
    'su,complete-subfield' : 'subject'
15
}
16
/* On remplace tous les caractères suivants  */
17
//https://www.obkb.com/dcljr/charstxt.html
18
var not_symbols = {
19
    '\'':'%27',
20
    '.':'%2E',
21
    '+': '',
22
    ',': '%2C',
23
    ';': '%3B',
24
    '-': '',
25
    '=': '',
26
    '&': '%26',
27
    '|': '',
28
    '>': '',
29
    '<': '',
30
    '!': '',
31
    '(': '',
32
    ')': '',
33
    '{': '',
34
    '}': '',
35
    '[': '',
36
    ']': '',
37
    '^': '',
38
    '"': '',
39
    '~': '',
40
    '*': '',
41
    '?': '',
42
    ':': '%3A',
43
    '/': '',
44
    "\\": '%5C'
45
};
46
47
function NumberResultsRecord(){
48
49
    var regex = `a[href*="${regex_es_link}"]`;
50
    var all_link = $(regex);
51
    /* array json data to server */
52
    var json_data=[];
53
54
    $.each( all_link, function( i, val ) {
55
        var url = '';
56
        var str = val.href;
57
        /* on prend param de q= */
58
        str = decodeURIComponent(str.split('?q=').pop());
59
        /* split query for fields for search [0] */
60
		var es_search = str.split(':');
61
        /* Remplacement pour un requete */
62
		var str_search = str.substring(str.indexOf(":") + 1);
63
		/* [0] this is field for search */
64
		str_search = str_search.replace(/[&\/\\#,+()$~%.'":;*?<>{}]/g, function(matched){
65
			return not_symbols[matched];
66
        });
67
        es_search[0] = es_search[0][0] == '(' ? es_search[0].substring(1) : es_search[0];
68
        var json = {};
69
        json[es_builder[es_search[0]]] = str_search;
70
        json_data.push(json);
71
  });
72
73
  $.ajax({
74
    type: 'GET',
75
    url: url_request + JSON.stringify(json_data) + '&key=' + key_display,
76
    success: function (data) {
77
        //consoleconsole.log(data);
78
        jQuery.each( all_link, function( i, val ) {
79
            $(val).after("&nbsp;<span style=\"color:black\"><b>["+data[i]+"]</b></span>");
80
            //console.log(val);
81
        });
82
    },
83
    error: function (data) {
84
        console.log(data);
85
    },
86
  });
87
88
}
(-)a/opac/svc/elasticsearch/opac-elasticsearch.pl (-1 / +51 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
use CGI qw ( -utf8 );
6
use JSON;
7
use utf8;
8
use Unicode::Normalize;
9
use CGI::Session;
10
use Koha::SearchEngine::Elasticsearch::Browse;
11
12
my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } );
13
my $cgi = CGI->new;
14
my $session = CGI::Session->new();
15
16
$session->param(-name=>'q', -value=>$cgi->param("q"));
17
$session->param(-name=>'key', -value=>$cgi->param("key"));
18
$session->expire('+1h');
19
20
my $iskey = 0;
21
22
#Chose GET in key parametre
23
if ($session->param("key") eq "nb_notice") {
24
  $iskey = 1;
25
  my $ses = NFKD( $session->param("q") );
26
  $ses =~ s/\p{NonspacingMark}//g;
27
  my $res = $browser->count_record($ses);
28
  print $cgi->header("application/json");
29
  print to_json($res);
30
}
31
32
if ($iskey == 0) {
33
  response404JSON();
34
}
35
36
sub response404JSON {
37
  my $json = JSON->new->utf8;
38
  my $header_type = "application/json";
39
  my $header_status = "404";
40
  my $output = $json->encode({
41
    "error" => "No data",
42
    "description" => "Bad request",
43
  });
44
  print $cgi->header(
45
    -type => $header_type,
46
    -charset => "utf-8",
47
    -status => $header_status
48
  );
49
  print $output;
50
  print "\n";
51
}

Return to bug 27428