koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/C4 SearchMarc.pm Search.pm [dev_week]


From: Joshua Ferraro
Subject: [Koha-cvs] koha/C4 SearchMarc.pm Search.pm [dev_week]
Date: Fri, 21 Jul 2006 17:31:41 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Joshua Ferraro <kados>  06/07/21 17:31:41

Modified files:
        C4             : SearchMarc.pm Search.pm 

Log message:
        moving subs from SearchMarc to Search

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/SearchMarc.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.36.2.28.2.3&r2=1.36.2.28.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.99.2.11.2.6&r2=1.99.2.11.2.7

Patches:
Index: SearchMarc.pm
===================================================================
RCS file: /sources/koha/koha/C4/SearchMarc.pm,v
retrieving revision 1.36.2.28.2.3
retrieving revision 1.36.2.28.2.4
diff -u -b -r1.36.2.28.2.3 -r1.36.2.28.2.4
--- SearchMarc.pm       21 Jul 2006 15:36:50 -0000      1.36.2.28.2.3
+++ SearchMarc.pm       21 Jul 2006 17:31:41 -0000      1.36.2.28.2.4
@@ -23,6 +23,7 @@
 use C4::Context;
 use C4::Biblio;
 use C4::Date;
+use C4::Search;
 use Date::Manip;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@@ -515,138 +516,6 @@
        return $marcsubjctsarray;
 }  #end getMARCsubjects
 
