Fix leak for rset_key_control
[idzebra-moved-to-github.git] / index / zsets.c
index 4094d72..949ace4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zsets.c,v 1.92 2005-08-18 19:20:38 adam Exp $
+/* $Id: zsets.c,v 1.96 2005-10-28 07:25:30 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -870,31 +870,42 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet,
        void *handle =
            (*rc->begin) (zh->reg, rank_class->class_handle, rset, nmem,
                          terms, numTerms);
-       zint psysno = 0;
+       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)
-           {
+           if (this_sys != psysno) 
+           {   /* new record .. */
                if (rfd->counted_items > rset->hits_limit)
                    break;
                if (psysno)
-               {
-                   score = (*rc->calc) (handle, 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++;
+                   if (stop_flag)
+                       break;
                }
                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)
-       {
-           score = (*rc->calc)(handle, 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++;
        }
@@ -1061,7 +1072,7 @@ ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
                                    zint sysno, zebra_snippets *snippets)
 {
     ZebraSet sset = resultSetGet(zh, setname);
-    yaz_log(YLOG_LOG, "zebra_get_hit_vector setname=%s zysno=" ZINT_FORMAT,
+    yaz_log(YLOG_DEBUG, "zebra_get_hit_vector setname=%s zysno=" ZINT_FORMAT,
            setname, sysno);
     if (!sset)
        return ZEBRA_FAIL;
@@ -1100,7 +1111,6 @@ ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
                for (ol = termid->ol; ol; ol = ol->next)
                {
                    zebra_snippets_append(snippets, key.mem[key.len-1],
-                                         termid->reg_type,
                                          ol->ord, termid->name);
                }
            }
@@ -1109,6 +1119,7 @@ ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname,
        
        rset_delete(rset_comb);
        nmem_destroy(nmem);
+       kc->dec(kc);
     }
     return ZEBRA_OK;
 }