- ZebraPosSet poset;
- int i, *pos_array;
- yaz_log(LOG_API,"api_records_retrieve s=%s n=%d",setname,num_recs);
-
- if (!zh->res)
- {
- zh->errCode = 30;
- zh->errString = odr_strdup (stream, setname);
- return;
- }
-
- zh->errCode = 0;
-
- if (zebra_begin_read (zh))
- return;
-
- pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
- for (i = 0; i<num_recs; i++)
- pos_array[i] = recs[i].position;
- poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
- if (!poset)
- {
- logf (LOG_DEBUG, "zebraPosSetCreate error");
- zh->errCode = 30;
- zh->errString = nmem_strdup (stream->mem, setname);
- }
- else
- {
- for (i = 0; i<num_recs; i++)
- {
- if (poset[i].term)
- {
- recs[i].errCode = 0;
- recs[i].format = VAL_SUTRS;
- recs[i].len = strlen(poset[i].term);
- recs[i].buf = poset[i].term;
- recs[i].base = poset[i].db;
- recs[i].sysno = 0;
-
- }
- else if (poset[i].sysno)
- {
- /* changed here ??? CHECK ??? */
- char *b;
- recs[i].errCode =
- zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
- stream, input_format, comp,
- &recs[i].format,
- &b,
- &recs[i].len,
- &recs[i].base);
- recs[i].buf = (char *) odr_malloc(stream,recs[i].len);
- memcpy(recs[i].buf, b, recs[i].len);
- recs[i].errString = 0; /* Hmmm !!! we should get this */
- recs[i].sysno = poset[i].sysno;
- recs[i].score = poset[i].score;
- }
- else
- {
- char num_str[20];
-
- sprintf (num_str, "%d", pos_array[i]);
- zh->errCode = 13;
- zh->errString = odr_strdup (stream, num_str);
- break;
- }
-
- }
- zebraPosSetDestroy (zh, poset, num_recs);
- }
- zebra_end_read (zh);
- xfree (pos_array);