* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsrel.c,v $
- * Revision 1.3 1995-09-11 15:23:40 adam
+ * Revision 1.5 1995-10-06 14:38:06 adam
+ * New result set method: r_score.
+ * Local no (sysno) and score is transferred to retrieveCtrl.
+ *
+ * Revision 1.4 1995/09/14 07:48:56 adam
+ * Other score calculation.
+ *
+ * Revision 1.3 1995/09/11 15:23:40 adam
* More work on relevance search.
*
* Revision 1.2 1995/09/11 13:09:41 adam
static int r_count (rset_control *ct);
static int r_read (RSFD rfd, void *buf);
static int r_write (RSFD rfd, const void *buf);
+static int r_score (RSFD rfd, int *score);
static const rset_control control =
{
r_rewind,
r_count,
r_read,
- r_write
+ r_write,
+ r_score
};
const rset_control *rset_kind_relevance = &control;
{
int idx, i, j;
+ logf (LOG_DEBUG, "add %f", score);
for (i = 0; i<info->no_rec; i++)
{
idx = info->sort_idx[i];
if (score <= info->score_buf[idx])
break;
}
- if (i == 0)
+ if (info->no_rec < info->max_rec)
{
- if (info->no_rec == info->max_rec)
- return;
- for (j = info->no_rec; j > 0; --j)
+ for (j = info->no_rec; j > i; --j)
info->sort_idx[j] = info->sort_idx[j-1];
idx = info->sort_idx[j] = info->no_rec;
++(info->no_rec);
}
+ else if (i == 0)
+ return;
else
{
idx = info->sort_idx[0];
for (j = 0; j < i; ++j)
info->sort_idx[j] = info->sort_idx[j+1];
info->sort_idx[j] = idx;
-
}
memcpy (info->key_buf + idx*info->key_size, key, info->key_size);
info->score_buf[idx] = score;
while (1)
{
int min = -1, i;
- double length, score;
+ double score;
/* find min with lowest sysno */
for (i = 0; i<parms->no_isam_positions; i++)
break;
memcpy (isam_tmp_buf, isam_buf[min], info->key_size);
/* calculate for all with those sysno */
- length = 0.0;
for (i = 0; i<parms->no_isam_positions; i++)
{
int r;
isam_r[i] = is_readkey (isam_pt[i], isam_buf[i]);
} while (isam_r[i] &&
(*parms->cmp)(isam_buf[i], isam_tmp_buf) <= 1);
- wgt[i] = 0.5+tf*0.5/max_tf[i];
- length += wgt[i] * wgt[i];
+ wgt[i] = 0.1+tf*0.9/max_tf[i];
}
}
/* calculate relevance value */
- length = sqrt (length);
score = 0.0;
for (i = 0; i<parms->no_isam_positions; i++)
- score += wgt[i]/length;
- if (score > 1.0)
- {
- key_logdump (LOG_LOG, isam_tmp_buf);
- logf (LOG_LOG, " %f", score);
- }
+ score += wgt[i];
/* if value is in the top score, then save it - don't emit yet */
add_rec (info, score, isam_tmp_buf);
}
if (p->position <= 0)
return 0;
--(p->position);
- logf (LOG_DEBUG, "score: %f",
- info->score_buf[info->sort_idx[p->position]]);
memcpy ((char*) buf,
info->key_buf + info->key_size * info->sort_idx[p->position],
info->key_size);
return 1;
}
+static int r_score (RSFD rfd, int *score)
+{
+ struct rset_rel_rfd *p = rfd;
+ struct rset_rel_info *info = p->info;
+
+ if (p->position < 0)
+ return 0;
+ *score = (int) (1000*info->score_buf[info->sort_idx[p->position]]);
+ return 1;
+}
+
static int r_write (RSFD rfd, const void *buf)
{
logf (LOG_FATAL, "relevance set type is read-only");