+ (sset->hits)++;
+ psysno = this_sys;
+ resultSetInsertSort (zh, sset,
+ sort_criteria, num_criteria, psysno);
+ }
+ }
+ rset_close (rfd);
+
+#if 0
+ for (i = 0; i < rset->no_rset_terms; i++)
+ yaz_log (LOG_LOG, "term=\"%s\" nn=" ZINT_FORMAT
+ " type=%s count=" ZINT_FORMAT,
+ rset->rset_terms[i]->name,
+ rset->rset_terms[i]->nn,
+ rset->rset_terms[i]->flags,
+ rset->rset_terms[i]->count);
+#endif
+ *sort_status = Z_SortResponse_success;
+ yaz_log (LOG_LOG, "resultSetSortSingle end");
+}
+
+RSET resultSetRef (ZebraHandle zh, const char *resultSetId)
+{
+ ZebraSet s;
+
+ if ((s = resultSetGet (zh, resultSetId)))
+ return s->rset;
+ return NULL;
+}
+
+void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset)
+{
+ zint kno = 0;
+ struct it_key key;
+ RSFD rfd;
+ TERMID termid;
+ int i;
+ ZebraRankClass rank_class;
+ struct rank_control *rc;
+ struct zset_sort_info *sort_info;
+ const char *rank_handler_name = res_get_def(zh->res, "rank", "rank-1");
+ double cur,tot;
+ zint est=-2; /* -2 not done, -1 can't do, >0 actual estimate*/
+ zint esthits;
+ double ratio;
+
+ sort_info = zebraSet->sort_info;
+ sort_info->num_entries = 0;
+ zebraSet->hits = 0;
+ rfd = rset_open (rset, RSETF_READ);
+
+ rank_class = zebraRankLookup (zh, rank_handler_name);
+ if (!rank_class)
+ {
+ yaz_log (LOG_WARN, "No such rank handler: %s", rank_handler_name);
+ return;
+ }
+ rc = rank_class->control;
+
+ if (rset_read (rfd, &key, &termid))
+ {
+ zint psysno = key.mem[0];
+ int score;
+ void *handle =
+ (*rc->begin) (zh->reg, rank_class->class_handle, rset);
+ (zebraSet->hits)++;
+ esthits=atoi(res_get_def(zh->res,"estimatehits","0"));
+ if (!esthits)
+ est=-1; /* can not do */
+ do
+ {
+ zint this_sys = key.mem[0];
+ kno++;
+ if (this_sys != psysno)