sort/rank.
-/* $Id: api.h,v 1.45 2007-01-17 13:51:36 adam Exp $
+/* $Id: api.h,v 1.46 2007-01-17 15:35:47 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
ZEBRA_RES zebra_set_limit(ZebraHandle zh, int complement_flag, zint *ids);
YAZ_EXPORT
-ZEBRA_RES zebra_set_busy_handler(ZebraHandle zh,
- int (*f)(void *client_data),
- void *client_data);
+ZEBRA_RES zebra_set_break_handler(ZebraHandle zh,
+ int (*f)(void *client_data),
+ void *client_data);
YAZ_END_CDECL
-/* $Id: rset.h,v 1.62 2007-01-15 20:08:24 adam Exp $
+/* $Id: rset.h,v 1.63 2007-01-17 15:35:47 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
void rset_visit(RSET rset, int level);
+void rset_set_hits_limit(RSET rs, zint l);
+
YAZ_END_CDECL
#endif
-/* $Id: index.h,v 1.193 2007-01-17 13:22:53 adam Exp $
+/* $Id: index.h,v 1.194 2007-01-17 15:35:48 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
struct zebra_limit *m_limit;
- int (*busy_handler_func)(void *client_data);
- void *busy_handler_data;
+ int (*break_handler_func)(void *client_data);
+ void *break_handler_data;
};
-/* $Id: zebraapi.c,v 1.246 2007-01-17 13:51:36 adam Exp $
+/* $Id: zebraapi.c,v 1.247 2007-01-17 15:35:48 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
zh->m_staticrank = 0;
zh->m_segment_indexing = 0;
- zh->busy_handler_func = 0;
- zh->busy_handler_data = 0;
+ zh->break_handler_func = 0;
+ zh->break_handler_data = 0;
default_encoding = res_get_def(zh->session_res, "encoding", "ISO-8859-1");
}
-ZEBRA_RES zebra_set_busy_handler(ZebraHandle zh,
- int (*f)(void *client_data),
- void *client_data)
+ZEBRA_RES zebra_set_break_handler(ZebraHandle zh,
+ int (*f)(void *client_data),
+ void *client_data)
{
- zh->busy_handler_func = f;
- zh->busy_handler_data = client_data;
+ zh->break_handler_func = f;
+ zh->break_handler_data = client_data;
return ZEBRA_OK;
}
-/* $Id: zebrasrv.c,v 1.8 2007-01-17 13:51:36 adam Exp $
+/* $Id: zebrasrv.c,v 1.9 2007-01-17 15:35:48 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
}
-static int busy_handler(void *client_data)
+static int break_handler(void *client_data)
{
bend_association assoc =(bend_association) client_data;
if (!bend_assoc_is_alive(assoc))
zebra_result (zh, &r->errcode, &r->errstring);
return 0;
}
- zebra_set_busy_handler(zh, busy_handler, r->association);
+ zebra_set_break_handler(zh, break_handler, r->association);
yaz_log (YLOG_DEBUG, "ResultSet '%s'", r->setname);
switch (r->query->which)
{
default:
r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP;
}
- zebra_set_busy_handler(zh, 0, 0);
+ zebra_set_break_handler(zh, 0, 0);
return 0;
}
-/* $Id: zsets.c,v 1.118 2007-01-17 13:22:53 adam Exp $
+/* $Id: zsets.c,v 1.119 2007-01-17 15:35:48 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
kno++;
if (this_sys != psysno)
{
+ if ((sset->hits & 255) == 0 && zh->break_handler_func)
+ {
+ if (zh->break_handler_func(zh->break_handler_data))
+ {
+ rset_set_hits_limit(rset, 0);
+ break;
+ }
+ }
(sset->hits)++;
psysno = this_sys;
resultSetInsertSort(zh, sset,
terms = (TERMID *) nmem_malloc(nmem, sizeof(*terms)*n);
rset_getterms(rset, terms, n, &numTerms);
-
rank_class = zebraRankLookup(zh, rank_handler_name);
if (!rank_class)
{
struct rank_control *rc = rank_class->control;
int score;
zint count = 0;
-
- void *handle =
- (*rc->begin) (zh->reg, rank_class->class_handle, rset, nmem,
- terms, numTerms);
+ void *handle = (*rc->begin) (zh->reg, rank_class->class_handle, rset,
+ nmem, terms, numTerms);
zint psysno = 0; /* previous doc id / sys no */
zint pstaticrank = 0; /* previous static rank */
int stop_flag = 0;
key_logdump_txt(log_level_searchhits, &key, termid->name);
if (this_sys != psysno)
{ /* new record .. */
- if (zh->busy_handler_func)
+ if (!(rfd->counted_items & 255) && zh->break_handler_func)
{
- if (zh->busy_handler_func(zh->busy_handler_data))
+ if (zh->break_handler_func(zh->break_handler_data))
{
- yaz_log(YLOG_LOG, "Session end. Stop search");
- zebraSet->estimated_hit_count = 1;
- break;
+ yaz_log(YLOG_LOG, "Aborted search");
+ stop_flag = 1;
}
}
if (rfd->counted_items > rset->hits_limit)
- {
- zebraSet->estimated_hit_count = 1;
- break;
- }
+ stop_flag = 1;
if (psysno)
{ /* only if we did have a previous record */
score = (*rc->calc) (handle, psysno, pstaticrank,
/* insert the hit. A=Ascending */
resultSetInsertRank (zh, sort_info, psysno, score, 'A');
count++;
- if (stop_flag)
- break;
}
+ if (stop_flag)
+ {
+ zebraSet->estimated_hit_count = 1;
+ rset_set_hits_limit(rset, 0);
+ break;
+ }
psysno = this_sys;
if (zh->m_staticrank)
pstaticrank = key.mem[0];
-/* $Id: rset.c,v 1.57 2007-01-15 15:10:19 adam Exp $
+/* $Id: rset.c,v 1.58 2007-01-17 15:35:48 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
return rnew;
}
+static void rset_close_int(RSET rs, RSFD rfd)
+{
+ RSFD *pfd;
+ (*rs->control->f_close)(rfd);
+
+ yaz_log(log_level, "rfd_delete_base: rfd=%p rs=%p priv=%p fl=%p",
+ rfd, rs, rfd->priv, rs->free_list);
+ for (pfd = &rs->use_list; *pfd; pfd = &(*pfd)->next)
+ if (*pfd == rfd)
+ {
+ *pfd = (*pfd)->next;
+ rfd->next = rs->free_list;
+ rs->free_list = rfd;
+ return;
+ }
+ yaz_log(YLOG_WARN, "rset_close handle not found. type=%s",
+ rs->control->desc);
+}
+
+void rset_set_hits_limit(RSET rs, zint l)
+{
+ rs->hits_limit = l;
+}
+
/**
\brief Closes a result set RFD handle
\param rfd the RFD handle.
*/
void rset_close(RSFD rfd)
{
- RSFD *pfd;
RSET rs = rfd->rset;
if (rs->hits_count == 0)
{
TERMID termid;
char buf[100];
+
while(rfd->counted_items <= rs->hits_limit
&& rset_default_read(rfd, buf, &termid))
;
yaz_log(log_level, "rset_close p=%p count=" ZINT_FORMAT, rs,
rs->hits_count);
}
- (*rs->control->f_close)(rfd);
-
- yaz_log(log_level, "rfd_delete_base: rfd=%p rs=%p priv=%p fl=%p",
- rfd, rs, rfd->priv, rs->free_list);
- for (pfd = &rs->use_list; *pfd; pfd = &(*pfd)->next)
- if (*pfd == rfd)
- {
- *pfd = (*pfd)->next;
- rfd->next = rs->free_list;
- rs->free_list = rfd;
- return;
- }
- yaz_log(YLOG_WARN, "rset_close handle not found. type=%s",
- rs->control->desc);
+ rset_close_int(rs, rfd);
}
/**
double cur, tot;
RSFD rfd = rset_open(rs, 0);
rset_pos(rfd, &cur, &tot);
- rset_close(rfd);
+ rset_close_int(rs, rfd);
return (zint) tot;
}