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 479-484 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
479
('OPACDetailQRCode','0','','Enable the display of a QR Code on the OPAC detail page','YesNo'),
479
('OPACDetailQRCode','0','','Enable the display of a QR Code on the OPAC detail page','YesNo'),
480
('OPACdidyoumean','',NULL,'Did you mean? configuration for the OPAC. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'),
480
('OPACdidyoumean','',NULL,'Did you mean? configuration for the OPAC. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'),
481
('OPACDisplay856uAsImage','OFF','OFF|Details|Results|Both','Display the URI in the 856u field as an image, the corresponding OPACXSLT option must be on','Choice'),
481
('OPACDisplay856uAsImage','OFF','OFF|Details|Results|Both','Display the URI in the 856u field as an image, the corresponding OPACXSLT option must be on','Choice'),
482
('OPACDisplayRecordCount','0',NULL,'If enabled, show the number of records next to search links in the bibliographic record detail page in the OPAC.','YesNo'),
482
('OpacExportOptions','bibtex,dc,marcxml,marc8,utf8,marcstd,mods,ris,isbd','','Define export options available on OPAC detail page.','multiple'),
483
('OpacExportOptions','bibtex,dc,marcxml,marc8,utf8,marcstd,mods,ris,isbd','','Define export options available on OPAC detail page.','multiple'),
483
('OPACFallback', 'prog', 'bootstrap|prog', 'Define the fallback theme for the OPAC interface.', 'Themes'),
484
('OPACFallback', 'prog', 'bootstrap|prog', 'Define the fallback theme for the OPAC interface.', 'Themes'),
484
('OpacFavicon','','','Enter a complete URL to an image to replace the default Koha favicon on the OPAC','free'),
485
('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 374-376 Searching: Link Here
374
            - pref: LibrisURL
374
            - pref: LibrisURL
375
              class: url
375
              class: url
376
            - "Please only change this if you are sure it needs changing."
376
            - "Please only change this if you are sure it needs changing."
377
        -
378
            - pref: OPACDisplayRecordCount
379
              type: boolean
380
              default: 0
381
              choices:
382
                  1: Show
383
                  0: "Don't show"
384
            - 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 54-59 Link Here
54
        [% Branches.GetBranchSpecificCSS( Branches.GetLoggedInBranchcode() || default_branch) | $raw %]
54
        [% Branches.GetBranchSpecificCSS( Branches.GetLoggedInBranchcode() || default_branch) | $raw %]
55
    </style>
55
    </style>
56
[% END %]
56
[% END %]
57
[% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
58
    [% Asset.js("js/opac-display-record-count.js") | $raw %]
59
[% END %]
57
[% IF SCO_login %]
60
[% IF SCO_login %]
58
    [% SET SCOUserCSS = Koha.Preference('SCOUserCSS') %]
61
    [% SET SCOUserCSS = Koha.Preference('SCOUserCSS') %]
59
    [% IF SCOUserCSS %]
62
    [% IF SCOUserCSS %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (+3 lines)
Lines 1462-1467 Link Here
1462
    [% END %]
1462
    [% END %]
1463
1463
1464
    <script>
1464
    <script>
1465
        [% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
1466
            NumberResultsRecord();
1467
        [% END %]
1465
        window.emojiPicker = new EmojiPicker({
1468
        window.emojiPicker = new EmojiPicker({
1466
        emojiable_selector: '[data-emojiable=true]',
1469
        emojiable_selector: '[data-emojiable=true]',
1467
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
1470
        assetsPath: '[% interface | html %]/lib/emoji-picker/img/',
(-)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 Modern::Perl;
4
use CGI qw ( -utf8 );
5
use JSON;
6
use utf8;
7
use Unicode::Normalize;
8
use CGI::Session;
9
use Koha::SearchEngine::Elasticsearch::Browse;
10
11
my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } );
12
my $cgi = CGI->new;
13
my $session = CGI::Session->new();
14
15
$session->param(-name=>'q', -value=>$cgi->param("q"));
16
$session->param(-name=>'key', -value=>$cgi->param("key"));
17
$session->expire('+1h');
18
19
my $iskey = 0;
20
21
#Chose GET in key parametre
22
if ($session->param("key") eq "nb_notice") {
23
  $iskey = 1;
24
  my $ses = NFKD( $session->param("q") );
25
  $ses =~ s/\p{NonspacingMark}//g;
26
  my $res = $browser->count_record($ses);
27
  print $cgi->header("application/json");
28
  print to_json($res);
29
}
30
31
if ($iskey == 0) {
32
  response404JSON();
33
}
34
35
sub response404JSON {
36
  my $res = CGI->new;
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 $res->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