[Koha-patches] [PATCH] Improving Breeding search

Henri-Damien LAURENT henridamien at koha-fr.org
Wed May 7 09:57:20 CEST 2008


ISBN are now sanitized.
searches both Title and author fields.
---
 C4/Breeding.pm |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/C4/Breeding.pm b/C4/Breeding.pm
index 79f2e2f..b73fb6f 100644
--- a/C4/Breeding.pm
+++ b/C4/Breeding.pm
@@ -110,7 +110,7 @@ sub ImportBreeding {
             # overwrite or ignore depending on user choice
             # drop every "special" char : spaces, - ...
             $oldbiblio->{isbn} =~ s/\(.*$//;
-            $oldbiblio->{isbn} =~ tr/ -_//;
+            $oldbiblio->{isbn} =~ s/[ -_]//;
             $oldbiblio->{isbn} = uc $oldbiblio->{isbn}; 
             # search if biblio exists
             my $biblioitemnumber;
@@ -187,8 +187,18 @@ sub BreedingSearch {
     } else {
         @bind=();
         if ($title) {
-            $query .= "title like ?";
-            push(@bind,"$title%");
+	    my @words = split /[\'\s]/, $title; 
+            @bind= map {"%".$_."%"} @words;
+            if (scalar(@bind)>0) {
+	       $query.="( ";
+               $query .= "title like ? AND " x scalar(@bind);
+               $query =~ s/ AND $//;
+	       $query .= ") OR (";
+               $query .= "author like ? AND " x scalar(@bind);
+               $query =~ s/ AND $//;
+	       $query.=" )";
+	    }
+	    @bind=(@bind, at bind);
         }
         if ($title && $isbn) {
             $query .= " and ";
@@ -198,6 +208,7 @@ sub BreedingSearch {
             push(@bind,"$isbn%");
         }
     }
+    warn $query;
     $sth   = $dbh->prepare($query);
     $sth->execute(@bind);
     while (my $data = $sth->fetchrow_hashref) {
-- 
1.5.4.3




More information about the Koha-patches mailing list