/*
- * Copyright (C) 1994-1995, Index Data I/S
+ * Copyright (C) 1994-1997, Index Data I/S
* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsrel.c,v $
- * Revision 1.16 1997-09-17 12:19:23 adam
+ * Revision 1.20 1997-10-31 12:37:55 adam
+ * Code calls xfree() instead of free().
+ *
+ * Revision 1.19 1997/10/01 11:44:06 adam
+ * Small improvement of new ranking.
+ *
+ * Revision 1.18 1997/09/24 13:36:41 adam
+ * More work on new ranking algorithm.
+ *
+ * Revision 1.17 1997/09/22 12:39:07 adam
+ * Added get_pos method for the ranked result sets.
+ *
+ * Revision 1.16 1997/09/17 12:19:23 adam
* Zebra version corresponds to YAZ version 1.4.
* Changed Zebra server so that it doesn't depend on global common_resource.
*
int max_rec;
int no_rec;
int (*cmp)(const void *p1, const void *p2);
+ int (*get_pos)(const void *p);
char *key_buf; /* key buffer */
float *score_buf; /* score buffer */
int *sort_idx; /* score sorted index */
qsort_info->key_buf + i2*qsort_info->key_size);
}
+#define NEW_RANKING 1
+
#define SCORE_SHOW 0.0 /* base score for showing up */
#define SCORE_COOC 0.3 /* component dependent on co-oc */
#define SCORE_DYN (1-(SCORE_SHOW+SCORE_COOC)) /* dynamic component of score */
char *isam_tmp_buf;
int *isam_r;
int *max_tf, *tf;
+
+#if NEW_RANKING
+ int *pos_tf = NULL;
+ int score_sum = 0;
+ int no_occur = 0;
+ char *isam_prev_buf = NULL;
+ int fact1, fact2;
+#endif
ISPT *isam_pt = NULL;
ISAMC_PP *isamc_pp = NULL;
int i;
}
logf (LOG_DEBUG, "max tf %d = %d", i, max_tf[i]);
}
-#if 0
+#if NEW_RANKING
while (1)
{
- int min = -1;
+ int r, min = -1;
int pos = 0;
for (i = 0; i<parms->no_isam_positions; i++)
if (isam_r[i] &&
(min < 0 ||
(r = (*parms->cmp)(isam_buf[i], isam_buf[min])) < 1))
min = i;
- if (min < 0)
- break;
+ if (!isam_prev_buf)
+ {
+ pos_tf = xmalloc (sizeof(*pos_tf) * parms->no_isam_positions);
+ isam_prev_buf = xmalloc (info->key_size);
+ fact1 = 100000/parms->no_isam_positions;
+ fact2 = 100000/(parms->no_isam_positions*parms->no_isam_positions);
+
+ no_occur = score_sum = 0;
+ memcpy (isam_prev_buf, isam_buf[min], info->key_size);
+ for (i = 0; i<parms->no_isam_positions; i++)
+ pos_tf[i] = -10;
+ }
+ else if (min < 0 ||
+ (*parms->cmp)(isam_buf[min], isam_prev_buf) > 1)
+ {
+ logf (LOG_LOG, "final occur = %d ratio=%d",
+ no_occur, score_sum / no_occur);
+ add_rec (info, score_sum / (10000.0*no_occur), isam_prev_buf);
+ if (min < 0)
+ break;
+ no_occur = score_sum = 0;
+ memcpy (isam_prev_buf, isam_buf[min], info->key_size);
+ for (i = 0; i<parms->no_isam_positions; i++)
+ pos_tf[i] = -10;
+ }
pos = (*parms->get_pos)(isam_buf[min]);
+ logf (LOG_LOG, "pos=%d", pos);
+ for (i = 0; i<parms->no_isam_positions; i++)
+ {
+ int d = pos - pos_tf[i];
+
+ no_occur++;
+ if (pos_tf[i] < 0 && i != min)
+ continue;
+ if (d < 10)
+ d = 10;
+ if (i == min)
+ score_sum += fact2 / d;
+ else
+ score_sum += fact1 / d;
+ }
+ pos_tf[min] = pos;
+ logf (LOG_LOG, "score_sum = %d", score_sum);
+ i = min;
+ if (isam_pt)
+ isam_r[i] = is_readkey (isam_pt[i], isam_buf[i]);
+ else if (isamc_pp)
+ isam_r[i] = isc_pp_read (isamc_pp[i], isam_buf[i]);
+ }
+ xfree (isam_prev_buf);
+ xfree (pos_tf);
#else
while (1)
{
info->max_rec = r_parms->max_rec;
assert (info->max_rec > 1);
info->cmp = r_parms->cmp;
+ info->get_pos = r_parms->get_pos;
info->key_buf = xmalloc (info->key_size * info->max_rec);
info->score_buf = xmalloc (sizeof(*info->score_buf) * info->max_rec);
if (*rfdp == rfd)
{
*rfdp = (*rfdp)->next;
- free (rfd);
+ xfree (rfd);
return;
}
logf (LOG_FATAL, "r_close but no rfd match!");