Bug 18829: Elasticsearch - Put a better display for the view of ES indexed record

To test:
- apply the patch
- go to global sysPref
- make sure that SearchEngine have "ElasticSearch" as value
- Search whatever you want in Search the catalog and select a record
- Search the link (Ctrl f) : "Elasticsearch Record :" , click on the link
- make sure that the pop-up open and you should see the elasticsearch result in JSON (the pop-up look the same as MARC preview)
- note fields are alphabetized
- from the command line delete the es record:
    curl -XDELETE es:9200/koha_kohadev_biblios/data/5
- click the preview link, it syas record not found
- check the logs - you see the error on missing record

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Axel Amghar 2019-04-29 11:27:49 +02:00 committed by Tomas Cohen Arazi
parent 942b07a0ce
commit 372aa0fb8a
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
3 changed files with 143 additions and 2 deletions

76
catalogue/showelastic.pl Executable file
View File

@ -0,0 +1,76 @@
#!/usr/bin/perl
# Koha library project www.koha-community.org
# Copyright 2020 Koha Development Team
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
# standard or CPAN modules used
use CGI qw(:standard -utf8);
use DBI;
use Encode;
use JSON;
use Try::Tiny;
# Koha modules used
use C4::Context;
use C4::Output;
use C4::Auth;
use C4::Biblio;
use C4::ImportBatch;
use C4::XSLT ;
use Koha::SearchEngine::Elasticsearch;
use LWP::Simple qw/get/;
my $input= new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "catalogue/showelastic.tt",
query => $input,
type => "intranet",
flagsrequired => { catalogue => 1 },
debug => 1,
}
);
my $biblionumber = $input->param('id');
my $es = Koha::SearchEngine::Elasticsearch->new({index=>'biblios'});
my $es_record;
my @es_fields;
try {
$es_record = $es->get_elasticsearch()->get({
index => $es->index_name,
type => 'data',
id => $biblionumber,
});
}
catch{
@es_fields = ("Error fetching record: see logs for details");
warn $_;
};
for my $field (sort keys %{$es_record} ){
push @es_fields, { $field, $es_record->{$field} };
};
$template->param( esrecord => to_json( \@es_fields ) );
output_html_with_http_headers $input, $cookie, $template->output;

View File

@ -148,6 +148,10 @@
</span>
[% END %]
[% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %]
<span id="catalogue_detail_elastic_record" class="results_summary"><span class="label">Elasticsearch Record :</span> <a href="/cgi-bin/koha/catalogue/showelastic.pl?id=[% biblionumber | uri %]" title="ELASTIC" class="previewElastic">Show</a></span>
[% END %]
[% IF ( holdcount ) %]
<span class="results_summary">
<span class="label">Holds:</span>
@ -1118,6 +1122,23 @@ Note that permanent location is a code, and location may be an authval.
</div>
</div>
<div id="elasticPreview" class="modal" tabindex="-1" role="dialog" aria-labelledby="elasticPreviewLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="elasticPreviewLabel">Elastic record</h3>
</div>
<div class="modal-body">
<div id="loading"> <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading </div>
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
</div>
</main>
</div> <!-- /.col-sm-10.col-sm-push-2 -->
@ -1710,10 +1731,18 @@ Note that permanent location is a code, and location may be an authval.
var page = $(this).attr("href");
$("#marcPreview .modal-body").load(page + " table");
$('#marcPreview').modal({show:true});
});
$("#marcPreview").on("hidden.bs.modal", function(){
$("#marcPreview .modal-body").html("<div id=\"loading\"><img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
[% IF ( Koha.Preference('SearchEngine') == 'Elasticsearch' ) %]
$("body").on("click",".previewElastic", function(e){
e.preventDefault();
var pageElastic = $(this).attr("href");
$("#elasticPreview .modal-body").load(pageElastic);
$('#elasticPreview').modal({show:true});
});
[% END %]
[% IF ( Koha.Preference('NovelistSelectStaffEnabled') && Koha.Preference('NovelistSelectStaffProfile') && ( normalized_isbn || normalized_upc ) ) %]
novSelect.loadContentForQuery({
ClientIdentifier : '[% IF normalized_isbn %][% normalized_isbn | html %][% ELSE %][% normalized_upc | html %][% END %]',
@ -2421,5 +2450,6 @@ Note that permanent location is a code, and location may be an authval.
});
[% END %]
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]

View File

@ -0,0 +1,35 @@
[% INCLUDE 'doc-head-open.inc' %]
[% USE raw %]
<title>Koha &rsaquo; Cataloging &rsaquo; MARC import</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body id="catalog_showelastic" class="catalog">
<pre id="main" style="direction: ltr;">
</pre>
</body>
<footer>
<style>
textarea
{
width: 100%;
min-height: 40em;
background-color : white;
resize:none;
}
</style>
<script>
display();
function display() {
let myJSON = JSON.stringify([% esrecord | $raw %], null, '\t');
let decode = decodeURIComponent(escape(myJSON));
let para = document.createElement('textarea');
para.disabled="yes";
para.textContent = decode;
document.getElementById('main').appendChild(para);
}
</script>
</footer>
</html>