[Net-z3950] Using records() method in Net-Z3950-ZOOM async mode

Mike Taylor mike at indexdata.com
Wed Jan 23 17:36:14 CET 2008


You need to invoke records() either before you go into the loop or
while you're going round it.  This is complicated stuff, indeed.
Sorry I don't have time to go into more detail -- check out the code
of IRSpy for a complex working example.
	http://search.cpan.org/~mirk/ZOOM-IRSpy-1.00/

 _/|_	 ___________________________________________________________________
/o ) \/  Mike Taylor    <mike at indexdata.com>    http://www.miketaylor.org.uk
)_v__/\  The Unix command to kill processes is not "kill -9".  The Unix
	 command to make a tape archive is not "tar cv".  Options are
	 optional.



Christopher Morgan writes:
 >  
 > Mike,
 > 
 > Many thanks. I'm having trouble deciding where to put the $rs->records()
 > line in the program. Part of my code is listed below. I assume that after
 > the while-loop is done, $conn->last_event() is ZOOM::Event::ZEND. Then a
 > for-loop prints out the hits from the servers. If I put
 > $r[$i-1]->records(10,3,0) in this loop (as I show after the ###), it doesn't
 > work. Should it go earlier in the program? Sorry -- this async mode is
 > tricky stuff!
 > 
 > - Chris
 > 
 > for ($i = 0; $i < @servers; $i++) {
 >     $z[$i] = new ZOOM::Connection($servers[$i], 0,
 > 				  async => 1, # asynchronous mode
 > 				  count => 1, # piggyback retrieval count
 > 				  preferredRecordSyntax => "usmarc");
 > 
 >     $r[$i] = $z[$i]->search_pqf('@attr 1=21 "civil war"');
 > 
 > while (($i = ZOOM::event(\@z)) != 0) {
 >     $ev = $z[$i-1]->last_event();
 >     print("connection ", $i-1, ": ", ZOOM::event_str($ev), "\n");
 >     if ($ev == ZOOM::Event::ZEND) {    	
 >     $size = $r[$i-1]->size();
 >     print "connection ", $i-1, ": $size hits\n";
 >     }	
 > }		
 > for ($j = 0; $j < @servers; $j++) {
 > 		for ($k = 0; $k < 4; $k++){
 > ###		$r[$j]->records(10,7,0);
 > 		print $r[$j]->record($k)->render()
 > 	  }
 > }
 > 
 > 
 > -----Original Message-----
 > From: Mike Taylor [mailto:mike at indexdata.com] 
 > Sent: Wednesday, January 23, 2008 8:08 AM
 > To: Christopher Morgan
 > Cc: net-z3950 at lists.indexdata.dk
 > Subject: [Net-z3950] Using records() method in Net-Z3950-ZOOM async mode
 > 
 > Hi, Chris.  Yes, you should be able to do this.
 > 
 > The basic approach is to set the "async" option, then when you have a
 > result-set you call $rs->records() and ignore the return value.  This issues
 > the request for the records, and eventually the server sends a response.
 > Loop on ZOOM::event() until it returns the connection that you issued the
 > records() call on and $conn->last_event() is ZOOM::Event::ZEND.
 > 
 > At that point either you will have an error -- check for it using
 > $conn->error() -- or one or more records have been returned.  You can fetch
 > the records using $rs->record().  Remember that the response may not have
 > included all the records you requested, though, so you will need to check
 > for the result of $rs->record() being undefined, and be prepared to submit a
 > followup $rs->records() request for those that are missing.
 > 
 >  _/|_	 ___________________________________________________________________
 > /o ) \/  Mike Taylor    <mike at indexdata.com>    http://www.miketaylor.org.uk
 > )_v__/\  There are some good things you can never have too much of.
 > 
 > 
 > 
 > Christopher Morgan writes:
 >  > Hi,
 >  >
 >  > I have been using a variation of Mike Taylor's async.pl program (in the
 > > examples folder of the Net-Z3950-ZOOM-1.21 distribution) with good success
 > > to search several Z39.50 servers simultaneously. 
 >  >
 >  > I'd like to be able to use the records() method in async mode to set a
 > given  > server to, say, $r[$i]->records(10, 7, 1) for retrieving records
 > (I'm  > assuming it is OK to use the records()method on an array element
 > like this).
 >  > How would I accomplish this? Can I apply a single records() setting to
 > all  > the servers in an array, and if so, how?
 >  >
 >  > Here is Mike's original code:
 >  >
 >  > use ZOOM;
 >  > @servers = ('z3950.loc.gov:7090/Voyager',
 >  > 	    'z3950.indexdata.com:210/gils',
 >  > 	    'agricola.nal.usda.gov:7190/Voyager');
 >  > for ($i = 0; $i < @servers; $i++) {
 >  >     $z[$i] = new ZOOM::Connection($servers[$i], 0,
 >  > 				  async => 1, # asynchronous mode
 >  > 				  count => 1, # piggyback retrieval count
 >  > 				  preferredRecordSyntax => "usmarc");
 >  >     $r[$i] = $z[$i]->search_pqf("mineral"); } while (($i =
 > ZOOM::event(\@z))
 >  > != 0) {
 >  >     $ev = $z[$i-1]->last_event();
 >  >     print("connection ", $i-1, ": ", ZOOM::event_str($ev), "\n");
 >  >     if ($ev == ZOOM::Event::ZEND) {
 >  > 	$size = $r[$i-1]->size();
 >  > 	print "connection ", $i-1, ": $size hits\n";
 >  > 	print $r[$i-1]->record(0)->render()
 >  > 	    if $size > 0;
 >  >     }
 >  > }
 >  >
 >  > Many thanks!
 >  >
 >  > - Chris Morgan
 >  >
 >  >
 >  > _______________________________________________
 >  > Net-z3950 mailing list
 >  > Net-z3950 at lists.indexdata.dk
 >  > http://lists.indexdata.dk/cgi-bin/mailman/listinfo/net-z3950
 > 
 > 
 > _______________________________________________
 > Net-z3950 mailing list
 > Net-z3950 at lists.indexdata.dk
 > http://lists.indexdata.dk/cgi-bin/mailman/listinfo/net-z3950



More information about the Net-z3950 mailing list