+ if (zebra_rec_keys_empty(zh->reg->keys))
+ {
+ /* the extraction process returned no information - the record
+ is probably empty - unless flagShowRecords is in use */
+ if (test_mode)
+ return ZEBRA_OK;
+ }
+
+ if (! *sysno)
+ {
+ /* new record */
+ if (action == action_delete)
+ {
+ yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
+ yaz_log(YLOG_WARN, "cannot delete record above (seems new)");
+ return ZEBRA_FAIL;
+ }
+ else if (action == action_replace)
+ {
+ yaz_log(YLOG_LOG, "update %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
+ yaz_log(YLOG_WARN, "cannot update record above (seems new)");
+ return ZEBRA_FAIL;
+ }
+ if (show_progress)
+ yaz_log(YLOG_LOG, "add %s %s " ZINT_FORMAT, recordType, pr_fname,
+ (zint) start_offset);
+ rec = rec_new(zh->reg->records);
+
+ *sysno = rec->sysno;
+
+ recordAttr = rec_init_attr(zh->reg->zei, rec);
+ if (extractCtrl.staticrank < 0)
+ {
+ yaz_log(YLOG_WARN, "Negative staticrank for record. Set to 0");
+ extractCtrl.staticrank = 0;
+ }
+
+ if (matchStr)
+ {
+ int db_ord = zebraExplain_get_database_ord(zh->reg->zei);
+ dict_insert_ord(zh->reg->matchDict, db_ord, matchStr,
+ sizeof(*sysno), sysno);
+ }
+
+ extract_flush_sort_keys(zh, *sysno, 1, zh->reg->sortKeys);
+#if FLUSH2
+ extract_flush_record_keys2(zh, *sysno,
+ zh->reg->keys, extractCtrl.staticrank,
+ 0, recordAttr->staticrank);
+#else
+ extract_flush_record_keys(zh, *sysno, 1, zh->reg->keys,
+ extractCtrl.staticrank);
+#endif
+ recordAttr->staticrank = extractCtrl.staticrank;
+ zh->records_inserted++;
+ }
+ else
+ {
+ /* record already exists */
+ zebra_rec_keys_t delkeys = zebra_rec_keys_open();
+ zebra_rec_keys_t sortKeys = zebra_rec_keys_open();
+ if (action == action_insert)
+ {
+ yaz_log(YLOG_LOG, "skipped %s %s " ZINT_FORMAT,
+ recordType, pr_fname, (zint) start_offset);
+ logRecord(zh);
+ return ZEBRA_FAIL;
+ }
+
+ rec = rec_get(zh->reg->records, *sysno);
+ assert(rec);
+
+ recordAttr = rec_init_attr(zh->reg->zei, rec);
+
+ /* decrease total size */
+ zebraExplain_recordBytesIncrement(zh->reg->zei,
+ - recordAttr->recordSize);
+
+ zebra_rec_keys_set_buf(delkeys,
+ rec->info[recInfo_delKeys],
+ rec->size[recInfo_delKeys],
+ 0);
+ zebra_rec_keys_set_buf(sortKeys,
+ rec->info[recInfo_sortKeys],
+ rec->size[recInfo_sortKeys],
+ 0);
+
+ extract_flush_sort_keys(zh, *sysno, 0, sortKeys);
+#if !FLUSH2
+ extract_flush_record_keys(zh, *sysno, 0, delkeys,
+ recordAttr->staticrank);
+#endif
+ if (action == action_delete)
+ {
+ /* record going to be deleted */
+#if FLUSH2
+ extract_flush_record_keys2(zh, *sysno, 0, recordAttr->staticrank,
+ delkeys, recordAttr->staticrank);
+#endif
+ if (zebra_rec_keys_empty(delkeys))
+ {
+ yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
+ yaz_log(YLOG_WARN, "cannot delete file above, "
+ "storeKeys false (3)");
+ }
+ else
+ {
+ if (show_progress)
+ yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
+ zh->records_deleted++;
+ if (matchStr)
+ {
+ int db_ord = zebraExplain_get_database_ord(zh->reg->zei);
+ dict_delete_ord(zh->reg->matchDict, db_ord, matchStr);
+ }
+ rec_del(zh->reg->records, &rec);
+ }
+ zebra_rec_keys_close(delkeys);
+ zebra_rec_keys_close(sortKeys);
+ rec_free(&rec);
+ logRecord(zh);
+ return ZEBRA_OK;
+ }
+ else
+ { /* update or special_update */
+ if (show_progress)
+ yaz_log(YLOG_LOG, "update %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
+ extract_flush_sort_keys(zh, *sysno, 1, zh->reg->sortKeys);