[Yazlist] Using yaz_present to display subsets of results

Sebastian Hammer quinn at indexdata.com
Tue Nov 7 05:10:23 CET 2006


Hi Mark,

The problem, I think, is in your for() loop through the records; I think 
it indicates a misunderstanding about how yaz_record() works. Generally, 
the record offset that you give to yaz_record() is the offset into the 
result set, not into any subset identified by yaz_range(). This is 
crucial: The yaz_range() function is strictly there to help you write 
more optimized client code; you do not need to call it.

In other words, if you want to display record numbers 10 to 20 from your 
set, you loop from 10 to 20 and call yaz_record() for each record. The 
underlying code will retrieve records as necessary on demand.

However, if you call yaz_range() before you call yaz_wait(), the 
underlying code will optimize it's behavior.. it will either ask the 
server to return records along with the search recult, or submit a 
single present request to fetch the records (if you're not asking for 
too many).. it makes no difference in a quick hack, but it can make a 
dramatic difference if you're designing for many users or heavy traffic. 
Your loop over yaz_record() will be the same whether you have called 
yaz_range() first, or not.

Looking at the documentation under php.net, I can understand any 
confusion.. the 'ZOOM' abstraction attempts to make things as simple as 
possible for the client programmers, allowing you to quickly put 
together useful applications without worrying about protocol mechanics. 
Functions like yaz_range() are there to help you write better clients.

Hope this helps,

--Sebastian



Mark Jordan wrote:

> Hi Adam,
>
> I'm still missing something. Using yaz_syntax($id, "usmarc") doesn't 
> make a difference. Here's my entire script (with record formatting 
> removed -- it just prints records as XML):
>
> <?php
>
> $max_recs = 5;
> $query = $argv[1];
> $field = $argv[2];
> $start_at_rec = $argv[3];
> $query = trim($query);
> $field = trim($field);
>
> $fields = array('title' => '4', 'author' => '1003', 'subject' => '21');
>
> $query = '@attr 1=' . $fields[$field] . ' ' . $query;
> print "Query is $query\n";
> print "Starting at record $start_at_rec\n";
>
> $id = yaz_connect('troy.lib.sfu.ca:210/innopac');
> yaz_range($id, $start_at_rec, $max_recs);
> yaz_syntax($id, "usmarc");
> yaz_search($id, 'rpn', $query);
> yaz_wait();
>
> $error = yaz_error($id);
> if (!empty($error)) {
>   echo "Error: $error";
>   print "\n";
>   exit;
> } else {
>   $hits = yaz_hits($id);
>   if ($hits == '0') {
>     print "No hits\n";
>     exit;
>   }
> }
>
> for ($p = 1; $p <= $max_recs; $p++) {
>   $rec = yaz_record($id, $p, "xml; marc-8, utf-8");
>   if (empty($rec)) continue;
>   print $rec;
> }
>
> ?>
>
> BTW I'm using PHP/YAZ version  1.0.7, YAZ version 2.1.36, PHP 5.1.6 on 
> FedoraCore 5/ppc.
>
> Mark
>
> Adam Dickmeiss wrote:
>
>> Mark Jordan wrote:
>>
>>> Hello,
>>>
>>> I have been unable to figure out how to use the yaz_present() 
>>> function to return subsets of my entire result set. I couldn't find 
>>> a functional example anywhere (inc. the PHP docs and the yaz mailing 
>>> list archives) so was hoping someone can tell me what I'm doing wrong.
>>>
>>> In the following example, changing the value of $start has no effect 
>>> on the records returned by by my search:
>>>
>>> $start = '1';
>>> $number = '5';
>>> $query = '@attr 1=4 test';
>>> $id = yaz_connect('troy.lib.sfu.ca:210/innopac');
>>> yaz_range($id, $start, $number);
>>> yaz_syntax($id, 'marc21');
>>
>>
>> Use
>>  yaz_syntax($id, "usmarc");
>> instead.
>>
>>> yaz_search($id, 'rpn', $query);
>>> yaz_present($id);
>>
>> It should not be necessary to use yaz_present. (yaz_search will get 
>> the range).
>>
>> / Adam
>>
>>> yaz_wait();
>>>
>>> // Formatting of results using XSL omitted
>>>
>>>
>>> Number of records found: 1578
>>> =============================
>>> The biplane houses :poems /by Les Murray.
>>> Embedded system design /by Peter Marwedel.
>>> Hardening Windows systems /Roberta Bragg.
>>> Java 2 :the complete reference /Patrick Naughton, Herbert Schildt.
>>> Practical MMIC design /Steve Marsh.
>>>
>>>
>>> Since yaz_present() only takes the resource ID as a parameter, and 
>>> only returns TRUE or FALSE, I'm not sure how else it would be used 
>>> to produce results. The docs are sparse on this topic.
>>>
>>> Any pointers to complete examples, or to what I am doing wrong, 
>>> would be appreciated. I'd be happy to post my complete script when 
>>> it is working.
>>>
>>> Mark
>>>
>>> Mark Jordan
>>> Head of Library Systems
>>> W.A.C. Bennett Library, Simon Fraser University
>>> Burnaby, British Columbia, V5A 1S6, Canada
>>> Phone (604) 291 5753 / Fax (604) 291 3023
>>> mjordan at sfu.ca / http://www.sfu.ca/~mjordan/
>>>
>
>
> _______________________________________________
> Yazlist mailing list
> Yazlist at lists.indexdata.dk
> http://lists.indexdata.dk/cgi-bin/mailman/listinfo/yazlist
>
>

-- 
Sebastian Hammer, Index Data
quinn at indexdata.com   www.indexdata.com
Ph: (603) 209-6853 Fax: (866) 383-4485




More information about the Yazlist mailing list