From d95fcf3ebd1d19bc0bd15e0efc69c6efa40a0423 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 19 Aug 2005 11:04:23 +0000 Subject: [PATCH] Pass a stop_flag to ranking method calc. When set to 1, it signals stop of result set processing. --- index/index.h | 5 +++-- index/rank1.c | 5 +++-- index/rankstatic.c | 6 ++++-- index/zsets.c | 10 +++++++--- index/zvrank.c | 4 ++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/index/index.h b/index/index.h index d620b87..e9c8f50 100644 --- a/index/index.h +++ b/index/index.h @@ -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); }; diff --git a/index/rank1.c b/index/rank1.c index fb3529e..44220c1 100644 --- a/index/rank1.c +++ b/index/rank1.c @@ -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; diff --git a/index/rankstatic.c b/index/rankstatic.c index 2b8fb20..9abc7ec 100644 --- a/index/rankstatic.c +++ b/index/rankstatic.c @@ -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) */ } diff --git a/index/zsets.c b/index/zsets.c index ed60386..a4b596f 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -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++; diff --git a/index/zvrank.c b/index/zvrank.c index 0985262..caa3001 100644 --- a/index/zvrank.c +++ b/index/zvrank.c @@ -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; -- 1.7.10.4