+
+static void zebra_snippets_clear(zebra_snippets *sn)
+{
+ zebra_snippet_word *w;
+
+ for (w = zebra_snippets_list(sn); w; w = w->next)
+ {
+ w->mark = 0;
+ w->match = 0;
+ }
+}
+
+const struct zebra_snippet_word *zebra_snippets_lookup(
+ const zebra_snippets *doc, const zebra_snippets *hit)
+{
+ const zebra_snippet_word *hit_w;
+ for (hit_w = zebra_snippets_constlist(hit); hit_w; hit_w = hit_w->next)
+ {
+ const zebra_snippet_word *doc_w;
+ for (doc_w = zebra_snippets_constlist(doc); doc_w; doc_w = doc_w->next)
+ {
+ if (doc_w->ord == hit_w->ord && doc_w->seqno == hit_w->seqno
+ && !doc_w->ws)
+ {
+ return doc_w;
+ }
+ }
+ }
+ return 0;
+}
+
+void zebra_snippets_ring(zebra_snippets *doc, const zebra_snippets *hit,
+ int before, int after)
+{
+ int ord = -1;
+
+ zebra_snippets_clear(doc);
+ while (1)
+ {
+ const zebra_snippet_word *hit_w;
+ zebra_snippet_word *doc_w;
+ int min_ord = 0; /* not set yet */
+
+ for (hit_w = zebra_snippets_constlist(hit); hit_w; hit_w = hit_w->next)
+ if (hit_w->ord > ord &&
+ (min_ord == 0 || hit_w->ord < min_ord))
+ {
+ min_ord = hit_w->ord;
+ }
+ if (min_ord == 0)
+ break;
+ ord = min_ord;
+
+ for (hit_w = zebra_snippets_constlist(hit); hit_w; hit_w = hit_w->next)
+ {
+ if (hit_w->ord == ord)
+ {
+ for (doc_w = zebra_snippets_list(doc); doc_w; doc_w = doc_w->next)
+ {
+ if (doc_w->ord == ord && doc_w->seqno == hit_w->seqno
+ && !doc_w->ws)
+ {
+ doc_w->match = 1;
+ doc_w->mark = 1;
+ break;
+ }
+
+ }
+ /* mark following terms */
+ if (doc_w)
+ {
+ zebra_snippet_word *w = doc_w->next;
+ while (w)
+ if (w->ord == ord
+ && hit_w->seqno - before < w->seqno
+ && hit_w->seqno + after > w->seqno)
+ {
+ w->mark = 1;
+ w = w->next;
+ }
+ else
+ break;
+ }
+ /* mark preceding terms */
+ if (doc_w)
+ {
+ zebra_snippet_word *w = doc_w->prev;
+ while (w)
+ if (w->ord == ord
+ && hit_w->seqno - before < w->seqno
+ && hit_w->seqno + after > w->seqno)
+ {
+ w->mark = 1;
+ w = w->prev;
+ }
+ else
+ break;
+ }
+ }
+ }
+ }
+}
+