-/* $Id: zsets.c,v 1.60 2004-09-01 15:01:32 heikki Exp $
+/* $Id: zsets.c,v 1.70 2004-11-15 22:44:33 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
zebraSet->locked = 1;
zebraSet->rpn = 0;
zebraSet->nmem = m;
- zebraSet->rset_nmem=nmem_create(); /* FIXME - where to free this ?? */
+ zebraSet->rset_nmem=nmem_create();
zebraSet->num_bases = num_bases;
zebraSet->basenames =
break;
if (s)
{
- yaz_log (LOG_DEBUG, "updating result set %s", name);
+ yaz_log(LOG_DEBUG, "updating result set %s", name);
if (!ov || s->locked)
return NULL;
if (s->rset)
rset_delete (s->rset);
+ if (s->rset_nmem)
+ nmem_destroy (s->rset_nmem);
if (s->nmem)
nmem_destroy (s->nmem);
}
{
const char *sort_max_str = zebra_get_resource(zh, "sortmax", "1000");
- yaz_log (LOG_DEBUG, "adding result set %s", name);
+ yaz_log(LOG_DEBUG, "adding result set %s", name);
s = (ZebraSet) xmalloc (sizeof(*s));
s->next = zh->sets;
zh->sets = s;
if (!s->term_entries && !s->rset && s->rpn)
{
NMEM nmem = nmem_create ();
- yaz_log (LOG_LOG, "research %s", name);
+ yaz_log(LOG_LOG, "research %s", name);
+ if (!s->rset_nmem)
+ s->rset_nmem=nmem_create();
s->rset =
rpn_search (zh, nmem, s->rset_nmem, s->rpn, s->num_bases,
s->basenames, s->name, s);
position = positions[i];
if (position > 0 && position <= sort_info->num_entries)
{
- yaz_log (LOG_DEBUG, "got pos=%d (sorted)", position);
+ yaz_log(LOG_DEBUG, "got pos=%d (sorted)", position);
sr[i].sysno = sort_info->entries[position-1]->sysno;
sr[i].score = sort_info->entries[position-1]->score;
}
while (num_i < num && positions[num_i] < position)
num_i++;
rfd = rset_open (rset, RSETF_READ);
- while (num_i < num && rset_read (rfd, &key))
+ while (num_i < num && rset_read (rfd, &key, 0))
{
-#if IT_KEY_NEW
zint this_sys = key.mem[0];
-#else
- zint this_sys = key.sysno;
-#endif
if (this_sys != psysno)
{
psysno = this_sys;
if (position == positions[num_i])
{
sr[num_i].sysno = psysno;
- yaz_log (LOG_DEBUG, "got pos=%d (unsorted)", position);
+ yaz_log(LOG_DEBUG, "got pos=%d (unsorted)", position);
sr[num_i].score = -1;
num_i++;
}
zh->errCode = 230;
return;
}
- yaz_log (LOG_DEBUG, "result set sort input=%s output=%s",
+ yaz_log(LOG_DEBUG, "result set sort input=%s output=%s",
*input_setnames, output_setname);
sset = resultSetGet (zh, input_setnames[0]);
if (!sset)
Z_SortKeySpecList *sort_sequence, int *sort_status)
{
int i;
+ int n = 0;
+ zint kno = 0;
zint psysno = 0;
struct it_key key;
struct sortKeyInfo sort_criteria[3];
int num_criteria;
RSFD rfd;
+ TERMID termid;
+ TERMID *terms;
+ int numTerms = 0;
- yaz_log (LOG_LOG, "resultSetSortSingle start");
assert(nmem); /* compiler shut up about unused param */
sset->sort_info->num_entries = 0;
+ rset_getterms(rset, 0, 0, &n);
+ terms = (TERMID *) nmem_malloc(nmem, sizeof(*terms)*n);
+ rset_getterms(rset, terms, n, &numTerms);
+
sset->hits = 0;
num_criteria = sort_sequence->num_specs;
if (num_criteria > 3)
switch (sk->which)
{
case Z_SortKey_sortField:
- yaz_log (LOG_DEBUG, "Sort: key %d is of type sortField", i+1);
+ yaz_log(LOG_DEBUG, "Sort: key %d is of type sortField", i+1);
zh->errCode = 207;
return;
case Z_SortKey_elementSpec:
- yaz_log (LOG_DEBUG, "Sort: key %d is of type elementSpec", i+1);
+ yaz_log(LOG_DEBUG, "Sort: key %d is of type elementSpec", i+1);
zh->errCode = 207;
return;
case Z_SortKey_sortAttributes:
- yaz_log (LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1);
+ yaz_log(LOG_DEBUG, "Sort: key %d is of type sortAttributes", i+1);
sort_criteria[i].attrUse =
zebra_maps_sort (zh->reg->zebra_maps,
sk->u.sortAttributes,
&sort_criteria[i].numerical);
- yaz_log (LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse);
+ yaz_log(LOG_DEBUG, "use value = %d", sort_criteria[i].attrUse);
if (sort_criteria[i].attrUse == -1)
{
zh->errCode = 116;
}
}
rfd = rset_open (rset, RSETF_READ);
- while (rset_read (rfd, &key))
+ while (rset_read (rfd, &key, &termid))
+ /* FIXME - pass a TERMID *, and use it for something below !! */
{
-#if IT_KEY_NEW
zint this_sys = key.mem[0];
-#else
- zint this_sys = key.sysno;
-#endif
+ kno++;
if (this_sys != psysno)
{
(sset->hits)++;
}
}
rset_close (rfd);
-
-#if 0
- for (i = 0; i < rset->no_rset_terms; i++)
- yaz_log (LOG_LOG, "term=\"%s\" nn=" ZINT_FORMAT
- " type=%s count=" ZINT_FORMAT,
- rset->rset_terms[i]->name,
- rset->rset_terms[i]->nn,
- rset->rset_terms[i]->flags,
- rset->rset_terms[i]->count);
-#endif
+ yaz_log(LOG_DEBUG, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, sort",
+ kno, sset->hits);
+ for (i = 0; i < numTerms; i++)
+ yaz_log(LOG_LOG, "term=\"%s\" type=%s count=" ZINT_FORMAT,
+ terms[i]->name, terms[i]->flags, rset_count(terms[i]->rset));
*sort_status = Z_SortResponse_success;
- yaz_log (LOG_LOG, "resultSetSortSingle end");
}
RSET resultSetRef (ZebraHandle zh, const char *resultSetId)
return NULL;
}
-void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset)
+void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset, NMEM nmem)
{
zint kno = 0;
struct it_key key;
RSFD rfd;
- /* int term_index; */
+ TERMID termid;
+ TERMID *terms;
+ int numTerms = 0;
+ int n = 0;
int i;
ZebraRankClass rank_class;
struct rank_control *rc;
sort_info = zebraSet->sort_info;
sort_info->num_entries = 0;
zebraSet->hits = 0;
- rfd = rset_open (rset, RSETF_READ);
+ rset_getterms(rset, 0, 0, &n);
+ terms = (TERMID *) nmem_malloc(nmem, sizeof(*terms)*n);
+ rset_getterms(rset, terms, n, &numTerms);
- yaz_log (LOG_LOG, "resultSetRank");
+ rfd = rset_open (rset, RSETF_READ);
rank_class = zebraRankLookup (zh, rank_handler_name);
if (!rank_class)
{
- yaz_log (LOG_WARN, "No such rank handler: %s", rank_handler_name);
+ yaz_log(LOG_WARN, "No such rank handler: %s", rank_handler_name);
return;
}
rc = rank_class->control;
- if (rset_read (rfd, &key))
+ if (rset_read (rfd, &key, &termid))
{
-#if IT_KEY_NEW
zint psysno = key.mem[0];
-#else
- zint psysno = key.sysno;
-#endif
int score;
void *handle =
- (*rc->begin) (zh->reg, rank_class->class_handle, rset);
+ (*rc->begin) (zh->reg, rank_class->class_handle, rset, nmem,
+ terms, numTerms);
(zebraSet->hits)++;
- esthits=atoi(res_get_def(zh->res,"estimatehits","0"));
+ esthits = atoi(res_get_def(zh->res, "estimatehits","0"));
if (!esthits)
- est=-1; /* can not do */
+ est = -1; /* can not do */
do
{
-#if IT_KEY_NEW
- zint this_sys = key.mem[0];
-#else
- zint this_sys = key.sysno;
-#endif
+ zint this_sys = key.mem[0]; /* FIXME - assumes scope==2 */
+ zint seqno = key.mem[1]; /* FIXME - assumes scope==2 */
kno++;
if (this_sys != psysno)
{
(zebraSet->hits)++;
psysno = this_sys;
}
- /* FIXME - Ranking is broken, since rsets no longer have */
- /* term lists! */
- /* (*rc->add) (handle, this_sys, term_index); */
+ (*rc->add) (handle, seqno, termid);
- if ( (est==-2) && (zebraSet->hits==esthits))
- { /* time to estimate the hits */
- rset_pos(rfd,&cur,&tot);
- if (tot>0) {
- ratio=cur/tot;
- est=(zint)(0.5+zebraSet->hits/ratio);
- logf(LOG_LOG, "Estimating hits (%s) "
- "%0.1f->"ZINT_FORMAT
- "; %0.1f->"ZINT_FORMAT,
- rset->control->desc,
- cur, zebraSet->hits,
- tot,est);
- i=0; /* round to 3 significant digits */
- while (est>1000) {
- est/=10;
- i++;
+ if ((est==-2) && (zebraSet->hits==esthits))
+ { /* time to estimate the hits */
+ rset_pos(rfd,&cur,&tot);
+ if (tot>0) {
+ ratio = cur/tot;
+ est = (zint)(0.5+zebraSet->hits/ratio);
+ logf(LOG_LOG, "Estimating hits (%s) "
+ "%0.1f->" ZINT_FORMAT
+ "; %0.1f->" ZINT_FORMAT,
+ rset->control->desc,
+ cur, zebraSet->hits,
+ tot, est);
+ i = 0; /* round to 3 significant digits */
+ while (est>1000) {
+ est /= 10;
+ i++;
+ }
+ while (i--)
+ est *= 10;
+ zebraSet->hits = est;
}
- while (i--) est*=10;
- zebraSet->hits=est;
}
}
- }
- while (rset_read (rfd, &key) && (est<0) );
-
- score = (*rc->calc) (handle, psysno);
- resultSetInsertRank (zh, sort_info, psysno, score, 'A');
+ while (rset_read (rfd, &key,&termid) && (est<0) );
+ score = (*rc->calc)(handle, psysno);
+ resultSetInsertRank(zh, sort_info, psysno, score, 'A');
(*rc->end) (zh->reg, handle);
}
rset_close (rfd);
-/*
- for (i = 0; i < rset->no_rset_terms; i++)
+
+ yaz_log(LOG_DEBUG, ZINT_FORMAT " keys, " ZINT_FORMAT " sysnos, rank",
+ kno, zebraSet->hits);
+ for (i = 0; i < numTerms; i++)
{
- if (est>0)
- rset->rset_terms[i]->count =
- est=(zint)(rset->rset_terms[i]->count/ratio);
- yaz_log (LOG_LOG, "term=\"%s\" nn=" ZINT_FORMAT
- " type=%s count=" ZINT_FORMAT,
- rset->rset_terms[i]->name,
- rset->rset_terms[i]->nn,
- rset->rset_terms[i]->flags,
- rset->rset_terms[i]->count);
+ yaz_log(LOG_LOG, "term=\"%s\" type=%s count=" ZINT_FORMAT,
+ terms[i]->name, terms[i]->flags, rset_count(terms[i]->rset));
}
-*/
- yaz_log (LOG_LOG, ZINT_FORMAT " keys, "ZINT_FORMAT" distinct sysnos",
- kno, zebraSet->hits);
}
ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name)