Handle undefined rank handler
[idzebra-moved-to-github.git] / index / zsets.c
index cf0e7d0..d543abd 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zsets.c,v 1.47 2004-05-10 08:47:54 adam Exp $
+/* $Id: zsets.c,v 1.49 2004-06-13 18:45:25 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
@@ -207,6 +207,8 @@ ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov)
     }
     else
     {
+       const char *sort_max_str = zebra_get_resource(zh, "sortmax", "1000");
+
        yaz_log (LOG_DEBUG, "adding result set %s", name);
        s = (ZebraSet) xmalloc (sizeof(*s));
        s->next = zh->sets;
@@ -216,7 +218,10 @@ ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov)
 
        s->sort_info = (struct zset_sort_info *)
            xmalloc (sizeof(*s->sort_info));
-       s->sort_info->max_entries = 1000;
+       s->sort_info->max_entries = atoi(sort_max_str);
+       if (s->sort_info->max_entries < 2)
+           s->sort_info->max_entries = 2;
+
        s->sort_info->entries = (struct zset_sort_entry **)
            xmalloc (sizeof(*s->sort_info->entries) *
                     s->sort_info->max_entries);
@@ -709,6 +714,7 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset)
     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");
 
     sort_info = zebraSet->sort_info;
     sort_info->num_entries = 0;
@@ -717,7 +723,12 @@ void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset)
 
     yaz_log (LOG_LOG, "resultSetRank");
 
-    rank_class = zebraRankLookup (zh, res_get_def(zh->res, "rank", "rank-1"));
+    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 (rset, rfd, &key, &term_index))