X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fsnippet.c;h=3bc028e3c7302fba9a7c3aa3f3b7dd54f871bf0e;hb=388742fccf1ecb74c539c70fd1ac7f15f329932a;hp=a3045a31e882ad8745a8d52810b1b44733761797;hpb=7a2d0f25682890bde5d8f2883d6020df2ed0b365;p=idzebra-moved-to-github.git diff --git a/util/snippet.c b/util/snippet.c index a3045a3..3bc028e 100644 --- a/util/snippet.c +++ b/util/snippet.c @@ -1,4 +1,4 @@ -/* $Id: snippet.c,v 1.3 2005-06-07 14:53:39 adam Exp $ +/* $Id: snippet.c,v 1.6 2006-05-10 08:13:46 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -47,14 +47,14 @@ void zebra_snippets_destroy(zebra_snippets *l) } void zebra_snippets_append(zebra_snippets *l, - zint seqno, int reg_type, int ord, const char *term) + zint seqno, int ord, const char *term) { - zebra_snippets_append_match(l, seqno, reg_type, ord, term, 0); + zebra_snippets_append_match(l, seqno, ord, term, 0); } void zebra_snippets_append_match(zebra_snippets *l, - zint seqno, int reg_type, - int ord, const char *term, int match) + zint seqno, int ord, const char *term, + int match) { struct zebra_snippet_word *w = nmem_malloc(l->nmem, sizeof(*w)); @@ -66,7 +66,6 @@ void zebra_snippets_append_match(zebra_snippets *l, l->tail = w; w->seqno = seqno; - w->reg_type = reg_type; w->ord = ord; w->term = nmem_strdup(l->nmem, term); w->match = match; @@ -81,9 +80,8 @@ void zebra_snippets_log(zebra_snippets *l, int log_level) { zebra_snippet_word *w; for (w = l->front; w; w = w->next) - yaz_log(log_level, "term=%s%s seqno=" ZINT_FORMAT " reg_type=%c " - "ord=%d", - w->term, (w->match ? "*" : ""), w->seqno, w->reg_type, w->ord); + yaz_log(log_level, "term=%s%s seqno=" ZINT_FORMAT " ord=%d", + w->term, (w->match ? "*" : ""), w->seqno, w->ord); } zebra_snippets *zebra_snippets_window(zebra_snippets *doc, zebra_snippets *hit, @@ -98,25 +96,22 @@ zebra_snippets *zebra_snippets_window(zebra_snippets *doc, zebra_snippets *hit, while(1) { int window_start; - int reg_type; + int first_seq_no_best_window = 0; + int last_seq_no_best_window = 0; + int number_best_window = 0; zebra_snippet_word *hit_w, *doc_w; int min_ord = 0; /* not set yet */ + for (hit_w = zebra_snippets_list(hit); hit_w; hit_w = hit_w->next) if (hit_w->ord > ord && - (min_ord == 0 || - (hit_w->ord < min_ord && hit_w->reg_type == reg_type))) + (min_ord == 0 || hit_w->ord < min_ord)) { min_ord = hit_w->ord; - reg_type = hit_w->reg_type; } if (min_ord == 0) break; ord = min_ord; - int first_seq_no_best_window = 0; - int last_seq_no_best_window = 0; - int number_best_window = 0; - for (hit_w = zebra_snippets_list(hit); hit_w; hit_w = hit_w->next) { if (hit_w->ord == ord) @@ -126,7 +121,7 @@ zebra_snippets *zebra_snippets_window(zebra_snippets *doc, zebra_snippets *hit, int seq_no_last = 0; while (look_w && look_w->seqno < hit_w->seqno + window_size) { - if (look_w->ord == ord && look_w->reg_type == reg_type) + if (look_w->ord == ord) { seq_no_last = look_w->seqno; number_this++; @@ -149,15 +144,15 @@ zebra_snippets *zebra_snippets_window(zebra_snippets *doc, zebra_snippets *hit, window_start = (first_seq_no_best_window + last_seq_no_best_window - window_size) / 2; for (doc_w = zebra_snippets_list(doc); doc_w; doc_w = doc_w->next) - if (doc_w->ord == ord && doc_w->reg_type == reg_type + if (doc_w->ord == ord && doc_w->seqno >= window_start && doc_w->seqno < window_start + window_size) { int match = 0; - for (hit_w = zebra_snippets_list(hit); hit_w; hit_w = hit_w->next) + for (hit_w = zebra_snippets_list(hit); hit_w; + hit_w = hit_w->next) { - if (hit_w->ord == ord && hit_w->reg_type == reg_type && - hit_w->seqno == doc_w->seqno) + if (hit_w->ord == ord && hit_w->seqno == doc_w->seqno) { match = 1; @@ -165,10 +160,17 @@ zebra_snippets *zebra_snippets_window(zebra_snippets *doc, zebra_snippets *hit, } } zebra_snippets_append_match(result, doc_w->seqno, - doc_w->reg_type, ord, - doc_w->term, match); + ord, doc_w->term, match); } } return result; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +