zebrasrv: sortkeys args are optional
[idzebra-moved-to-github.git] / index / rankstatic.c
index 2b8fb20..09f593e 100644 (file)
@@ -1,8 +1,5 @@
-/* $Id: rankstatic.c,v 1.2 2005-08-19 10:48:36 adam Exp $
-   Copyright (C) 1995-2005
-   Index Data ApS
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+   Copyright (C) 1994-2011 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
@@ -15,11 +12,14 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <assert.h>
 #include <limits.h>
@@ -31,6 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #endif
 
 #include "index.h"
+#include "rank.h"
 
 static int log_level = 0;
 static int log_initialized = 0;
@@ -83,8 +84,29 @@ static void *begin (struct zebra_register *reg,
     si->no_rank_entries = 0;
     for (i = 0; i < numterms; i++)
     {
+       struct ord_list *ol = terms[i]->ol;
+
         yaz_log(log_level, "i=%d flags=%s '%s'", i, 
                 terms[i]->flags, terms[i]->name );
+
+       for (; ol; ol = ol->next)
+       {
+           const char *index_type = 0;
+           const char *db = 0;
+           const char *string_index = 0;
+           int set = -1;
+           int use = -1;
+
+           zebraExplain_lookup_ord(reg->zei,
+                                   ol->ord, &index_type, &db, &string_index);
+
+           if (string_index)
+               yaz_log(log_level, " ord=%d index_type=%s db=%s str-index=%s",
+                        ol->ord, index_type, db, string_index);
+           else
+               yaz_log(log_level, " ord=%d index_type=%s db=%s set=%d use=%d",
+                        ol->ord, index_type, db, set, use);
+       }
        if (!strncmp (terms[i]->flags, "rank,", 5)) 
            (si->no_rank_entries)++;
     }
@@ -116,15 +138,20 @@ static void add (void *set_handle, int seqno, TERMID term)
  *  score should be between 0 and 1000. If score cannot be obtained
  *  -1 should be returned.
  */
-static int calc (void *set_handle, zint sysno, zint staticrank)
+static int calc (void *set_handle, zint sysno, zint staticrank,
+                int *stop_flag)
 {
     struct rank_set_info *si = (struct rank_set_info *) set_handle;
 
     if (!si->no_rank_entries)
        return -1;   /* ranking not enabled for any terms */
 
+    /* if we set *stop_flag = 1, we stop processing (of result set list) */
     /* staticrank = 0 is highest, MAXINT lowest */
-    return INT_MAX - staticrank;  /* but score is reverse (logical) */
+    if (staticrank >= INT_MAX)
+        return 0;
+    /* but score is reverse (logical) */
+    return INT_MAX - CAST_ZINT_TO_INT(staticrank);
 }
 
 /*
@@ -156,3 +183,12 @@ static struct rank_control rank_control = {
 };
  
 struct rank_control *rank_static_class = &rank_control;
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+