Added function zebra_create_rset_isam .
[idzebra-moved-to-github.git] / index / rpnscan.c
index 79b12aa..3312157 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rpnscan.c,v 1.20 2007-11-01 16:01:33 adam Exp $
+/* $Id: rpnscan.c,v 1.23 2007-12-03 11:49:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -79,31 +79,6 @@ static ZEBRA_RES trans_scan_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     return ZEBRA_OK;
 }
 
-static void 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;
-}
-
 static void get_first_snippet_from_rset(ZebraHandle zh, 
                                         RSET rset, zebra_snippets *snippets, 
                                         zint *sysno)
@@ -238,7 +213,7 @@ static int scan_save_set(ZebraHandle zh, ODR stream, NMEM nmem,
             rset = rset_create_and(nmem, kc, kc->scope, 2, rsets);
         }
         /* count it */
-        count_set(zh, rset, &count, approx_limit);
+        zebra_count_set(zh, rset, &count, approx_limit);
 
         if (pos != -1)
         {
@@ -290,7 +265,7 @@ static ZEBRA_RES rpn_scan_norm(ZebraHandle zh, ODR stream, NMEM nmem,
 {
     struct scan2_info_entry *ar = nmem_malloc(nmem, sizeof(*ar) * ord_no);
     struct rpn_char_map_info rcmi;
-    zebra_map_t zm = zebra_map_get(zh->reg->zebra_maps, index_type);
+    zebra_map_t zm = zebra_map_get_or_add(zh->reg->zebra_maps, index_type);
     int i, dif;
     int after_pos;
     int pos = 0;
@@ -471,7 +446,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
                   const Odr_oid *attributeset,
                   int num_bases, char **basenames,
                   int *position, int *num_entries, ZebraScanEntry **list,
-                  int *is_partial, RSET limit_set)
+                  int *is_partial, const char *set_name)
 {
     int base_no;
     int ords[RPN_MAX_ORDS], ord_no = 0;
@@ -484,6 +459,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     NMEM nmem;
     ZEBRA_RES res;
     struct rset_key_control *kc = 0;
+    RSET limit_set = 0;
 
     *list = 0;
     *is_partial = 0;
@@ -491,37 +467,38 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     if (!attributeset)
         attributeset = yaz_oid_attset_bib_1;
 
-    if (!limit_set) /* no limit set given already */
+    if (!set_name)
     {
         /* see if there is a @attr 8=set */
         AttrType termset;
         int termset_value_numeric;
-        const char *termset_value_string;
+        const char *termset_value_string = 0;
         attr_init_APT(&termset, zapt, 8);
         termset_value_numeric =
             attr_find_ex(&termset, NULL, &termset_value_string);
         if (termset_value_numeric != -1)
         {
-            char resname[32];
-            const char *termset_name = 0;
-            
             if (termset_value_numeric != -2)
             {
+                char resname[32];
                 sprintf(resname, "%d", termset_value_numeric);
-                termset_name = resname;
+                set_name = odr_strdup(stream, resname); 
             }
             else
-                termset_name = termset_value_string;
-            
-            limit_set = resultSetRef(zh, termset_name);
+                set_name = odr_strdup(stream, termset_value_string);
+        }
+    }
 
-            if (!limit_set)
-            {
-                zebra_setError(zh, 
-                               YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
-                               termset_name);
-                return ZEBRA_FAIL;
-            }
+    if (set_name)
+    {
+        limit_set = resultSetRef(zh, set_name);
+        
+        if (!limit_set)
+        {
+            zebra_setError(zh, 
+                           YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+                           set_name);
+            return ZEBRA_FAIL;
         }
     }
 
@@ -543,7 +520,7 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     if (sort_flag)
     {
         return rpn_facet(zh, stream, zapt, attributeset, position, num_entries,
-                         list, is_partial, limit_set);
+                         list, is_partial, set_name);
     }
     for (base_no = 0; base_no < num_bases; base_no++)
     {
@@ -575,8 +552,8 @@ ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     kc = zebra_key_control_create(zh);
 
     res = rpn_scan_norm(zh, stream, nmem, kc, zapt, position, num_entries,
-                        list,
-                        is_partial, limit_set, index_type, ord_no, ords);
+                        list, is_partial, limit_set,
+                        index_type, ord_no, ords);
     nmem_destroy(nmem);
     (*kc->dec)(kc);
     return res;