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 722-726 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
722
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
722
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
723
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
723
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
724
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
724
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
725
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
725
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
726
('OPACDisplayRecordCount','0',NULL,NULL,'YesNo')
726
;
727
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc (+3 lines)
Lines 26-31 Link Here
26
var Koha = {};
26
var Koha = {};
27
</script>
27
</script>
28
28
29
[% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
30
    [% Asset.js("js/opac-display-record-count.js") %]
31
[% END %]
29
[% IF lang && lang != 'en' %]
32
[% IF lang && lang != 'en' %]
30
    [% Asset.js(lang _ '/js/locale_data.js') | $raw %]
33
    [% Asset.js(lang _ '/js/locale_data.js') | $raw %]
31
[% END %]
34
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+9 lines)
Lines 283-285 Searching: Link Here
283
            - LIBRIS base URL
283
            - LIBRIS base URL
284
            - pref: LibrisURL
284
            - pref: LibrisURL
285
            - "Please only change this if you are sure it needs changing."
285
            - "Please only change this if you are sure it needs changing."
286
        -
287
            - pref: OPACDisplayRecordCount
288
              type: boolean
289
              default: no
290
              choices:
291
                  yes: Show
292
                  no: "Don't show"
293
            - the number of records next to search links in the bibliographic record detail page in the OPAC.
294
        -
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-1 / +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
1449
    [% IF ( Koha.Preference('OPACDisplayRecordCount') ) %]
1450
        NumberResultsRecord();
1451
    [% END %]
1450
    [% IF ( Koha.Preference('OPACShowMusicalInscripts') ) %]
1452
    [% IF ( Koha.Preference('OPACShowMusicalInscripts') ) %]
1451
        <script>
1453
        <script>
1452
            var interface = "[% interface | html %]";
1454
            var interface = "[% interface | html %]";
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/opac-display-record-count.js (+91 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
89
90
  console.log("json_data =  ", JSON.stringify(json_data) );
91
}
(-)a/opac/svc/elasticsearch/opac-autocomplete.pl (-1 / +53 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 Switch;
9
use utf8;
10
use Text::Unaccent;
11
use CGI::Session;
12
use Koha::SearchEngine::Elasticsearch::Browse;
13
14
my $browser = Koha::SearchEngine::Elasticsearch::Browse->new( { index => 'biblios' } );
15
my $cgi = CGI->new;
16
my $session = CGI::Session->new();
17
18
$session->param(-name=>'q', -value=>$cgi->param("q"));
19
$session->param(-name=>'key', -value=>$cgi->param("key"));
20
$session->expire('+1h');
21
22
#Chose GET in key parametre
23
given ($session->param("key")) {
24
  when ("nb_notice") {
25
    my $res = $browser->count_record(unac_string("UTF-8", $session->param("q")));
26
    print $cgi->header("application/json");
27
    print to_json($res);
28
  }
29
  #no key 404
30
  default {
31
    response404JSON();
32
  }
33
}
34
35
sub response404JSON {
36
  my $json = JSON->new->utf8;
37
  my $header_type = "application/json";
38
  my $header_status = "404";
39
  my $output = $json->encode({
40
    "error" => "No data",
41
    "description" => "Bad request",
42
  });
43
  print $cgi->header(
44
    -type => $header_type,
45
    -charset => "utf-8",
46
    -status => $header_status
47
  );
48
  print $output;
49
  print "\n";
50
}
51
52
53

Return to bug 27428