+}
+#endif
+
+ZEBRA_RES zebra_rec_keys_to_snippets1(ZebraHandle zh,
+ zebra_rec_keys_t reckeys,
+ zebra_snippets *snippets)
+{
+ NMEM nmem = nmem_create();
+ if (zebra_rec_keys_rewind(reckeys))
+ {
+ const char *str;
+ size_t slen;
+ struct it_key key;
+ while (zebra_rec_keys_read(reckeys, &str, &slen, &key))
+ {
+ char *dst_term = 0;
+ int ord;
+ zint seqno;
+ const char *index_type;
+
+ assert(key.len <= IT_KEY_LEVEL_MAX && key.len > 2);
+ seqno = key.mem[key.len-1];
+ ord = CAST_ZINT_TO_INT(key.mem[0]);
+
+ zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type,
+ 0/* db */, 0 /* string_index */);
+ assert(index_type);
+ zebra_term_untrans_iconv(zh, nmem, index_type,
+ &dst_term, str);
+ zebra_snippets_append(snippets, seqno, 0, ord, dst_term);
+ nmem_reset(nmem);
+ }
+ }
+ nmem_destroy(nmem);
+ return ZEBRA_OK;
+}
+
+void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys)
+{
+ yaz_log(YLOG_LOG, "print_rec_keys");
+ if (zebra_rec_keys_rewind(reckeys))
+ {
+ const char *str;
+ size_t slen;
+ struct it_key key;
+ while (zebra_rec_keys_read(reckeys, &str, &slen, &key))
+ {
+ char dst_buf[IT_MAX_WORD];
+ zint seqno;
+ const char *index_type;
+ int ord = CAST_ZINT_TO_INT(key.mem[0]);
+ const char *db = 0;
+ assert(key.len <= IT_KEY_LEVEL_MAX && key.len > 2);
+
+ zebraExplain_lookup_ord(zh->reg->zei, ord, &index_type, &db, 0);
+
+ seqno = key.mem[key.len-1];
+
+ zebra_term_untrans(zh, index_type, dst_buf, str);
+
+ yaz_log(YLOG_LOG, "ord=%d seqno=" ZINT_FORMAT
+ " term=%s", ord, seqno, dst_buf);
+ }
+ }
+}
+
+static void extract_add_index_string(RecWord *p, zinfo_index_category_t cat,
+ const char *str, int length)
+{
+ struct it_key key;
+ ZebraHandle zh = p->extractCtrl->handle;
+ ZebraExplainInfo zei = zh->reg->zei;
+ int ch, i;
+
+ ch = zebraExplain_lookup_attr_str(zei, cat, p->index_type, p->index_name);
+ if (ch < 0)
+ ch = zebraExplain_add_attr_str(zei, cat, p->index_type, p->index_name);
+
+ i = 0;
+ key.mem[i++] = ch;
+ key.mem[i++] = p->record_id;
+ key.mem[i++] = p->section_id;
+
+ if (zh->m_segment_indexing)
+ key.mem[i++] = p->segment;
+ key.mem[i++] = p->seqno;
+ key.len = i;
+
+ zebra_rec_keys_write(zh->reg->keys, str, length, &key);
+}
+
+static void extract_add_sort_string(RecWord *p, const char *str, int length)
+{
+ struct it_key key;
+ ZebraHandle zh = p->extractCtrl->handle;
+ ZebraExplainInfo zei = zh->reg->zei;
+ int ch;
+ zinfo_index_category_t cat = zinfo_index_category_sort;
+
+ ch = zebraExplain_lookup_attr_str(zei, cat, p->index_type, p->index_name);
+ if (ch < 0)
+ ch = zebraExplain_add_attr_str(zei, cat, p->index_type, p->index_name);
+ key.len = 3;
+ key.mem[0] = ch;
+ key.mem[1] = p->record_id;
+ key.mem[2] = p->section_id;
+
+ zebra_rec_keys_write(zh->reg->sortKeys, str, length, &key);
+}
+
+static void extract_add_staticrank_string(RecWord *p,
+ const char *str, int length)
+{
+ char valz[40];
+ struct recExtractCtrl *ctrl = p->extractCtrl;
+
+ if (length > sizeof(valz)-1)
+ length = sizeof(valz)-1;
+
+ memcpy(valz, str, length);
+ valz[length] = '\0';
+ ctrl->staticrank = atozint(valz);
+}
+
+static void extract_add_string(RecWord *p, zebra_map_t zm,
+ const char *string, int length)
+{
+ assert(length > 0);
+
+ if (!p->index_name)
+ return;
+ if (log_level_details)
+ {
+
+ WRBUF w = wrbuf_alloc();
+
+ wrbuf_write_escaped(w, string, length);
+ yaz_log(log_level_details, "extract_add_string: %s", wrbuf_cstr(w));
+ wrbuf_destroy(w);
+ }
+ if (zebra_maps_is_index(zm))
+ {
+ extract_add_index_string(p, zinfo_index_category_index,
+ string, length);
+ if (zebra_maps_is_alwaysmatches(zm))
+ {
+ RecWord word;
+ memcpy(&word, p, sizeof(word));
+
+ word.seqno = 1;
+ extract_add_index_string(
+ &word, zinfo_index_category_alwaysmatches, "", 0);
+ }
+ }
+ else if (zebra_maps_is_sort(zm))
+ {
+ extract_add_sort_string(p, string, length);
+ }
+ else if (zebra_maps_is_staticrank(zm))
+ {
+ extract_add_staticrank_string(p, string, length);
+ }
+}
+
+static void extract_add_incomplete_field(RecWord *p, zebra_map_t zm)
+{
+ const char *b = p->term_buf;
+ int remain = p->term_len;
+ int first = 1;
+ const char **map = 0;