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 724-728 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
724
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
724
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
725
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
725
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
726
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
726
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
727
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
727
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
728
('OPACDisplayRecordCount','0',NULL,NULL,'YesNo')
728
;
729
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+8 lines)
Lines 276-278 Searching: Link Here
276
            - LIBRIS base URL
276
            - LIBRIS base URL
277
            - pref: LibrisURL
277
            - pref: LibrisURL
278
            - "Please only change this if you are sure it needs changing."
278
            - "Please only change this if you are sure it needs changing."
279
        -
280
            - pref: OPACDisplayRecordCount
281
              type: boolean
282
              default: no
283
              choices:
284
                  yes: Show
285
                  no: "Don't show"
286
            - 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 (-2 / +3 lines)
Lines 1446-1452 Link Here
1446
    [% IF ( Koha.Preference('OPACDetailQRCode') ) %]
1446
    [% IF ( Koha.Preference('OPACDetailQRCode') ) %]
1447
        [% Asset.js("lib/kjua/kjua.min.js") | $raw %]
1447
        [% Asset.js("lib/kjua/kjua.min.js") | $raw %]
1448
    [% END %]
1448
    [% END %]
1449
1450
    [% IF ( Koha.Preference('OPACShowMusicalInscripts') ) %]
1449
    [% IF ( Koha.Preference('OPACShowMusicalInscripts') ) %]
1451
        <script>
1450
        <script>
1452
            var interface = "[% interface | html %]";
1451
            var interface = "[% interface | html %]";
Lines 1460-1465 Link Here
1460
    [% END %]
1459
    [% END %]
1461
1460
1462
    <script>
1461
    <script>
1462
        [% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
1463
            NumberResultsRecord();
1464
        [% END %]
1463
        window.emojiPicker = new EmojiPicker({
1465
        window.emojiPicker = new EmojiPicker({
1464
        emojiable_selector: '[data-emojiable=true]',
1466
        emojiable_selector: '[data-emojiable=true]',
1465
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
1467
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
Lines 1723-1729 Link Here
1723
                    });
1725
                    });
1724
                }());
1726
                }());
1725
            [% END # /IF ( OPACShelfBrowser ) %]
1727
            [% END # /IF ( OPACShelfBrowser ) %]
1726
1727
            [% IF ( OpacStarRatings != 'disable' ) %]
1728
            [% IF ( OpacStarRatings != 'disable' ) %]
1728
                // -----------------------------------------------------
1729
                // -----------------------------------------------------
1729
                // star-ratings code
1730
                // 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-autocomplete.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
        console.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-autocomplete.pl (-1 / +49 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
use CGI qw ( -utf8 );
6
use v5.10;
7
use JSON;
8
use utf8;
9
use Text::Unaccent;
10
use CGI::Session;
11
use Koha::SearchEngine::Elasticsearch::Browse;
12
13
my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } );
14
my $cgi = CGI->new;
15
my $session = CGI::Session->new();
16
17
$session->param(-name=>'q', -value=>$cgi->param("q"));
18
$session->param(-name=>'key', -value=>$cgi->param("key"));
19
$session->expire('+1h');
20
21
#Chose GET in key parametre
22
given ($session->param("key")) {
23
  when ("nb_notice") {
24
    my $res = $browser->count_record(unac_string("UTF-8", $session->param("q")));
25
    print $cgi->header("application/json");
26
    print to_json($res);
27
  }
28
  #no key 404
29
  default {
30
    response404JSON();
31
  }
32
}
33
34
sub response404JSON {
35
  my $json = JSON->new->utf8;
36
  my $header_type = "application/json";
37
  my $header_status = "404";
38
  my $output = $json->encode({
39
    "error" => "No data",
40
    "description" => "Bad request",
41
  });
42
  print $cgi->header(
43
    -type => $header_type,
44
    -charset => "utf-8",
45
    -status => $header_status
46
  );
47
  print $output;
48
  print "\n";
49
}

Return to bug 27428