+ (*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)