6 use Net::Z3950::SimpleServer;
10 my $max_records = 3; # XXX configure this
11 my $max_result_sets = 10;
21 $this->{HANDLE} = $session;
22 $this->{IMP_NAME} = "Biblio Z39.50";
23 $this->{IMP_VER} = "0.2";
24 $session->{SETS} = {};
32 diag "SearchHandle ",Dumper($this);
34 my $session = $this->{HANDLE};
35 my $rpn = $this->{RPN};
38 eval { $query = $rpn->{query}->render(); };
39 warn "ERROR: $@" if $@;
40 if ( $@ && ref($@) ) { ## Did someone/something report any errors?
41 $this->{ERR_CODE} = $@->{errcode};
42 $this->{ERR_STR} = $@->{errstr};
46 diag "search for $query";
48 my $setname = $this->{SETNAME};
49 my $repl_set = $this->{REPL_SET};
50 diag "SETNAME $setname REPL_SET $repl_set";
52 unless ( $result = COBISS->search( $query ) ) {
53 $this->{ERR_CODE} = 108;
56 my $hits = $COBISS::hits || diag "no results for $query";
57 diag "got $hits hits";
60 upper => $hits < $max_records ? $max_records : $hits,
61 data => $result->{'resultElements'}, # FIXME
63 my $sets = $session->{SETS};
65 if ( defined( $sets->{$setname} ) && !$repl_set ) {
66 $this->{ERR_CODE} = 21;
69 if ( scalar keys %$sets >= $max_result_sets ) {
70 $this->{ERR_CODE} = 112;
71 $this->{ERR_STR} = "Max number is $max_result_sets";
74 $sets->{$setname} = $rs;
75 $this->{HITS} = $session->{HITS} = $hits;
76 $session->{QUERY} = $query;
81 my $session = $this->{HANDLE};
82 my $setname = $this->{SETNAME};
83 my $req_form = $this->{REQ_FORM};
84 my $offset = $this->{OFFSET};
85 my $sets = $session->{SETS};
86 my $hits = $session->{HITS};
92 if ( !defined( $rs = $sets->{$setname} ) ) {
93 $this->{ERR_CODE} = 30;
96 if ( $offset > $hits ) {
97 $this->{ERR_CODE} = 13;
100 $this->{BASENAME} = "HtmlZ3950";
102 # if ( !defined($req_form) || ( $req_form eq &Net::Z3950::OID::xml ) )
105 $this->{REP_FORM} = &Net::Z3950::OID::xml;
106 $this->{RECORD} = '<xml>FIXME: not implementd</xml>';
108 elsif ( $req_form eq &Net::Z3950::OID::unimarc ) { # FIXME convert to usmarc
109 $this->{REP_FORM} = &Net::Z3950::OID::unimarc;
110 $this->{RECORD} = COBISS->fetch_rec('unimarc');
112 elsif ( $req_form eq &Net::Z3950::OID::usmarc ) { # FIXME convert to usmarc
113 $this->{REP_FORM} = &Net::Z3950::OID::usmarc;
114 $this->{RECORD} = COBISS->fetch_rec('usmarc');
116 else { ## Unsupported record format
117 $this->{ERR_CODE} = 239;
118 $this->{ERR_STR} = $req_form;
121 if ( $offset == $hits ) {
133 my $z = new Net::Z3950::SimpleServer(
134 INIT => \&InitHandle,
135 SEARCH => \&SearchHandle,
136 FETCH => \&FetchHandle,
137 CLOSE => \&CloseHandle
139 $z->launch_server( $0, @ARGV );
141 package Net::Z3950::RPN::And;
145 return $this->[0]->render() . ' AND ' . $this->[1]->render();
148 package Net::Z3950::RPN::Or;
152 return $this->[0]->render() . ' OR ' . $this->[1]->render();
155 package Net::Z3950::RPN::AndNot;
159 return $this->[0]->render() . ' AND NOT ' . $this->[1]->render();
162 package Net::Z3950::RPN::Term;
164 use Data::Dump qw(dump);
168 my ($this,$from) = @_;
170 print "render ", dump($this);
172 my $usemap = eval '$' . $from . '::usemap';
174 warn "# $from usermap ",dump($usemap);
178 foreach my $attr ( @{ $this->{attributes} } ) {
179 my $type = $attr->{attributeType};
180 my $value = $attr->{attributeValue};
181 $attributes->{$type} = $value;
183 if ( defined( my $use = $attributes->{1} ) ) {
184 if ( defined( my $field = $usemap->{$use} ) ) {
188 die { errcode => 114, errstr => $use }; ## Unsupported use attribute
191 if ( defined( my $rel = $attributes->{2} ) )
192 { ## No relation attributes supported
194 die { errcode => 117, errstr => $rel };
197 if ( defined( my $pos = $attributes->{3} ) )
198 { ## No position attributes either
200 die { errcode => 119, errstr => $pos };
203 if ( defined( my $struc = $attributes->{4} ) ) { ## No structure
204 if ( ( $struc != 1 ) && ( $struc != 2 ) ) {
205 die { errcode => 118, errstr => $struc };
208 if ( defined( $attributes->{5} ) ) { ## No truncation
209 die { errcode => 113, errstr => 5 };
211 my $comp = $attributes->{6};
213 if ( defined($comp) && ( $comp >= 2 ) ) {
214 $prefix = "all$prefix= ";
217 $prefix = "$prefix=";
221 my $q = $prefix . $this->{term};