Added other sort index test.
[idzebra-moved-to-github.git] / index / zsets.c
index 19a6cf8..a200503 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: zsets.c,v 1.126 2007-11-30 12:19:09 adam Exp $
-   Copyright (C) 1995-2007
-   Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1995-2008 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -1307,7 +1304,13 @@ static ZEBRA_RES zebra_recid_to_sysno(ZebraHandle zh,
     int sysnos_offset = 0;
     int i;
     
-    if (zh->reg->isamb)
+    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++)
         {
@@ -1361,13 +1364,9 @@ static ZEBRA_RES zebra_recid_to_sysno(ZebraHandle zh,
                                 while (r && key_found.mem[0] == recid)
                                 {
                                     if (sysnos_offset < *no_sysnos)
-                                        sysnos[sysnos_offset] = 
+                                        sysnos[sysnos_offset++] = 
                                             key_found.mem[key_found.len-1];
-                                
-                                    yaz_log(YLOG_LOG,  "Found " ZINT_FORMAT, 
-                                            key_found.mem[key_found.len-1]);
                                     r = isamb_pp_read(pt, &key_found);
-                                    sysnos_offset++;
                                 }
                                 isamb_pp_close(pt);
                             }
@@ -1397,6 +1396,32 @@ ZEBRA_RES zebra_result_recid_to_sysno(ZebraHandle zh,
     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;
+}
                    
 
 /*