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, NULL, '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 / +2 lines)
Lines 738-742 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
738
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
738
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
739
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
739
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
740
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
740
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
741
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
741
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
742
('OPACDisplayRecordCount','0',NULL,NULL,'YesNo')
742
;
743
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+8 lines)
Lines 292-294 Searching: Link Here
292
            - LIBRIS base URL
292
            - LIBRIS base URL
293
            - pref: LibrisURL
293
            - pref: LibrisURL
294
            - "Please only change this if you are sure it needs changing."
294
            - "Please only change this if you are sure it needs changing."
295
        -
296
            - pref: OPACDisplayRecordCount
297
              type: boolean
298
              default: no
299
              choices:
300
                  1: Show
301
                  0: "Don't show"
302
            - 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 1401-1406 Link Here
1401
    [% END %]
1401
    [% END %]
1402
1402
1403
    <script>
1403
    <script>
1404
        [% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
1405
            NumberResultsRecord();
1406
        [% END %]
1404
        window.emojiPicker = new EmojiPicker({
1407
        window.emojiPicker = new EmojiPicker({
1405
        emojiable_selector: '[data-emojiable=true]',
1408
        emojiable_selector: '[data-emojiable=true]',
1406
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
1409
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
Lines 1817-1823 Link Here
1817
                    });
1820
                    });
1818
                }());
1821
                }());
1819
            [% END # /IF ( OPACShelfBrowser ) %]
1822
            [% END # /IF ( OPACShelfBrowser ) %]
1820
1821
            [% IF ( OpacStarRatings != 'disable' ) %]
1823
            [% IF ( OpacStarRatings != 'disable' ) %]
1822
                // -----------------------------------------------------
1824
                // -----------------------------------------------------
1823
                // star-ratings code
1825
                // 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") == "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