Pass a stop_flag to ranking method calc. When set to 1, it signals
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 19 Aug 2005 11:04:23 +0000 (11:04 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 19 Aug 2005 11:04:23 +0000 (11:04 +0000)
stop of result set processing.

index/index.h
index/rank1.c
index/rankstatic.c
index/zsets.c
index/zvrank.c

index d620b87..e9c8f50 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: index.h,v 1.148 2005-08-19 09:21:34 adam Exp $
+/* $Id: index.h,v 1.149 2005-08-19 11:04:23 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -333,7 +333,8 @@ struct rank_control {
      * int rssize;     // number of records in result set (estimate?)
      */
     void (*end)(struct zebra_register *reg, void *set_handle);
-    int (*calc)(void *set_handle, zint sysno, zint staticrank);
+    int (*calc)(void *set_handle, zint sysno, zint staticrank,
+               int *stop_flag);
     void (*add)(void *set_handle, int seqno, TERMID term);
 };
 
index fb3529e..44220c1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rank1.c,v 1.26 2005-08-19 09:21:34 adam Exp $
+/* $Id: rank1.c,v 1.27 2005-08-19 11:04:23 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -188,7 +188,8 @@ 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)
 {
     int i, lo, divisor, score = 0;
     struct rank_set_info *si = (struct rank_set_info *) set_handle;
index 2b8fb20..9abc7ec 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rankstatic.c,v 1.2 2005-08-19 10:48:36 adam Exp $
+/* $Id: rankstatic.c,v 1.3 2005-08-19 11:04:23 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -116,13 +116,15 @@ 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) */
 }
index ed60386..a4b596f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zsets.c,v 1.93 2005-08-19 09:21:34 adam Exp $
+/* $Id: zsets.c,v 1.94 2005-08-19 11:04:23 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -872,6 +872,7 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet,
                          terms, numTerms);
        zint psysno = 0;  /* previous doc id / sys no */
        zint pstaticrank = 0; /* previous static rank */
+       int stop_flag = 0;
        while (rset_read(rfd, &key, &termid))
        {
            zint this_sys = key.mem[sysno_mem_index];
@@ -886,10 +887,13 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet,
                    break;
                if (psysno)
                {   /* only if we did have a previous record */
-                   score = (*rc->calc) (handle, psysno, pstaticrank);
+                   score = (*rc->calc) (handle, psysno, pstaticrank,
+                                        &stop_flag);
                    /* insert the hit. A=Ascending */
                    resultSetInsertRank (zh, sort_info, psysno, score, 'A');
                    count++;
+                   if (stop_flag)
+                       break;
                }
                psysno = this_sys;
                if (zh->m_staticrank)
@@ -900,7 +904,7 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet,
        /* no more items */
        if (psysno)
        {   /* we had - at least - one record */
-           score = (*rc->calc)(handle, psysno, pstaticrank);
+           score = (*rc->calc)(handle, psysno, pstaticrank, &stop_flag);
            /* insert the hit. A=Ascending */
            resultSetInsertRank(zh, sort_info, psysno, score, 'A');
            count++;
index 0985262..caa3001 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zvrank.c,v 1.18 2005-08-19 09:21:34 adam Exp $
+/* $Id: zvrank.c,v 1.19 2005-08-19 11:04:23 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -782,7 +782,7 @@ static void zv_add (void *rsi, int seqno, TERMID term) {
  *  score should be between 0 and 1000. If score cannot be obtained
  *  -1 should be returned.
  */
-static int zv_calc (void *rsi, zint sysno, zint staticrank)
+static int zv_calc (void *rsi, zint sysno, zint staticrank, int *stop_flag)
 {
     int i, veclen; 
     int score=0;