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

(-)a/Koha/SearchEngine/Elasticsearch/Browse.pm (-19 / +11 lines)
Lines 164-177 sub _build_query { Link Here
164
}
164
}
165
165
166
sub _build_query_count_record {
166
sub _build_query_count_record {
167
    my ($self, $cgi_q, $key, $item) = @_;
167
    my ( $self, $cgi_q, $key, $item ) = @_;
168
    my $query = {
168
    my $query = { query => { match_phrase => { $key => $item } } };
169
        query => {
170
            match_phrase => {
171
                $key  => $item
172
            }
173
        }
174
    };
175
    return $query;
169
    return $query;
176
}
170
}
177
171
Lines 184-212 Return an arrayref of record counts Link Here
184
=cut
178
=cut
185
179
186
sub count_record {
180
sub count_record {
187
    my ($self, $cgi_q) = @_;
181
    my ( $self, $cgi_q ) = @_;
188
    my @results_return;
182
    my @results_return;
189
    my $decoded;
183
    my $decoded;
190
    $cgi_q =~ s/\{\'/\{\"/g;
184
    $cgi_q =~ s/\{\'/\{\"/g;
191
    $cgi_q =~ s/\'\}/\"\}/g;
185
    $cgi_q =~ s/\'\}/\"\}/g;
186
192
    #$cgi_q =~ s/\'\:\'/\"\:\"}/g;
187
    #$cgi_q =~ s/\'\:\'/\"\:\"}/g;
193
    eval {
188
    eval { $decoded = JSON::XS::decode_json($cgi_q); };
194
        $decoded = JSON::XS::decode_json($cgi_q);
195
    };
196
    if ($@) {
189
    if ($@) {
197
        warn "Caught JSON::XS decode error: $_";
190
        warn "Caught JSON::XS decode error: $_";
198
    }
191
    }
199
192
200
    foreach my $item (@$decoded)
193
    foreach my $item (@$decoded) {
201
    {
194
        for my $key ( keys %$item ) {
202
        for my $key ( keys %$item ){
203
            my $elasticsearch = $self->get_elasticsearch();
195
            my $elasticsearch = $self->get_elasticsearch();
204
            my $query = $self->_build_query_count_record($cgi_q, $key, $$item{$key});
196
            my $query         = $self->_build_query_count_record( $cgi_q, $key, $$item{$key} );
205
            my $res = $elasticsearch->search(
197
            my $res           = $elasticsearch->search(
206
                index => $self->index_name,
198
                index => $self->index_name,
207
                body => $query
199
                body  => $query
208
            );
200
            );
209
        push(@results_return, $res->{'hits'}->{'total'});
201
            push( @results_return, $res->{'hits'}->{'total'} );
210
        }
202
        }
211
    }
203
    }
212
    return \@results_return;
204
    return \@results_return;
(-)a/installer/data/mysql/atomicupdate/bug_27428-number_records_next_to_search_links_opac.perl (-8 lines)
Lines 1-8 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/atomicupdate/bug_27428-number_records_next_to_search_links_opac.pl (+18 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "27428",
5
    description => "A single line description",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        # Do you stuffs here
11
        $dbh->do(
12
            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')}
13
        );
14
15
        # Print useful stuff here
16
        say $out "Added new system preference 'OPACDisplayRecordCount'";
17
    },
18
};
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/opac-display-record-count.js (-17 / +3 lines)
Lines 1-11 Link Here
1
var url_request = '/cgi-bin/koha/svc/elasticsearch/opac-elasticsearch.pl?q=';
1
var url_request = '/cgi-bin/koha/svc/elasticsearch/opac-elasticsearch.pl?q=';
2
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=";
3
var regex_es_link = "/cgi-bin/koha/opac-search.pl?q=";
6
/* key API */
7
var key_display = 'nb_notice';
4
var key_display = 'nb_notice';
8
/* idx de recherche */
9
var es_builder = {
5
var es_builder = {
10
    'an' : 'koha-auth-number',
6
    'an' : 'koha-auth-number',
11
    'Provider' : 'provider',
7
    'Provider' : 'provider',
Lines 13-20 var es_builder = { Link Here
13
    'au' : 'author',
9
    'au' : 'author',
14
    'su,complete-subfield' : 'subject'
10
    'su,complete-subfield' : 'subject'
15
}
11
}
16
/* On remplace tous les caractères suivants  */
17
//https://www.obkb.com/dcljr/charstxt.html
18
var not_symbols = {
12
var not_symbols = {
19
    '\'':'%27',
13
    '\'':'%27',
20
    '.':'%2E',
14
    '.':'%2E',
Lines 46-66 var not_symbols = { Link Here
46
40
47
function NumberResultsRecord(){
41
function NumberResultsRecord(){
48
42
49
    var regex = 'a[href*="${' + regex_es_link + '}"]';
43
    var regex = 'a[href*="' + regex_es_link + '"]';
50
    var all_link = $(regex);
44
    var all_link = $(regex);
51
    /* array json data to server */
52
    var json_data=[];
45
    var json_data=[];
53
46
54
    $.each( all_link, function( i, val ) {
47
    $.each( all_link, function( i, val ) {
55
        var url = '';
56
        var str = val.href;
48
        var str = val.href;
57
        /* on prend param de q= */
58
        str = decodeURIComponent(str.split('?q=').pop());
49
        str = decodeURIComponent(str.split('?q=').pop());
59
        /* split query for fields for search [0] */
50
        var es_search = str.split(':');
60
		var es_search = str.split(':');
51
        var str_search = str.substring(str.indexOf(":") + 1);
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){
52
		str_search = str_search.replace(/[&\/\\#,+()$~%.'":;*?<>{}]/g, function(matched){
65
			return not_symbols[matched];
53
			return not_symbols[matched];
66
        });
54
        });
Lines 74-83 function NumberResultsRecord(){ Link Here
74
    type: 'GET',
62
    type: 'GET',
75
    url: url_request + JSON.stringify(json_data) + '&key=' + key_display,
63
    url: url_request + JSON.stringify(json_data) + '&key=' + key_display,
76
    success: function (data) {
64
    success: function (data) {
77
        //consoleconsole.log(data);
78
        jQuery.each( all_link, function( i, val ) {
65
        jQuery.each( all_link, function( i, val ) {
79
            $(val).after("&nbsp;<span style=\"color:black\"><b>["+data[i]+"]</b></span>");
66
            $(val).after("&nbsp;<span style=\"color:black\"><b>["+data[i]+"]</b></span>");
80
            //console.log(val);
81
        });
67
        });
82
    },
68
    },
83
    error: function (data) {
69
    error: function (data) {
(-)a/opac/svc/elasticsearch/opac-elasticsearch.pl (-28 / +29 lines)
Lines 9-51 use CGI::Session; Link Here
9
use Koha::SearchEngine::Elasticsearch::Browse;
9
use Koha::SearchEngine::Elasticsearch::Browse;
10
10
11
my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } );
11
my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } );
12
my $cgi = CGI->new;
12
my $cgi     = CGI->new;
13
my $session = CGI::Session->new();
13
my $session = CGI::Session->new();
14
14
15
$session->param(-name=>'q', -value=>$cgi->param("q"));
15
$session->param( -name => 'q',   -value => $cgi->param("q") );
16
$session->param(-name=>'key', -value=>$cgi->param("key"));
16
$session->param( -name => 'key', -value => $cgi->param("key") );
17
$session->expire('+1h');
17
$session->expire('+1h');
18
18
19
my $iskey = 0;
19
my $iskey = 0;
20
20
21
#Chose GET in key parametre
21
#Chose GET in key parametre
22
if ($session->param("key") eq "nb_notice") {
22
if ( $session->param("key") eq "nb_notice" ) {
23
  $iskey = 1;
23
    $iskey = 1;
24
  my $ses = NFKD( $session->param("q") );
24
    my $ses = NFKD( $session->param("q") );
25
  $ses =~ s/\p{NonspacingMark}//g;
25
    $ses =~ s/\p{NonspacingMark}//g;
26
  my $res = $browser->count_record($ses);
26
    my $res = $browser->count_record($ses);
27
  print $cgi->header("application/json");
27
    print $cgi->header("application/json");
28
  print to_json($res);
28
    print to_json($res);
29
}
29
}
30
30
31
if ($iskey == 0) {
31
if ( $iskey == 0 ) {
32
  response404JSON();
32
    response404JSON();
33
}
33
}
34
34
35
sub response404JSON {
35
sub response404JSON {
36
  my $res = CGI->new;
36
    my $res           = CGI->new;
37
  my $json = JSON->new->utf8;
37
    my $json          = JSON->new->utf8;
38
  my $header_type = "application/json";
38
    my $header_type   = "application/json";
39
  my $header_status = "404";
39
    my $header_status = "404";
40
  my $output = $json->encode({
40
    my $output        = $json->encode(
41
    "error" => "No data",
41
        {
42
    "description" => "Bad request",
42
            "error"       => "No data",
43
  });
43
            "description" => "Bad request",
44
  print $res->header(
44
        }
45
    -type => $header_type,
45
    );
46
    -charset => "utf-8",
46
    print $res->header(
47
    -status => $header_status
47
        -type    => $header_type,
48
  );
48
        -charset => "utf-8",
49
  print $output;
49
        -status  => $header_status
50
  print "\n";
50
    );
51
    print $output;
52
    print "\n";
51
}
53
}
52
- 

Return to bug 27428