Bug 9811: Remove useless orderby management
[koha_fer] / C4 / Matcher.pm
index 4e064be..8caab0a 100644 (file)
@@ -630,23 +630,37 @@ sub get_matches {
     $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
     foreach my $matchpoint ( @{ $self->{'matchpoints'} } ) {
         my @source_keys = _get_match_keys( $source_record, $matchpoint );
+
         next if scalar(@source_keys) == 0;
 
+        # FIXME - because of a bug in QueryParser, an expression ofthe
+        # format 'isbn:"isbn1" || isbn:"isbn2" || isbn"isbn3"...'
+        # does not get parsed correctly, so we will not
+        # do AggressiveMatchOnISBN if UseQueryParser is on
+        @source_keys = C4::Koha::GetVariationsOfISBNs(@source_keys)
+          if ( $matchpoint->{index} =~ /^isbn$/i
+            && C4::Context->preference('AggressiveMatchOnISBN') )
+            && !C4::Context->preference('UseQueryParser');
+
         # build query
         my $query;
         my $error;
         my $searchresults;
         my $total_hits;
         if ( $self->{'record_type'} eq 'biblio' ) {
+
             if ($QParser) {
                 $query = join( " || ",
                     map { "$matchpoint->{'index'}:$_" } @source_keys );
             }
             else {
+                my $phr = C4::Context->preference('AggressiveMatchOnISBN') ? ',phr' : q{};
                 $query = join( " or ",
-                    map { "$matchpoint->{'index'}=$_" } @source_keys );
+                    map { "$matchpoint->{'index'}$phr=$_" } @source_keys );
             }
+
             require C4::Search;
+
             ( $error, $searchresults, $total_hits ) =
               C4::Search::SimpleSearch( $query, 0, $max_matches );
         }
@@ -696,7 +710,7 @@ sub get_matches {
     if ($self->{'record_type'} eq 'biblio') {
         require C4::Biblio;
         foreach my $marcblob (keys %matches) {
-            my $target_record = MARC::Record->new_from_usmarc($marcblob);
+            my $target_record = C4::Search::new_record_from_zebra('biblioserver',$marcblob);
             my $record_number;
             my $result = C4::Biblio::TransformMarcToKoha(C4::Context->dbh, $target_record, '');
             $record_number = $result->{'biblionumber'};