+=head2 new_record_from_zebra
+
+Given raw data from a Zebra result set, return a MARC::Record object
+
+This helper function is needed to take into account all the involved
+system preferences and configuration variables to properly create the
+MARC::Record object.
+
+If we are using GRS-1, then the raw data we get from Zebra should be USMARC
+data. If we are using DOM, then it has to be MARCXML.
+
+=cut
+
+sub new_record_from_zebra {
+
+ my $server = shift;
+ my $raw_data = shift;
+ # Set the default indexing modes
+ my $index_mode = ( $server eq 'biblioserver' )
+ ? C4::Context->config('zebra_bib_index_mode') // 'grs1'
+ : C4::Context->config('zebra_auth_index_mode') // 'dom';
+
+ my $marc_record = eval {
+ if ( $index_mode eq 'dom' ) {
+ MARC::Record->new_from_xml( $raw_data, 'UTF-8' );
+ } else {
+ MARC::Record->new_from_usmarc( $raw_data );
+ }
+ };
+
+ if ($@) {
+ return;
+ } else {
+ return $marc_record;
+ }
+
+}