Koha/catalogue/showelastic.pl
Axel Amghar 372aa0fb8a
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>
2023-04-14 15:39:43 -03:00

76 lines
1.9 KiB
Perl
Executable file

#!/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;