-/* $Id: zsets.c,v 1.50 2004-08-04 08:35:24 adam Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
+/* $Id: zsets.c,v 1.49.2.3 2005-01-21 11:35:49 adam Exp $
+ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005
Index Data Aps
This file is part of the Zebra server.
int term_entries_max;
struct zebra_set *next;
int locked;
+
+ int cache_position; /* last position */
+ RSFD cache_rfd; /* rfd (NULL if not existing) */
+ int cache_psysno;
};
struct zset_sort_entry {
- zint sysno;
+ int sysno;
int score;
char buf[ZSET_SORT_MAX_LEVEL][SORT_IDX_ENTRYSIZE];
};
zebraSet->locked = 1;
zebraSet->rpn = 0;
zebraSet->nmem = m;
-
+
zebraSet->num_bases = num_bases;
zebraSet->basenames =
nmem_malloc (zebraSet->nmem, num_bases * sizeof(*zebraSet->basenames));
if (!ov || s->locked)
return NULL;
if (s->rset)
+ {
+ if (s->cache_rfd)
+ rset_close(s->rset, s->cache_rfd);
rset_delete (s->rset);
+ }
if (s->nmem)
nmem_destroy (s->nmem);
}
s->rset = 0;
s->nmem = 0;
s->rpn = 0;
+ s->cache_position = 0;
+ s->cache_rfd = 0;
return s;
}
for (; s; s = s->next)
{
if (s->rset)
+ {
+ if (s->cache_rfd)
+ rset_close(s->rset, s->cache_rfd);
rset_delete (s->rset);
+ }
s->rset = 0;
+ s->cache_rfd = 0;
+ s->cache_position = 0;
}
}
if (s->nmem)
nmem_destroy (s->nmem);
if (s->rset)
+ {
+ if (s->cache_rfd)
+ rset_close (s->rset, s->cache_rfd);
rset_delete (s->rset);
+ }
xfree (s->name);
xfree (s);
}
{
int position = 0;
int num_i = 0;
- zint psysno = 0;
+ int psysno = 0;
int term_index;
RSFD rfd;
struct it_key key;
position = sort_info->num_entries;
while (num_i < num && positions[num_i] < position)
num_i++;
- rfd = rset_open (rset, RSETF_READ);
+
+ if (sset->cache_rfd &&
+ num_i < num && positions[num_i] > sset->cache_position)
+ {
+ position = sset->cache_position;
+ rfd = sset->cache_rfd;
+ psysno = sset->cache_psysno;
+ }
+ else
+ {
+ if (sset->cache_rfd)
+ rset_close(rset, sset->cache_rfd);
+ rfd = rset_open (rset, RSETF_READ);
+ }
while (num_i < num && rset_read (rset, rfd, &key, &term_index))
{
-#if IT_KEY_NEW
- zint this_sys = key.mem[0];
-#else
- zint this_sys = key.sysno;
-#endif
- if (this_sys != psysno)
+ if (key.sysno != psysno)
{
- psysno = this_sys;
+ psysno = key.sysno;
if (sort_info)
{
/* determine we alreay have this in our set */
}
}
}
- rset_close (rset, rfd);
+ sset->cache_position = position;
+ sset->cache_psysno = psysno;
+ sset->cache_rfd = rfd;
}
}
return sr;
void resultSetInsertSort (ZebraHandle zh, ZebraSet sset,
struct sortKeyInfo *criteria, int num_criteria,
- zint sysno)
+ int sysno)
{
struct zset_sort_entry this_entry;
struct zset_sort_entry *new_entry = NULL;
new_entry->score = -1;
}
-void resultSetInsertRank (ZebraHandle zh, struct zset_sort_info *sort_info,
- zint sysno, int score, int relation)
+void resultSetInsertRank(ZebraHandle zh, struct zset_sort_info *sort_info,
+ int sysno, int score, int relation)
{
struct zset_sort_entry *new_entry = NULL;
int i, j;
ZebraSet sset, RSET rset,
Z_SortKeySpecList *sort_sequence, int *sort_status)
{
- int i;
- zint psysno = 0;
+ int kno = 0;
+ int i, psysno = 0;
struct it_key key;
struct sortKeyInfo sort_criteria[3];
int num_criteria;
int term_index;
RSFD rfd;
- yaz_log (LOG_LOG, "resultSetSortSingle start");
sset->sort_info->num_entries = 0;
sset->hits = 0;
rfd = rset_open (rset, RSETF_READ);
while (rset_read (rset, rfd, &key, &term_index))
{
-#if IT_KEY_NEW
- zint this_sys = key.mem[0];
-#else
- zint this_sys = key.sysno;
-#endif
- if (this_sys != psysno)
+ kno++;
+ if (key.sysno != psysno)
{
(sset->hits)++;
- psysno = this_sys;
+ psysno = key.sysno;
resultSetInsertSort (zh, sset,
sort_criteria, num_criteria, psysno);
}
}
rset_close (rset, rfd);
+ yaz_log (LOG_LOG, "%d keys, %d sysnos, sort", kno, sset->hits);
for (i = 0; i < rset->no_rset_terms; i++)
yaz_log (LOG_LOG, "term=\"%s\" nn=%d type=%s count=%d",
rset->rset_terms[i]->name,
rset->rset_terms[i]->count);
*sort_status = Z_SortResponse_success;
- yaz_log (LOG_LOG, "resultSetSortSingle end");
}
RSET resultSetRef (ZebraHandle zh, const char *resultSetId)
zebraSet->hits = 0;
rfd = rset_open (rset, RSETF_READ);
- yaz_log (LOG_LOG, "resultSetRank");
-
rank_class = zebraRankLookup (zh, rank_handler_name);
if (!rank_class)
{
if (rset_read (rset, rfd, &key, &term_index))
{
-#if IT_KEY_NEW
- zint psysno = key.mem[0];
-#else
- zint psysno = key.sysno;
-#endif
+ int psysno = key.sysno;
int score;
void *handle =
(*rc->begin) (zh->reg, rank_class->class_handle, rset);
(zebraSet->hits)++;
do
{
-#if IT_KEY_NEW
- zint this_sys = key.mem[0];
-#else
- zint this_sys = key.sysno;
-#endif
kno++;
- if (this_sys != psysno)
+ if (key.sysno != psysno)
{
score = (*rc->calc) (handle, psysno);
resultSetInsertRank (zh, sort_info, psysno, score, 'A');
(zebraSet->hits)++;
- psysno = this_sys;
+ psysno = key.sysno;
}
- (*rc->add) (handle, this_sys, term_index);
+ (*rc->add) (handle, key.seqno, term_index);
}
while (rset_read (rset, rfd, &key, &term_index));
score = (*rc->calc) (handle, psysno);
}
rset_close (rset, rfd);
+ yaz_log (LOG_LOG, "%d keys, %d sysnos, rank", kno, zebraSet->hits);
for (i = 0; i < rset->no_rset_terms; i++)
yaz_log (LOG_LOG, "term=\"%s\" nn=%d type=%s count=%d",
rset->rset_terms[i]->name,
rset->rset_terms[i]->flags,
rset->rset_terms[i]->count);
- yaz_log (LOG_LOG, "%d keys, %d distinct sysnos", kno, zebraSet->hits);
}
ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name)