-sub searchZOOM {
-    use C4::Biblio;
-    my ($search_or_scan,$type,$query,$num,$startfrom,$then_sort_by) = @_;
-    my $dbh = C4::Context->dbh;
-    my $zconn=C4::Context->Zconn("biblioserver");
-
-    #warn ($type,$query,$num,$startfrom) ;
-    if ($zconn eq "error") {
-        return("error with connection",undef); #FIXME: better error handling
-    }
-
-    my $zoom_query_obj;
-
-    if ($type eq 'ccl') {
-        $zoom_query_obj = new ZOOM::Query::CCL2RPN($query,$zconn);
-    } elsif ($type eq 'cql') {
-        eval {
-            $zoom_query_obj = new ZOOM::Query::CQL2RPN($query,$zconn);
-        };
-        if ($@) {
-            return ("error: Sorry, there was a problem with your query: 
$@",undef); #FIXME: better error handling
-        }
-    } else {
-        eval {
-            $zoom_query_obj = new ZOOM::Query::PQF($query);
-        };
-        if ($@) {
-            return("error with search: $@",undef); #FIXME: better error 
handling
-        }
-    }
-
-    # PERFORM THE SEARCH
-    my $result;
-    my @results;
-    my $numresults;
-    if ($search_or_scan =~ /scan/) {
-        eval {
-            $result = $zconn->scan($zoom_query_obj);
-        };
-        if ($@) {
-            return ("error with scan: $@",undef);
-        }
-    } else {
-        eval {
-            $result = $zconn->search($zoom_query_obj);
-        };
-        if ($@) {
-            return("error with search: $@",undef); #FIXME: better error 
handling
-        }
-    }
-
-    # RESORT RESULT SET
-    if ($then_sort_by) {
-        $result->sort("yaz", "$then_sort_by")
-    }
-    # build our results and faceted searching
-    my @facets; my %facets_counter; my %facets_counter_subs; my 
@facets_counter_subs_array;
-    $numresults = 0 | $result->size() if  ($result);
-    for ( my $i=$startfrom; $i<(($startfrom+$num<=$numresults) ? 
($startfrom+$num):$numresults) ; $i++){
-        if  ($search_or_scan =~ /scan/) { # this is an index scan
-            my ($term,$occ) = $result->term($i);
-            # here we create a minimal MARC record and hand it off to the
-            # template just like a normal result ... perhaps not ideal, but
-            # it works for now FIXME: distinguish between MARC21 and UNIMARC
-            use MARC::Record;
-            my $tmprecord = MARC::Record->new();
-            $tmprecord->encoding('UTF-8');
-            my $tmptitle = MARC::Field->new( '245',' ',' ',
-                        a => $term,
-                        b => $occ);
-                        $tmprecord->append_fields($tmptitle);
-            push @results, $tmprecord->as_usmarc();
-        } else { # this is a real search
-            my $rec = $result->record($i);
-            push(@results,$rec->raw()) if $rec; #FIXME: sometimes this fails
-
-            ##### build facets ####
-            my $tmprecord = MARC::Record->new_from_usmarc($rec->raw());
-            my @subfields = $tmprecord->field('650');   #subject facets
-            my @authfields = $tmprecord->field('100');  #author facets
-            my @serfields = $tmprecord->field('440');   #series facets
-            my $subject_added_entry;
-            foreach my $subjectfield (@subfields) {
-                my @fields = $subjectfield->subfields();
-                foreach my $subfield (@fields) {
-                    my ($code,$data) = @$subfield;
-                    if ($code eq 'a') {
-                        $facets_counter{$data}++;
-                        $subject_added_entry = $data;
-                    }
-                }
-                my $fieldstring = $subjectfield->as_string();
-                $facets_counter_subs{$subject_added_entry} = $fieldstring;
-            }
-
-        }
-    }
-    #foreach my $value (keys %facets_counter_subs) {
-    #   my %facets_row = (
-    #       'facetsubjectsub' => $value,
-    #   );
-    #   push @facets_counter_subs_array, \%facets_row; 
#facets_counter_subs{$subject_added_entry};
-    #}#
-    foreach my $value (sort { $facets_counter{$b} <=> $facets_counter{$a} } 
keys %facets_counter) {
-
-        #foreach my $subvalue (keys %facets_counter_subs) {
-        #   my %facets_row = (
-        #       'facetsubjectsub' => $facets_counter_subs{$subvalue}, 
#$subvalue{$value},
-        #   );
-        #   push @facets_counter_subs_array, \%facets_row;
-        #}#
-
-
-        my %facets_row = (
-                'facetsubject' => $value,
-                'facetcount' => $facets_counter{$value},
-                'facetcountersubs' => address@hidden, 
#%facets_counter_subs->{$value},
-                );
-        push @facets,\%facets_row;
-
-    }
-    #while( my ($k, $v) = each %$facets_counter ) {
-     #       my %facets_row = (
-    #   'facetsubject' => $k,
-    #   'facetcount' => $v,
-    #   );
-    #   push @facets,\%facets_row;
-    #}#
-    return(undef,$numresults,address@hidden,@results);
-}
-
-
 
 END { }       # module clean-up code here (global destructor)
 

Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.99.2.11.2.6
retrieving revision 1.99.2.11.2.7
diff -u -b -r1.99.2.11.2.6 -r1.99.2.11.2.7
--- Search.pm   21 Jul 2006 17:20:07 -0000      1.99.2.11.2.6
+++ Search.pm   21 Jul 2006 17:31:41 -0000      1.99.2.11.2.7
@@ -35,7 +35,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.99.2.11.2.6 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.99.2.11.2.7 $' =~ /\d+/g;
           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -64,12 +64,13 @@
 
 @ISA = qw(Exporter);
 @EXPORT = qw(
+
 &CatSearch &BornameSearch &ItemInfo &KeywordSearch &subsearch
 &itemdata &bibdata &GetItems &borrdata &itemnodata &itemcount
 &borrdata2 &borrdata3 &NewBorrowerNumber &bibitemdata &borrissues
 &getboracctrecord &ItemType &itemissues &subject &subtitle
 &addauthor &bibitems &barcodes &findguarantees &allissues
-&findguarantor &getwebsites &getwebbiblioitems &itemcount2 &FindDuplicate
+&findseealso &findguarantor &getwebsites &getwebbiblioitems &itemcount2 
&FindDuplicate
 &isbnsearch &getbranchname &getborrowercategory &getborrowercategoryinfo 
 
 &searchZOOM &catalogsearch &catalogsearch3 &CatSearch3 &catalogsearch4
@@ -77,6 +78,28 @@
 &getMARCnotes &getMARCsubjects &getMARCurls);
 # make all your functions, whether exported or not;
 
+=head1 findseealso($dbh,$fields);
+
+=head2 $dbh is a link to the DB handler.
+
+use C4::Context;
+my $dbh =C4::Context->dbh;
+
+=head2 $fields is a reference to the fields array
+
+This function modify the @$fields array and add related fields to search on.
+
+=cut
+
+sub findseealso {
+    my ($dbh, $fields) = @_;
+    my $tagslib = MARCgettagslib ($dbh,1);
+    for (my $i=0;$i<=$#{$fields};$i++) {
+        my ($tag) =substr(@$fields[$i],1,3);
+        my ($subfield) =substr(@$fields[$i],4,1);
+        @$fields[$i].=','.$tagslib->{$tag}->{$subfield}->{seealso} if 
($tagslib->{$tag}->{$subfield}->{seealso});
+    }
+}
 
 =item findguarantees
 
@@ -201,87 +224,134 @@
 =cut
 #'
 sub catalogsearch {
-       my ($env,$type,$search,$num,$offset)address@hidden;
-       my $dbh = C4::Context->dbh;
-       #  foreach my $key (%$search){
-       #    $search->{$key}=$dbh->quote($search->{$key});
-       #  }
-       my ($count,@results);
-       if ($search->{'itemnumber'} ne '' || $search->{'isbn'} ne ''){
-#              print STDERR "Doing a precise search\n";
-               
($count,@results)=CatSearch($env,'precise',$search,$num,$offset);
-       } elsif ($search->{'subject'} ne ''){
-               
($count,@results)=CatSearch($env,'subject',$search,$num,$offset);
-       } elsif ($search->{'keyword'} ne ''){
-               
($count,@results)=&KeywordSearch($env,'keyword',$search,$num,$offset);
-       } else {
-               ($count,@results)=CatSearch($env,'loose',$search,$num,$offset);
+    my ($dbh, $tags, $and_or, $excluding, $operator, $value, 
$offset,$length,$orderby,$desc_or_asc) = @_;
 
+    # used for the new API
+    my ($search_or_scan,$type,$query,$num,$startfrom,$then_sort_by);
+
+    $search_or_scan = 'search';
+    $then_sort_by = '';
+    my $number_of_results = $length; # num of results to return
+    $startfrom = $offset; # offset
+    my $ccl_query;
+    for (my $i = 0 ; $i <= $#{$value} ; $i++) {
+        $ccl_query.= @$value[$i];
+    }
+    #warn "CCL: $ccl_query";
+    my ($error,$count,$facets,@results) = 
searchZOOM('search','ccl',$ccl_query,$number_of_results,$startfrom,$then_sort_by);
+
+    my @result = ();
+    my $subtitle; # Added by JF for Subtitles
+
+    # find bibids from results
+    #put them in @result
+    foreach my $rec (@results) {
+        my $record = MARC::Record->new_from_usmarc($rec);
+        my $oldbiblio = MARCmarc2koha($dbh,$record,'');
+        push @result, $oldbiblio->{'biblionumber'}; #FIXME bibid?
+    }
+    # we have bibid list. Now, loads title and author from [offset] to 
[offset]+[length]
+    my $counter = $offset;
+    # HINT : biblionumber as bn is important. The hash is fills biblionumber 
with items.biblionumber.
+    # so if you dont' has an item, you get a not nice empty value.
+    my $sth = $dbh->prepare("SELECT biblio.biblionumber as 
bn,biblioitems.*,biblio.*, itemtypes.notforloan,itemtypes.description
+                            FROM biblio
+                            LEFT JOIN biblioitems on biblio.biblionumber = 
biblioitems.biblionumber
+                            LEFT JOIN itemtypes on 
itemtypes.itemtype=biblioitems.itemtype
+                            WHERE biblio.biblionumber = ?"); 
#marc_biblio.biblionumber AND bibid = ?");
+        my $sth_subtitle = $dbh->prepare("SELECT subtitle FROM bibliosubtitle 
WHERE biblionumber=?"); # Added BY JF for Subtitles
+    my @finalresult = ();
+    my @CNresults=();
+    my $totalitems=0;
+    my $oldline;
+    my ($oldbibid, $oldauthor, $oldtitle);
+    my $sth_itemCN;
+    if (C4::Context->preference('hidelostitems')) {
+        $sth_itemCN = $dbh->prepare("select items.* from items where 
biblionumber=? and (itemlost = 0 or itemlost is NULL) order by homebranch");
+    } else {
+        $sth_itemCN = $dbh->prepare("select items.* from items where 
biblionumber=? order by homebranch");
+    }
+    my $sth_issue = $dbh->prepare("select date_due,returndate from issues 
where itemnumber=?");
+    # parse all biblios between start & end.
+    #while (($counter <= $#result) && ($counter <= ($offset + $length))) { 
#FIXME, do all of them
+    while ($counter <= $#result) {
+        # search & parse all items & note itemcallnumber
+        #warn $result[$counter];
+        $sth->execute($result[$counter]);
+        my $continue=1;
+        my $line = $sth->fetchrow_hashref;
+        my $biblionumber=$line->{bn};
+        # Return subtitles first ADDED BY JF
+                $sth_subtitle->execute($biblionumber);
+                my $subtitle_here.= $sth_subtitle->fetchrow." ";
+                chop $subtitle_here;
+                $subtitle = $subtitle_here;
+#               warn "Here's the Biblionumber ".$biblionumber;
+#                warn "and here's the subtitle: ".$subtitle_here;
+
+        # /ADDED BY JF
+
+#       $continue=0 unless $line->{bn};
+#       my $lastitemnumber;
+        $sth_itemCN->execute($biblionumber);
+        my @CNresults = ();
+        my $notforloan=1; # to see if there is at least 1 item that can be 
issued
+        while (my $item = $sth_itemCN->fetchrow_hashref) {
+            # parse the result, putting holdingbranch & itemcallnumber in 
separate array
+            # then all other fields in the main array
+
+            # search if item is on loan
+            my $date_due;
+            $sth_issue->execute($item->{itemnumber});
+            while (my $loan = $sth_issue->fetchrow_hashref) {
+                if ($loan->{date_due} and !$loan->{returndate}) {
+                    $date_due = $loan->{date_due};
+                }
+            }
+            # store this item
+            my %lineCN;
+            $lineCN{holdingbranch} = $item->{holdingbranch};
+            $lineCN{itemcallnumber} = $item->{itemcallnumber};
+            $lineCN{location} = $item->{location};
+            $lineCN{date_due} = format_date($date_due);
+            #$lineCN{notforloan} = $notforloanstatus{$line->{notforloan}} if 
($line->{notforloan}); # setting not forloan if itemtype is not for loan
+            #$lineCN{notforloan} = $notforloanstatus{$item->{notforloan}} if 
($item->{notforloan}); # setting not forloan it this item is not for loan
+            $notforloan=0 unless ($item->{notforloan} or $item->{wthdrawn} or 
$item->{itemlost});
+            push @CNresults,\%lineCN;
+            $totalitems++;
+        }
+        # save the biblio in the final array, with item and item issue status
+        my %newline;
+        %newline = %$line;
+        $newline{totitem} = $totalitems;
+        # if $totalitems == 0, check if it's being ordered.
+        if ($totalitems == 0) {
+            my $sth = $dbh->prepare("select count(*) from aqorders where 
biblionumber=? and datecancellationprinted is NULL");
+            $sth->execute($biblionumber);
+            my ($ordered) = $sth->fetchrow;
+            $newline{onorder} = 1 if $ordered;
        }
-       if ($env->{itemcount} eq '1') {
-               foreach my $data (@results){
-                       my ($counts) = itemcount2($env, 
$data->{'biblionumber'}, 'intra');
-                       my $subject2=$data->{'subject'};
-                       $subject2=~ s/ /%20/g;
-                       $data->{'itemcount'}=$counts->{'total'};
-                       my $totalitemcounts=0;
-                       foreach my $key (keys %$counts){
-                               if ($key ne 'total'){   # FIXME - Should ignore 
'order', too.
-                                       #$data->{'location'}.="$key 
$counts->{$key} ";
-                                       $totalitemcounts+=$counts->{$key};
-                                       
$data->{'locationhash'}->{$key}=$counts->{$key};
-                               }
-                       }
-                       my $locationtext='';
-                       my $locationtextonly='';
-                       my $notavailabletext='';
-                       foreach (sort keys %{$data->{'locationhash'}}) {
-                               if ($_ eq 'notavailable') {
-                                       $notavailabletext="Not available";
-                                       my $c=$data->{'locationhash'}->{$_};
-                                       
$data->{'not-available-p'}=$totalitemcounts;
-                                       if ($totalitemcounts>1) {
-                                       $notavailabletext.=" ($c)";
-                                       $data->{'not-available-plural-p'}=1;
-                                       }
-                               } else {
-                                       $locationtext.="$_";
-                                       my $c=$data->{'locationhash'}->{$_};
-                                       if ($_ eq 'Item Lost') {
-                                       $data->{'lost-p'}=$totalitemcounts;
-                                       $data->{'lost-plural-p'}=1
-                                                       if $totalitemcounts > 1;
-                                       } elsif ($_ eq 'Withdrawn') {
-                                       $data->{'withdrawn-p'}=$totalitemcounts;
-                                       $data->{'withdrawn-plural-p'}=1
-                                                       if $totalitemcounts > 1;
-                                       } elsif ($_ eq 'On Loan') {
-                                       $data->{'on-loan-p'}=$totalitemcounts;
-                                       $data->{'on-loan-plural-p'}=1
-                                                       if $totalitemcounts > 1;
-                                       } else {
-                                       $locationtextonly.=$_;
-                                       $locationtextonly.=" ($c), "
-                                                       if $totalitemcounts>1;
-                                       }
-                                       if ($totalitemcounts>1) {
-                                       $locationtext.=" ($c), ";
-                                       }
-                               }
-                       }
-                       if ($notavailabletext) {
-                               $locationtext.=$notavailabletext;
-                       } else {
-                               $locationtext=~s/, $//;
-                       }
-                       $data->{'location'}=$locationtext;
-                       $data->{'location-only'}=$locationtextonly;
-                       $data->{'subject2'}=$subject2;
-                       $data->{'use-location-flags-p'}=1; # XXX
-               }
+        $newline{biblionumber} = $biblionumber;
+        $newline{norequests} = 0;
+        $newline{norequests} = 1 if ($line->{notforloan}); # itemtype not 
issuable
+        $newline{norequests} = 1 if (!$line->{notforloan} && $notforloan); # 
itemtype issuable but all items not issuable for instance
+                $newline{subtitle} = $subtitle;  # put the subtitle in ADDED 
BY JF
+
+        my @CNresults2= @CNresults;
+        $newline{CN} = address@hidden;
+        $newline{'even'} = 1 if $#finalresult % 2 == 0;
+        $newline{'odd'} = 1 if $#finalresult % 2 == 1;
+        $newline{'timestamp'} = format_date($newline{timestamp});
+        @CNresults = ();
+        push @finalresult, \%newline;
+        $totalitems=0;
+        $counter++;
        }
-       return ($count,@results);
+    my $nbresults = $#result+1;
+    return (address@hidden, $nbresults);
 }
+
+
 sub add_html_bold_fields {
        my ($type, $data, $search) = @_;
        




reply via email to

[Prev in Thread] Current Thread [Next in Thread]