+ if (p->index_name)
+ {
+ ch = zebraExplain_lookup_attr_str(zei, p->index_type, p->index_name);
+ if (ch < 0)
+ ch = zebraExplain_add_attr_str(zei, p->index_type, p->index_name);
+ }
+ else
+ {
+#if NATTR
+ return;
+#else
+ ch = zebraExplain_lookup_attr_su(zei, p->index_type,
+ p->attrSet, p->attrUse);
+ if (ch < 0)
+ ch = zebraExplain_add_attr_su(zei, p->index_type,
+ p->attrSet, p->attrUse);
+#endif
+ }
+ key.len = 4;
+ key.mem[0] = ch;
+ key.mem[1] = p->record_id;
+ key.mem[2] = p->section_id;
+ key.mem[3] = p->seqno;
+
+#if 0
+ if (1)
+ {
+ char strz[80];
+ int i;
+
+ strz[0] = 0;
+ for (i = 0; i<length && i < 20; i++)
+ sprintf(strz+strlen(strz), "%02X", str[i] & 0xff);
+ /* just for debugging .. */
+ yaz_log(YLOG_LOG, "add: set=%d use=%d "
+ "record_id=%lld section_id=%lld seqno=%lld %s",
+ p->attrSet, p->attrUse, p->record_id, p->section_id, p->seqno,
+ strz);
+ }
+#endif
+
+ 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;
+
+ if (p->index_name)
+ {
+ ch = zebraExplain_lookup_attr_str(zei, p->index_type, p->index_name);
+ if (ch < 0)
+ ch = zebraExplain_add_attr_str(zei, p->index_type, p->index_name);
+ }
+ else
+ {
+#if NATTR
+ return;
+#else
+ ch = zebraExplain_lookup_attr_su(zei, p->index_type,
+ VAL_IDXPATH, p->attrUse);
+ if (ch < 0)
+ ch = zebraExplain_add_attr_su(zei, p->index_type,
+ VAL_IDXPATH, p->attrUse);
+#endif
+ }
+ key.len = 4;
+ key.mem[0] = ch;
+ key.mem[1] = p->record_id;
+ key.mem[2] = p->section_id;
+ key.mem[3] = p->seqno;
+
+#if 0
+ if (1)
+ {
+ char strz[80];
+ int i;
+
+ strz[0] = 0;
+ for (i = 0; i<length && i < 20; i++)
+ sprintf(strz+strlen(strz), "%02X", str[i] & 0xff);
+ /* just for debugging .. */
+ yaz_log(YLOG_LOG, "add: set=%d use=%d "
+ "record_id=%lld section_id=%lld seqno=%lld %s",
+ p->attrSet, p->attrUse, p->record_id, p->section_id, p->seqno,
+ strz);
+ }
+#endif
+ zebra_rec_keys_write(zh->reg->sortKeys, str, length, &key);
+}
+
+void extract_add_string (RecWord *p, const char *string, int length)
+{
+ assert (length > 0);
+ if (zebra_maps_is_sort (p->zebra_maps, p->index_type))
+ extract_add_sort_string (p, string, length);
+ else
+ extract_add_index_string (p, string, length);
+}
+
+static void extract_add_incomplete_field (RecWord *p)
+{
+ const char *b = p->term_buf;
+ int remain = p->term_len;
+ const char **map = 0;
+
+ yaz_log(YLOG_DEBUG, "Incomplete field, w='%.*s'", p->term_len, p->term_buf);
+
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->index_type, &b, remain, 0);
+
+ while (map)
+ {
+ char buf[IT_MAX_WORD+1];
+ int i, remain;
+
+ /* Skip spaces */
+ while (map && *map && **map == *CHR_SPACE)
+ {
+ remain = p->term_len - (b - p->term_buf);
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->index_type, &b,
+ remain, 0);
+ else
+ map = 0;
+ }
+ if (!map)
+ break;
+ i = 0;
+ while (map && *map && **map != *CHR_SPACE)
+ {
+ const char *cp = *map;
+
+ while (i < IT_MAX_WORD && *cp)
+ buf[i++] = *(cp++);
+ remain = p->term_len - (b - p->term_buf);
+ if (remain > 0)
+ map = zebra_maps_input(p->zebra_maps, p->index_type, &b, remain, 0);
+ else
+ map = 0;
+ }
+ if (!i)
+ return;
+ extract_add_string (p, buf, i);
+ p->seqno++;
+ }
+}
+
+static void extract_add_complete_field (RecWord *p)
+{
+ const char *b = p->term_buf;
+ char buf[IT_MAX_WORD+1];
+ const char **map = 0;
+ int i = 0, remain = p->term_len;
+
+ yaz_log(YLOG_DEBUG, "Complete field, w='%.*s'",
+ p->term_len, p->term_buf);
+
+ if (remain > 0)
+ map = zebra_maps_input (p->zebra_maps, p->index_type, &b, remain, 1);
+
+ while (remain > 0 && i < IT_MAX_WORD)
+ {
+ while (map && *map && **map == *CHR_SPACE)
+ {
+ remain = p->term_len - (b - p->term_buf);
+
+ if (remain > 0)
+ {
+ int first = i ? 0 : 1; /* first position */
+ map = zebra_maps_input(p->zebra_maps, p->index_type, &b, remain, first);
+ }
+ else
+ map = 0;
+ }
+ if (!map)
+ break;
+
+ if (i && i < IT_MAX_WORD)
+ buf[i++] = *CHR_SPACE;
+ while (map && *map && **map != *CHR_SPACE)
+ {
+ const char *cp = *map;
+
+ if (**map == *CHR_CUT)
+ {
+ i = 0;
+ }
+ else
+ {
+ if (i >= IT_MAX_WORD)
+ break;
+ yaz_log(YLOG_DEBUG, "Adding string to index '%d'", **map);
+ while (i < IT_MAX_WORD && *cp)
+ buf[i++] = *(cp++);
+ }
+ remain = p->term_len - (b - p->term_buf);
+ if (remain > 0)
+ {
+ map = zebra_maps_input (p->zebra_maps, p->index_type, &b,
+ remain, 0);
+ }
+ else
+ map = 0;
+ }
+ }
+ if (!i)
+ return;
+ extract_add_string (p, buf, i);
+}
+
+void extract_token_add (RecWord *p)
+{
+ WRBUF wrbuf;
+#if 0
+ yaz_log (YLOG_LOG, "token_add "
+ "reg_type=%c attrSet=%d attrUse=%d seqno=%d s=%.*s",
+ p->reg_type, p->attrSet, p->attrUse, p->seqno, p->length,
+ p->string);
+#endif
+ if ((wrbuf = zebra_replace(p->zebra_maps, p->index_type, 0,
+ p->term_buf, p->term_len)))
+ {
+ p->term_buf = wrbuf_buf(wrbuf);
+ p->term_len = wrbuf_len(wrbuf);
+ }
+ if (zebra_maps_is_complete (p->zebra_maps, p->index_type))
+ extract_add_complete_field (p);
+ else
+ extract_add_incomplete_field(p);
+}
+
+static void extract_set_store_data_cb(struct recExtractCtrl *p,
+ void *buf, size_t sz)
+{
+ ZebraHandle zh = (ZebraHandle) p->handle;
+
+ xfree(zh->store_data_buf);
+ zh->store_data_buf = 0;
+ zh->store_data_size = 0;
+ if (buf && sz)
+ {
+ zh->store_data_buf = xmalloc(sz);
+ zh->store_data_size = sz;
+ memcpy(zh->store_data_buf, buf, sz);
+ }
+}
+
+static void extract_set_store_data_prepare(struct recExtractCtrl *p)
+{
+ ZebraHandle zh = (ZebraHandle) p->handle;
+ xfree(zh->store_data_buf);
+ zh->store_data_buf = 0;
+ zh->store_data_size = 0;
+ p->setStoreData = extract_set_store_data_cb;
+}
+
+void extract_schema_add (struct recExtractCtrl *p, Odr_oid *oid)
+{
+ ZebraHandle zh = (ZebraHandle) p->handle;
+ zebraExplain_addSchema (zh->reg->zei, oid);
+}
+
+void extract_flushSortKeys (ZebraHandle zh, SYSNO sysno,
+ int cmd, zebra_rec_keys_t reckeys)
+{
+ if (zebra_rec_keys_rewind(reckeys))
+ {
+ SortIdx sortIdx = zh->reg->sortIdx;
+ size_t slen;
+ const char *str;
+ struct it_key key_in;
+
+ sortIdx_sysno (sortIdx, sysno);
+
+ while (zebra_rec_keys_read(reckeys, &str, &slen, &key_in))