koha-cvs
[Top][All Lists]
Advanced

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

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


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

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

Modified files:
        C4             : Search.pm 

Log message:
        adding searchZOOM to Search.pm, removing from scripts and SearchMarc.pm

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

Patches:
Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.99.2.11.2.5
retrieving revision 1.99.2.11.2.6
diff -u -b -r1.99.2.11.2.5 -r1.99.2.11.2.6
--- Search.pm   21 Jul 2006 15:43:05 -0000      1.99.2.11.2.5
+++ Search.pm   21 Jul 2006 17:20:07 -0000      1.99.2.11.2.6
@@ -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.5 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.99.2.11.2.6 $' =~ /\d+/g;
           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 =head1 NAME
@@ -69,8 +69,11 @@
 &borrdata2 &borrdata3 &NewBorrowerNumber &bibitemdata &borrissues
 &getboracctrecord &ItemType &itemissues &subject &subtitle
 &addauthor &bibitems &barcodes &findguarantees &allissues
-&findguarantor &getwebsites &getwebbiblioitems &catalogsearch &itemcount2 
&FindDuplicate
-&isbnsearch &getbranchname &getborrowercategory &getborrowercategoryinfo 
&catalogsearch3 &CatSearch3 &catalogsearch4
+&findguarantor &getwebsites &getwebbiblioitems &itemcount2 &FindDuplicate
+&isbnsearch &getbranchname &getborrowercategory &getborrowercategoryinfo 
+
+&searchZOOM &catalogsearch &catalogsearch3 &CatSearch3 &catalogsearch4
+
 &getMARCnotes &getMARCsubjects &getMARCurls);
 # make all your functions, whether exported or not;
 
@@ -4016,6 +4019,139 @@
        my address@hidden;
         return $marcurlsarray;
 }  #end getMARCurls
+
+
+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)
 
 1;




reply via email to

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