+
+ZebraSet resultSetClone(ZebraHandle zh, const char *setname,
+ ZebraSet rset)
+{
+ ZebraSet nset;
+ int i;
+
+ nset = resultSetAdd(zh, setname, 1);
+ if (!nset)
+ return 0;
+
+ nset->nmem = nmem_create();
+
+ nset->num_bases = rset->num_bases;
+ nset->basenames =
+ nmem_malloc(nset->nmem, nset->num_bases * sizeof(*rset->basenames));
+ for (i = 0; i<rset->num_bases; i++)
+ nset->basenames[i] = nmem_strdup(nset->nmem, rset->basenames[i]);
+
+ if (rset->rset)
+ nset->rset = rset_dup(rset->rset);
+ if (rset->rpn)
+ nset->rpn = copy_RPNQuery(rset->rpn, nset->nmem);
+ return nset;
+}
+
+ZEBRA_RES resultSetSort(ZebraHandle zh, NMEM nmem,
+ int num_input_setnames, const char **input_setnames,
+ const char *output_setname,
+ Z_SortKeySpecList *sort_sequence, int *sort_status)
+{
+ ZebraSet sset;
+ RSET rset;
+
+ if (num_input_setnames == 0)
+ {
+ zebra_setError(zh, YAZ_BIB1_NO_RESULT_SET_NAME_SUPPLIED_ON_SORT, 0);
+ return ZEBRA_FAIL;
+ }
+ if (num_input_setnames > 1)
+ {
+ zebra_setError(zh, YAZ_BIB1_SORT_TOO_MANY_INPUT_RESULTS, 0);
+ return ZEBRA_FAIL;
+ }
+ if (!log_level_set)
+ loglevels();
+ yaz_log(log_level_sort, "result set sort input=%s output=%s",
+ *input_setnames, output_setname);
+ sset = resultSetGet(zh, input_setnames[0]);
+ if (!sset)
+ {
+ zebra_setError(zh, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ input_setnames[0]);
+ return ZEBRA_FAIL;
+ }
+ if (!(rset = sset->rset))
+ {
+ zebra_setError(zh, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ input_setnames[0]);
+ return ZEBRA_FAIL;
+ }
+ if (strcmp(output_setname, input_setnames[0]))
+ sset = resultSetClone(zh, output_setname, sset);
+ sset->sortSpec = copy_SortKeySpecList(sort_sequence, sset->nmem);
+ return resultSetSortSingle(zh, nmem, sset, rset, sort_sequence,
+ sort_status);
+}
+
+ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem,
+ ZebraSet sset, RSET rset,
+ Z_SortKeySpecList *sort_sequence,
+ int *sort_status)
+{
+ int i;
+ int ib;
+ int n = 0;
+ zint kno = 0;
+ zint psysno = 0;
+ struct it_key key;
+ struct sortKeyInfo sort_criteria[ZSET_SORT_MAX_LEVEL];
+ char *cmp_buf[ZSET_SORT_MAX_LEVEL];
+ char *tmp_cmp_buf[ZSET_SORT_MAX_LEVEL];
+ int num_criteria;
+ RSFD rfd;
+ TERMID termid;
+ TERMID *terms;
+ int numTerms = 0;
+ size_t sysno_mem_index = 0;
+
+ int numbases = zh->num_basenames;
+ yaz_log(log_level_sort, "searching %d databases",numbases);
+
+ if (zh->m_staticrank)
+ sysno_mem_index = 1;
+
+ assert(nmem); /* compiler shut up about unused param */
+ sset->sort_info->num_entries = 0;
+
+ rset_getterms(rset, 0, 0, &n);
+ terms = (TERMID *) nmem_malloc(nmem, sizeof(*terms)*n);
+ rset_getterms(rset, terms, n, &numTerms);
+
+ sset->hits = 0;
+ num_criteria = sort_sequence->num_specs;
+ if (num_criteria > ZSET_SORT_MAX_LEVEL)
+ num_criteria = ZSET_SORT_MAX_LEVEL;
+ /* set up the search criteria */
+ for (i = 0; i < num_criteria; i++)
+ {
+ Z_SortKeySpec *sks = sort_sequence->specs[i];
+ Z_SortKey *sk;
+ ZEBRA_RES res;
+
+ sort_criteria[i].ord = (int *)
+ nmem_malloc(nmem, sizeof(int)*numbases);
+ sort_criteria[i].numerical = (int *)
+ nmem_malloc(nmem, sizeof(int)*numbases);
+
+ /* initialize ord and numerical for each database */
+ for (ib = 0; ib < numbases; ib++)
+ {
+ sort_criteria[i].ord[ib] = -1;
+ sort_criteria[i].numerical[ib] = 0;
+ }
+
+ if (sks->which == Z_SortKeySpec_missingValueData)
+ {
+ zebra_setError(zh, YAZ_BIB1_UNSUPP_MISSING_DATA_ACTION, 0);
+ return ZEBRA_FAIL;
+ }
+ if (*sks->sortRelation == Z_SortKeySpec_ascending)
+ sort_criteria[i].relation = 'A';
+ else if (*sks->sortRelation == Z_SortKeySpec_descending)
+ sort_criteria[i].relation = 'D';
+ else
+ {
+ zebra_setError(zh, YAZ_BIB1_ILLEGAL_SORT_RELATION, 0);
+ return ZEBRA_FAIL;
+ }
+ if (sks->sortElement->which == Z_SortElement_databaseSpecific)
+ {
+ zebra_setError(zh, YAZ_BIB1_DATABASE_SPECIFIC_SORT_UNSUPP, 0);
+ return ZEBRA_FAIL;
+ }
+ else if (sks->sortElement->which != Z_SortElement_generic)
+ {
+ zebra_setError(zh, YAZ_BIB1_SORT_ILLEGAL_SORT, 0);
+ return ZEBRA_FAIL;
+ }
+ sk = sks->sortElement->u.generic;
+ switch (sk->which)
+ {
+ case Z_SortKey_sortField:
+ yaz_log(log_level_sort, "key %d is of type sortField", i+1);
+ for (ib = 0; ib < numbases; ib++)
+ {
+ zebraExplain_curDatabase(zh->reg->zei, zh->basenames[ib]);
+ sort_criteria[i].numerical[ib] = 0;
+ sort_criteria[i].ord[ib] =
+ zebraExplain_lookup_attr_str(zh->reg->zei,
+ zinfo_index_category_sort,
+ 0, sk->u.sortField);
+ if (sks->which != Z_SortKeySpec_null
+ && sort_criteria[i].ord[ib] == -1)
+ {
+ zebra_setError(zh,
+ YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0);
+ return ZEBRA_FAIL;
+ }
+ }
+ break;
+ case Z_SortKey_elementSpec:
+ yaz_log(log_level_sort, "key %d is of type elementSpec", i+1);
+ zebra_setError(zh, YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0);
+ return ZEBRA_FAIL;
+ case Z_SortKey_sortAttributes:
+ yaz_log(log_level_sort, "key %d is of type sortAttributes", i+1);
+ /* for every database we searched, get the sort index file
+ id (ord) and its numerical indication and store them in
+ the sort_criteria */
+ for (ib = 0; ib < numbases; ib++)
+ {
+ zebraExplain_curDatabase(zh->reg->zei, zh->basenames[ib]);
+ res = zebra_sort_get_ord(zh, sk->u.sortAttributes,
+ &sort_criteria[i].ord[ib],
+ &sort_criteria[i].numerical[ib]);
+ }
+
+ if (sks->which != Z_SortKeySpec_null && res != ZEBRA_OK)
+ return ZEBRA_FAIL;
+ break;
+ }
+ /* right now we look up the index type based on the first database
+ if the index_type's can differ between the indexes of different
+ databases (which i guess they can?) then we have to store the
+ index types for each database, just like the ord and numerical */
+ if (zebraExplain_lookup_ord(zh->reg->zei, sort_criteria[i].ord[0],
+ &sort_criteria[i].index_type,
+ 0, 0))
+ {
+ zebra_setError(zh, YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0);
+ return ZEBRA_FAIL;
+ }
+ }
+ /* allocate space for each cmpare buf + one extra for tmp comparison */
+ /* cmp_buf is an array of array, the first dimension is the criteria and the second dimension are
+ all other result entries to compare against. This is slowly filled when records are processed.
+ tmp_cmp_buf is an array with a value of the current record for each criteria
+ */
+ for (i = 0; i<num_criteria; i++)
+ {
+ cmp_buf[i] = xmalloc(sset->sort_info->max_entries
+ * SORT_IDX_ENTRYSIZE);
+ tmp_cmp_buf[i] = xmalloc(SORT_IDX_ENTRYSIZE);
+ }
+ rfd = rset_open(rset, RSETF_READ);
+ while (rset_read(rfd, &key, &termid))
+ {
+ zint this_sys = key.mem[sysno_mem_index];
+ if (log_level_searchhits)
+ key_logdump_txt(log_level_searchhits, &key, termid->name);
+ kno++;
+ if (this_sys != psysno)
+ {
+ int database_no = 0;
+ if ((sset->hits & 255) == 0 && zh->break_handler_func)
+ {
+ if (zh->break_handler_func(zh->break_handler_data))
+ {
+ rset_set_hits_limit(rset, 0);
+ break;
+ }
+ }
+ (sset->hits)++;
+ psysno = this_sys;
+
+ /* determine database from the term, but only bother if more than
+ one database is in use*/
+ if (numbases > 1 && termid->ol)
+ {
+ const char *this_db = 0;
+ if (zebraExplain_lookup_ord(zh->reg->zei, termid->ol->ord, 0, &this_db, 0)
+ == 0 && this_db)
+ {
+ for (ib = 0; ib < numbases; ib++)
+ if (!strcmp(this_db, zh->basenames[ib]))
+ database_no = ib;
+ }
+ }
+#if 0
+ yaz_log(YLOG_LOG, "sysno=" ZINT_FORMAT " database_no=%d", this_sys,
+ database_no);
+ ord_list_print(termid->ol);
+#endif
+ resultSetInsertSort(zh, sset, database_no,
+ sort_criteria, num_criteria, psysno, cmp_buf,
+ tmp_cmp_buf);
+ }
+ }
+ rset_close(rfd);
+
+ /* free the compare buffers */
+ for (i = 0; i<num_criteria; i++)
+ {
+ xfree(cmp_buf[i]);
+ xfree(tmp_cmp_buf[i]);
+ }
+
+ yaz_log(log_level_sort, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, sort",
+ kno, sset->hits);
+ for (i = 0; i < numTerms; i++)
+ yaz_log(log_level_sort, "term=\"%s\" type=%s count=" ZINT_FORMAT,
+ terms[i]->name, terms[i]->flags, terms[i]->rset->hits_count);
+ *sort_status = Z_SortResponse_success;
+ return ZEBRA_OK;
+}
+
+RSET resultSetRef(ZebraHandle zh, const char *resultSetId)
+{
+ ZebraSet s;
+
+ if ((s = resultSetGet(zh, resultSetId)))
+ return s->rset;
+ return NULL;
+}
+
+ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet,
+ RSET rset, NMEM nmem)
+{
+ struct it_key key;
+ TERMID termid;
+ TERMID *terms;
+ zint kno = 0;
+ int numTerms = 0;
+ int n = 0;
+ int i;
+ ZebraRankClass rank_class;
+ struct zset_sort_info *sort_info;
+ const char *rank_handler_name = res_get_def(zh->res, "rank", "rank-1");
+ size_t sysno_mem_index = 0;
+
+ if (zh->m_staticrank)
+ sysno_mem_index = 1;
+
+ if (!log_level_set)
+ loglevels();
+ sort_info = zebraSet->sort_info;
+ sort_info->num_entries = 0;
+ zebraSet->hits = 0;
+ zebraSet->estimated_hit_count = 0;
+ rset_getterms(rset, 0, 0, &n);
+ terms = (TERMID *) nmem_malloc(nmem, sizeof(*terms)*n);
+ rset_getterms(rset, terms, n, &numTerms);
+
+ rank_class = zebraRankLookup(zh, rank_handler_name);
+ if (!rank_class)
+ {
+ yaz_log(YLOG_WARN, "No such rank handler: %s", rank_handler_name);
+ zebra_setError(zh, YAZ_BIB1_UNSUPP_SEARCH, "Cannot find rank handler");
+ return ZEBRA_FAIL;
+ }
+ else
+ {
+ RSFD rfd = rset_open(rset, RSETF_READ);
+ struct rank_control *rc = rank_class->control;
+ int score;
+ zint count = 0;
+ void *handle = (*rc->begin) (zh->reg, rank_class->class_handle, rset,
+ nmem, terms, numTerms);
+ zint psysno = 0; /* previous doc id / sys no */
+ zint pstaticrank = 0; /* previous static rank */
+ int stop_flag = 0;
+ while (rset_read(rfd, &key, &termid))
+ {
+ zint this_sys = key.mem[sysno_mem_index];
+
+ zint seqno = key.mem[key.len-1];
+ kno++;
+ if (log_level_searchhits)
+ key_logdump_txt(log_level_searchhits, &key, termid->name);
+ if (this_sys != psysno)
+ { /* new record .. */
+ if (!(rfd->counted_items & 255) && zh->break_handler_func)
+ {
+ if (zh->break_handler_func(zh->break_handler_data))
+ {
+ yaz_log(YLOG_LOG, "Aborted search");
+ stop_flag = 1;
+ }
+ }
+ if (rfd->counted_items > rset->hits_limit)
+ stop_flag = 1;
+ if (stop_flag)
+ {
+ zebraSet->estimated_hit_count = 1;
+ break;
+ }
+ if (psysno)
+ { /* only if we did have a previous record */
+ score = (*rc->calc)(handle, psysno, pstaticrank,
+ &stop_flag);
+ /* insert the hit. A=Ascending */
+ resultSetInsertRank(zh, sort_info, psysno, score, 'A');
+ count++;
+ }
+ psysno = this_sys;
+ if (zh->m_staticrank)
+ pstaticrank = key.mem[0];
+ }
+ (*rc->add)(handle, CAST_ZINT_TO_INT(seqno), termid);
+ }
+ /* no more items */
+ if (psysno)
+ { /* we had - at least - one record */
+ score = (*rc->calc)(handle, psysno, pstaticrank, &stop_flag);
+ /* insert the hit. A=Ascending */
+ resultSetInsertRank(zh, sort_info, psysno, score, 'A');
+ count++;
+ }
+ (*rc->end)(zh->reg, handle);
+ rset_close(rfd);
+ }
+ zebraSet->hits = rset->hits_count;
+
+ yaz_log(log_level_searchterms, ZINT_FORMAT " keys, "
+ ZINT_FORMAT " sysnos, rank", kno, zebraSet->hits);
+ for (i = 0; i < numTerms; i++)
+ {
+ yaz_log(log_level_searchterms, "term=\"%s\" type=%s count="
+ ZINT_FORMAT,
+ terms[i]->name, terms[i]->flags, terms[i]->rset->hits_count);
+ }
+ return ZEBRA_OK;
+}
+
+ZebraRankClass zebraRankLookup(ZebraHandle zh, const char *name)
+{
+ ZebraRankClass p = zh->reg->rank_classes;
+ while (p && strcmp(p->control->name, name))
+ p = p->next;
+ if (p && !p->init_flag)
+ {
+ if (p->control->create)
+ p->class_handle = (*p->control->create)(zh);
+ p->init_flag = 1;
+ }
+ return p;
+}
+
+void zebraRankInstall(struct zebra_register *reg, struct rank_control *ctrl)
+{
+ ZebraRankClass p = (ZebraRankClass) xmalloc(sizeof(*p));
+ p->control = (struct rank_control *) xmalloc(sizeof(*p->control));
+ memcpy(p->control, ctrl, sizeof(*p->control));
+ p->control->name = xstrdup(ctrl->name);
+ p->init_flag = 0;
+ p->next = reg->rank_classes;
+ reg->rank_classes = p;
+}
+
+void zebraRankDestroy(struct zebra_register *reg)
+{
+ ZebraRankClass p = reg->rank_classes;
+ while (p)
+ {
+ ZebraRankClass p_next = p->next;
+ if (p->init_flag && p->control->destroy)
+ (*p->control->destroy)(reg, p->class_handle);
+ xfree(p->control->name);
+ xfree(p->control);
+ xfree(p);
+ p = p_next;
+ }
+ reg->rank_classes = NULL;
+}
+
+static int trav_rset_for_termids(RSET rset, TERMID *termid_array,
+ zint *hits_array, int *approx_array)
+{
+ int no = 0;
+ int i;
+ for (i = 0; i<rset->no_children; i++)
+ no += trav_rset_for_termids(rset->children[i],
+ (termid_array ? termid_array + no : 0),
+ (hits_array ? hits_array + no : 0),
+ (approx_array ? approx_array + no : 0));
+ if (rset->term)
+ {
+ if (termid_array)
+ termid_array[no] = rset->term;
+ if (hits_array)
+ hits_array[no] = rset->hits_count;
+ if (approx_array)
+ approx_array[no] = rset->hits_approx;
+#if 0
+ yaz_log(YLOG_LOG, "rset=%p term=%s limit=" ZINT_FORMAT
+ " count=" ZINT_FORMAT,
+ rset, rset->term->name, rset->hits_limit, rset->hits_count);
+#endif
+ no++;
+ }
+ return no;
+}
+
+ZEBRA_RES zebra_result_set_term_no(ZebraHandle zh, const char *setname,
+ int *num_terms)
+{
+ ZebraSet sset = resultSetGet(zh, setname);
+ *num_terms = 0;
+ if (sset)
+ {
+ *num_terms = trav_rset_for_termids(sset->rset, 0, 0, 0);
+ return ZEBRA_OK;
+ }
+ return ZEBRA_FAIL;
+}
+
+ZEBRA_RES zebra_result_set_term_info(ZebraHandle zh, const char *setname,
+ int no, zint *count, int *approx,
+ char *termbuf, size_t *termlen,
+ const char **term_ref_id)
+{
+ ZebraSet sset = resultSetGet(zh, setname);
+ if (sset)
+ {
+ int num_terms = trav_rset_for_termids(sset->rset, 0, 0, 0);
+ if (no >= 0 && no < num_terms)
+ {
+ TERMID *term_array = xmalloc(num_terms * sizeof(*term_array));
+ zint *hits_array = xmalloc(num_terms * sizeof(*hits_array));
+ int *approx_array = xmalloc(num_terms * sizeof(*approx_array));
+
+ trav_rset_for_termids(sset->rset, term_array,
+ hits_array, approx_array);
+
+ if (count)
+ *count = hits_array[no];
+ if (approx)
+ *approx = approx_array[no];
+ if (termbuf)
+ {
+ char *inbuf = term_array[no]->name;
+ size_t inleft = strlen(inbuf);
+ size_t outleft = *termlen - 1;
+
+ if (zh->iconv_from_utf8 != 0)
+ {
+ char *outbuf = termbuf;
+ size_t ret;
+
+ ret = yaz_iconv(zh->iconv_from_utf8, &inbuf, &inleft,
+ &outbuf, &outleft);
+ if (ret == (size_t)(-1))
+ *termlen = 0;
+ else
+ {
+ yaz_iconv(zh->iconv_from_utf8, 0, 0,
+ &outbuf, &outleft);
+ *termlen = outbuf - termbuf;
+ }
+ }
+ else
+ {
+ if (inleft > outleft)
+ inleft = outleft;
+ *termlen = inleft;
+ memcpy(termbuf, inbuf, *termlen);
+ }
+ termbuf[*termlen] = '\0';
+ }
+ if (term_ref_id)
+ *term_ref_id = term_array[no]->ref_id;
+
+ xfree(term_array);
+ xfree(hits_array);
+ xfree(approx_array);
+ return ZEBRA_OK;
+ }
+ }
+ return ZEBRA_FAIL;
+}
+
+ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
+ zint sysno, zebra_snippets *snippets)
+{
+ ZebraSet sset = resultSetGet(zh, setname);
+ yaz_log(YLOG_DEBUG, "zebra_get_hit_vector setname=%s zysno=" ZINT_FORMAT,
+ setname, sysno);
+ if (!sset)
+ return ZEBRA_FAIL;
+ else
+ {
+ struct rset_key_control *kc = zebra_key_control_create(zh);
+ NMEM nmem = nmem_create();
+ struct it_key key;
+ RSET rsets[2], rset_comb;
+ RSET rset_temp = rset_create_temp(nmem, kc, kc->scope,
+ res_get(zh->res, "setTmpDir"),0 );
+
+ TERMID termid;
+ RSFD rsfd = rset_open(rset_temp, RSETF_WRITE);
+
+ key.mem[0] = sysno;
+ key.mem[1] = 0;
+ key.mem[2] = 0;
+ key.mem[3] = 0;
+ key.len = 2;
+ rset_write(rsfd, &key);
+ rset_close(rsfd);
+
+ rsets[0] = rset_temp;
+ rsets[1] = rset_dup(sset->rset);
+
+ rset_comb = rset_create_and(nmem, kc, kc->scope, 2, rsets);
+
+ rsfd = rset_open(rset_comb, RSETF_READ);
+
+ while (rset_read(rsfd, &key, &termid))
+ {
+ if (termid)
+ {
+ struct ord_list *ol;
+ for (ol = termid->ol; ol; ol = ol->next)
+ {
+ zebra_snippets_append(snippets, key.mem[key.len-1], 0,
+ ol->ord, termid->name);
+ }
+ }
+ }
+ rset_close(rsfd);
+
+ rset_delete(rset_comb);
+ nmem_destroy(nmem);
+ kc->dec(kc);
+ }
+ return ZEBRA_OK;
+}
+
+static ZEBRA_RES zebra_recid_to_sysno(ZebraHandle zh,
+ const char **basenames, int num_bases,
+ zint recid,
+ zint *sysnos, int *no_sysnos)
+{
+ ZEBRA_RES res = ZEBRA_OK;
+ int sysnos_offset = 0;
+ int i;
+
+ if (!zh->reg->isamb || !zh->m_segment_indexing)
+ {
+ if (sysnos_offset < *no_sysnos)
+ *sysnos = recid;
+ sysnos_offset++;
+ }
+ else
+ {
+ for (i = 0; res == ZEBRA_OK && i < num_bases; i++)
+ {
+ const char *database = basenames[i];
+ if (zebraExplain_curDatabase(zh->reg->zei, database) == 0)
+ {
+ const char *index_type = "w";
+ const char *use_string = "_ALLRECORDS";
+ int ord;
+ zinfo_index_category_t cat = zinfo_index_category_alwaysmatches;
+ ord = zebraExplain_lookup_attr_str(zh->reg->zei, cat,
+ index_type, use_string);
+ if (ord != -1)
+ {
+ char ord_buf[32];
+ int ord_len = key_SU_encode(ord, ord_buf);
+ char *info;
+
+ ord_buf[ord_len] = '\0';
+
+ info = dict_lookup(zh->reg->dict, ord_buf);
+ if (info)
+ {
+ if (*info != sizeof(ISAM_P))
+ {
+ res = ZEBRA_FAIL;
+ }
+ else
+ {
+ ISAM_P isam_p;
+ ISAMB_PP pt;
+ struct it_key key_until, key_found;
+ int i = 0;
+ int r;
+
+ memcpy(&isam_p, info+1, sizeof(ISAM_P));
+
+ pt = isamb_pp_open(zh->reg->isamb, isam_p, 2);
+ if (!pt)
+ res = ZEBRA_FAIL;
+ else
+ {
+ key_until.mem[i++] = recid;
+ key_until.mem[i++] = 0; /* section_id */
+ if (zh->m_segment_indexing)
+ key_until.mem[i++] = 0; /* segment */
+ key_until.mem[i++] = 0;
+ key_until.len = i;
+
+ r = isamb_pp_forward(pt, &key_found, &key_until);
+ while (r && key_found.mem[0] == recid)
+ {
+ if (sysnos_offset < *no_sysnos)
+ sysnos[sysnos_offset++] =
+ key_found.mem[key_found.len-1];
+ r = isamb_pp_read(pt, &key_found);
+ }
+ isamb_pp_close(pt);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ *no_sysnos = sysnos_offset;
+ return res;
+}
+
+ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
+ const char *setname,
+ zint recid,
+ zint *sysnos, int *no_sysnos)
+{
+ const char **basenames;
+ int num_bases;
+ ZEBRA_RES res;
+
+ res = resultSetGetBaseNames(zh, setname, &basenames, &num_bases);
+ if (res != ZEBRA_OK)
+ return ZEBRA_FAIL;
+
+ return zebra_recid_to_sysno(zh, basenames, num_bases,
+ recid, sysnos, no_sysnos);
+}
+
+void zebra_count_set(ZebraHandle zh, RSET rset, zint *count,
+ zint approx_limit)
+{
+ zint psysno = 0;
+ struct it_key key;
+ RSFD rfd;
+
+ yaz_log(YLOG_DEBUG, "count_set");
+
+ rset->hits_limit = approx_limit;
+
+ *count = 0;
+ rfd = rset_open(rset, RSETF_READ);
+ while (rset_read(rfd, &key,0 /* never mind terms */))
+ {
+ if (key.mem[0] != psysno)
+ {
+ psysno = key.mem[0];
+ if (rfd->counted_items >= rset->hits_limit)
+ break;
+ }
+ }
+ rset_close(rfd);
+ *count = rset->hits_count;
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+