/[pg-zoom]/zoom.sql
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /zoom.sql

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Thu Apr 26 18:50:59 2007 UTC revision 2 by dpavlin, Thu Apr 26 19:25:45 2007 UTC
# Line 28  my ( $host, $port, $database ) = Line 28  my ( $host, $port, $database ) =
28    
29  use ZOOM;  use ZOOM;
30  use MARC::Record;  use MARC::Record;
31    use Encode qw/encode decode/;
32    
33  my $pqf = {  my $pqf = {
34          isbn => '@attr 1=7 @attr 4=1 "%s"',          isbn => '@attr 1=7 @attr 4=1 "%s"',
# Line 51  my $conn = new ZOOM::Connection($host, $ Line 52  my $conn = new ZOOM::Connection($host, $
52    
53  $conn->option(preferredRecordSyntax => "usmarc");  $conn->option(preferredRecordSyntax => "usmarc");
54    
55  my $rs = $conn->search_pqf( q2cqf( $query ) );  my $cqf = q2cqf( $query );
56    
57    my $rs = $conn->search_pqf( $cqf );
58    
59  my $n = $rs->size();  my $n = $rs->size();
60  # fetch all results  # fetch all results
61  $rs->records(0, $n - 1, 0);  $rs->records(0, $n - 1, 0);
62    
63  warn "found $n results for $query";  warn "$n results for '$query' [$cqf]\n";
64    
65    sub strip_non_digit {
66            my $d = shift;
67            $d =~ s/^\D+//;
68            $d =~ s/\D+$//;
69            return $d;
70    }
71    
72    # fix encoding
73    sub e {
74            my $t = shift;
75            $t =~ s/éc/è/g;
76            $t =~ s/âc/æ/g;
77            $t =~ s/és/¹/g;
78            $t =~ s/éz/¾/g;
79            $t =~ s/éC/È/g;
80            $t =~ s/âC/Æ/g;
81            $t =~ s/éS/©/g;
82            $t =~ s/éZ/®/g;
83            $t =~ s/£/Ð/g;
84            warn "## $t\n";
85    #       $t = decode('iso-8859-2', $t);
86    #       return encode('utf-8',$t);
87            return $t;
88    }
89    
90  foreach my $i ( 1 .. $n ) {  foreach my $i ( 1 .. $n ) {
91          my $marc = new_from_usmarc MARC::Record( $rs->record( $i - 1 )->raw() );          my $marc = new_from_usmarc MARC::Record( $rs->record( $i - 1 )->raw() );
92    
93          return_next({          return_next({
94                  title => $marc->title,                  title => e( $marc->title ),
95                  author => $marc->author,                  author => e( $marc->author ),
96                  edition => $marc->edition,                  edition => e( $marc->edition ),
97                  date => $marc->publication_date,                  date => strip_non_digit( $marc->publication_date ),
98          });          });
99  }  }
100    
# Line 75  return undef; Line 103  return undef;
103  $$;  $$;
104    
105  -- if your terminal isn't iso-8859-2, change this!  -- if your terminal isn't iso-8859-2, change this!
106  set client_encoding  = 'iso-8859-2';  -- set client_encoding  = 'iso-8859-2';
107    
108    -- example
109    -- select * from search('title:djece');
110    -- select * from search('osman');
111    
112    select * from search('title:mor');

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26