+ switch (parms->method)
+ {
+ case RSREL_METHOD_B:
+ while (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 (!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]);
+ } /* while */
+ xfree (isam_prev_buf);
+ xfree (pos_tf);
+ break;
+ case RSREL_METHOD_A:
+ while (1)
+ {
+ int min = -1, i, r;
+ double score;
+ int co_oc, last_term; /* Number of co-occurrences */
+
+ last_term = -1;
+ /* find min with lowest sysno */
+ for (i = 0; i<parms->no_isam_positions; i++)
+ {
+ if (isam_r[i] &&
+ (min < 0
+ || (r = (*parms->cmp)(isam_buf[i], isam_buf[min])) < 2))
+ {
+ min = i;
+ co_oc = 1;
+ }
+ else if (!r && last_term != parms->term_no[i])
+ co_oc++; /* new occurrence */
+ last_term = parms->term_no[i];
+ }
+
+ if (min < 0)
+ break;
+ memcpy (isam_tmp_buf, isam_buf[min], info->key_size);
+ /* calculate for all with those sysno */
+ for (i = 0; i < parms->no_terms; i++)
+ tf[i] = 0;
+ for (i = 0; i<parms->no_isam_positions; i++)
+ {
+ int r;
+
+ if (isam_r[i])
+ r = (*parms->cmp)(isam_buf[i], isam_tmp_buf);
+ else
+ r = 2;
+ if (r <= 1 && r >= -1)
+ {
+ do
+ {
+ tf[parms->term_no[i]]++;
+ 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]);
+ } while (isam_r[i] &&
+ (*parms->cmp)(isam_buf[i], isam_tmp_buf) <= 1);
+ }
+ }
+ /* calculate relevance value */
+ score = 0.0;
+ for (i = 0; i<parms->no_terms; i++)
+ if (tf[i])
+ score += SCORE_SHOW + SCORE_COOC*co_oc/parms->no_terms +
+ SCORE_DYN*tf[i]/max_tf[i];
+ /* if value is in the top score, then save it - don't emit yet */
+ add_rec (info, score/parms->no_terms, isam_tmp_buf);
+ } /* while */
+ break;
+ } /* switch */
+ for (i = 0; i<info->no_rec; i++)
+ info->sysno_idx[i] = i;
+ qsort_info = info;
+ qsort (info->sysno_idx, info->no_rec, sizeof(*info->sysno_idx), qcomp);