Use HAVE_UNISTD_H when including unistd.h.
[idzebra-moved-to-github.git] / index / zebraapi.c
index 5ee16a2..1fbb956 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.174 2005-06-07 11:36:38 adam Exp $
+/* $Id: zebraapi.c,v 1.178 2005-06-14 20:28:54 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -27,7 +27,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <io.h>
 #include <process.h>
 #include <direct.h>
-#else
+#endif
+#if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -38,6 +39,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <charmap.h>
 #include <idzebra/api.h>
 
+#define DEFAULT_APPROX_LIMIT 2000000000
+
 /* simple asserts to validate the most essential input args */
 #define ASSERTZH assert(zh && zh->service)
 #define ASSERTZHRES assert(zh && zh->service && zh->res)
@@ -115,6 +118,7 @@ ZebraHandle zebra_open (ZebraService zs)
     zh->num_basenames = 0;
     zh->basenames = 0;
 
+    zh->approx_limit = DEFAULT_APPROX_LIMIT;
     zh->trans_no = 0;
     zh->trans_w_no = 0;
 
@@ -233,22 +237,16 @@ Dict dict_open_res (BFiles bfs, const char *name, int cache, int rw,
 {
     int page_size = 4096;
     char resource_str[200];
-    const char *v;
     sprintf (resource_str, "dict.%.100s.pagesize", name);
     assert(bfs);
     assert(name);
 
-    v = res_get(res, resource_str);
-    if (v)
-    {
-       page_size = atoi(v);
+    if (res_get_int(res, resource_str, &page_size) == ZEBRA_OK)
        yaz_log(YLOG_LOG, "Using custom dictionary page size %d for %s",
                page_size, name);
-    }
     return dict_open(bfs, name, cache, rw, compact_flag, page_size);
 }
 
-
 static
 struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
                                             int rw, int useshadow, Res res,
@@ -692,6 +690,12 @@ static void zebra_select_register (ZebraHandle zh, const char *new_reg)
            zebra_close_res(zh);
        }
     }
+    if (zh->res)
+    {
+       int approx = 0;
+       if (res_get_int(zh->res, "estimatehits", &approx) == ZEBRA_OK)
+           zebra_set_approx_limit(zh, approx);
+    }
 }
 
 void map_basenames_func (void *vp, const char *name, const char *value)
@@ -864,6 +868,14 @@ ZEBRA_RES zebra_select_databases (ZebraHandle zh, int num_bases,
     return ZEBRA_OK;
 }
 
+ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit)
+{
+    if (approx_limit == 0)
+       approx_limit = DEFAULT_APPROX_LIMIT;
+    zh->approx_limit = approx_limit;
+    return ZEBRA_OK;
+}
+
 ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
                           const char *setname, zint *hits)
 {
@@ -970,12 +982,20 @@ ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
            }
            else
            {
-               if (ret == ZEBRA_OK) /* only need to set it once */
+               /* only need to set it once */
+               if (pos_array[i] < zh->approx_limit && ret == ZEBRA_OK)
+               {
                    zebra_setError_zint(zh,
                                        YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
                                        pos_array[i]);
-               ret = ZEBRA_FAIL;
-                break;
+                   ret = ZEBRA_FAIL;
+                   break;
+               }
+               recs[i].buf = 0;  /* no record and no error issued */
+               recs[i].len = 0;
+               recs[i].errCode = 0;
+               recs[i].format = VAL_NONE;
+               recs[i].sysno = 0;
            }
        }
        zebra_meta_records_destroy(zh, poset, num_recs);