{
int no = 0;
const char *norm_str;
-#if 1
- yaz_log(YLOG_LOG, "relevance_snippet for field=%s content=%s",
- name, words);
-#endif
- pp2_charset_token_first(r->prt, words, 0);
+ int highlight = 0;
+ pp2_charset_token_first(r->prt, words, 0);
while ((norm_str = pp2_charset_token_next(r->prt)))
{
size_t org_start, org_len;
struct word_entry *entries = r->entries;
- int highlight = 0;
int i;
pp2_get_org(r->prt, &org_start, &org_len);
for (; entries; entries = entries->next, i++)
{
- yaz_log(YLOG_LOG, "Compare: %s %s", norm_str, entries->norm_str);
if (*norm_str && !strcmp(norm_str, entries->norm_str))
+ break;
+ }
+ if (entries)
+ {
+ if (!highlight)
+ {
highlight = 1;
+ wrbuf_puts(w_snippet, "<match>");
+ no++;
+ }
+ }
+ else
+ {
+ if (highlight)
+ {
+ highlight = 0;
+ wrbuf_puts(w_snippet, "</match>");
+ }
}
- if (highlight)
- wrbuf_puts(w_snippet, "<match>");
-
wrbuf_xmlputs_n(w_snippet, words + org_start, org_len);
- if (highlight)
- wrbuf_puts(w_snippet, "</match>");
- no += highlight;
}
+ if (highlight)
+ wrbuf_puts(w_snippet, "</match>");
if (no)
{
- yaz_log(YLOG_LOG, "SNIPPET match: %s", wrbuf_cstr(w_snippet));
+ yaz_log(YLOG_DEBUG, "SNIPPET match: %s", wrbuf_cstr(w_snippet));
}
return no;
}
}
}
-void relevance_newrec(struct relevance *r, struct record_cluster *rec)
+void relevance_mergerec(struct relevance *r, struct record_cluster *dst,
+ const struct record_cluster *src)
{
- if (!rec->term_frequency_vec)
- {
- int i;
+ int i;
- // term frequency [1,..] . [0] is total length of all fields
- rec->term_frequency_vec =
- nmem_malloc(r->nmem,
- r->vec_len * sizeof(*rec->term_frequency_vec));
- for (i = 0; i < r->vec_len; i++)
- rec->term_frequency_vec[i] = 0;
+ for (i = 0; i < r->vec_len; i++)
+ dst->term_frequency_vec[i] += src->term_frequency_vec[i];
- // term frequency divided by length of field [1,...]
- rec->term_frequency_vecf =
- nmem_malloc(r->nmem,
- r->vec_len * sizeof(*rec->term_frequency_vecf));
- for (i = 0; i < r->vec_len; i++)
- rec->term_frequency_vecf[i] = 0.0;
- }
+ for (i = 0; i < r->vec_len; i++)
+ dst->term_frequency_vecf[i] += src->term_frequency_vecf[i];
+}
+
+void relevance_newrec(struct relevance *r, struct record_cluster *rec)
+{
+ int i;
+
+ // term frequency [1,..] . [0] is total length of all fields
+ rec->term_frequency_vec =
+ nmem_malloc(r->nmem,
+ r->vec_len * sizeof(*rec->term_frequency_vec));
+ for (i = 0; i < r->vec_len; i++)
+ rec->term_frequency_vec[i] = 0;
+
+ // term frequency divided by length of field [1,...]
+ rec->term_frequency_vecf =
+ nmem_malloc(r->nmem,
+ r->vec_len * sizeof(*rec->term_frequency_vecf));
+ for (i = 0; i < r->vec_len; i++)
+ rec->term_frequency_vecf[i] = 0.0;
}
void relevance_donerecord(struct relevance *r, struct record_cluster *cluster)