X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fextract.c;h=b4f7ee74544afa0b18d3a37f770b940e7be2f6ec;hb=27a6d4f7f7425896345ab5a2bfdf35a96c97416e;hp=51d2b94feec0ec7eefa21053a1c9db0270344c57;hpb=7a23ff31063e70f55eb387477130a358f0992988;p=idzebra-moved-to-github.git diff --git a/index/extract.c b/index/extract.c index 51d2b94..b4f7ee7 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.250 2007-03-01 10:35:46 adam Exp $ +/* $Id: extract.c,v 1.254 2007-03-20 22:07:21 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -319,6 +319,18 @@ static void all_matches_add(struct recExtractCtrl *ctrl) "", 0); } +ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, + struct ZebraRecStream *stream, + enum zebra_recctrl_action_t action, + int test_mode, + const char *recordType, + zint *sysno, + const char *match_criteria, + const char *fname, + RecType recType, + void *recTypeClientData); + + ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname, int deleteFlag) { @@ -417,26 +429,15 @@ ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname, streamp = &stream; zebra_create_stream_fd(streamp, fd, 0); } - while(1) - { - int more = 0; - r = zebra_extract_record_stream(zh, streamp, - deleteFlag, - 0, /* tst_mode */ - zh->m_record_type, - sysno, - 0, /*match_criteria */ - fname, - 1, /* force_update */ - 1, /* allow_update */ - recType, recTypeClientData, &more); - if (!more) - break; - if (sysno) - { - break; - } - } + r = zebra_extract_records_stream(zh, streamp, + deleteFlag ? + action_delete : action_update, + 0, /* tst_mode */ + zh->m_record_type, + sysno, + 0, /*match_criteria */ + fname, + recType, recTypeClientData); if (streamp) stream.destroy(streamp); zh->m_record_type = original_record_type; @@ -452,20 +453,17 @@ ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname, ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, const char *buf, size_t buf_size, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, - const char *fname, - int force_update, - int allow_update) + const char *fname) { struct ZebraRecStream stream; ZEBRA_RES res; void *clientData; RecType recType = 0; - int more = 0; if (recordType && *recordType) { @@ -496,31 +494,63 @@ ZEBRA_RES zebra_buffer_extract_record(ZebraHandle zh, zebra_create_stream_mem(&stream, buf, buf_size); - res = zebra_extract_record_stream(zh, &stream, - delete_flag, - test_mode, - recordType, - sysno, - match_criteria, - fname, - force_update, - allow_update, - recType, clientData, &more); + res = zebra_extract_records_stream(zh, &stream, + action, + test_mode, + recordType, + sysno, + match_criteria, + fname, + recType, clientData); stream.destroy(&stream); return res; } +ZEBRA_RES zebra_extract_records_stream(ZebraHandle zh, + struct ZebraRecStream *stream, + enum zebra_recctrl_action_t action, + int test_mode, + const char *recordType, + zint *sysno, + const char *match_criteria, + const char *fname, + RecType recType, + void *recTypeClientData) +{ + ZEBRA_RES res = ZEBRA_OK; + while (1) + { + int more = 0; + res = zebra_extract_record_stream(zh, stream, + action, + test_mode, + recordType, + sysno, + match_criteria, + fname, + recType, recTypeClientData, &more); + if (!more) + { + res = ZEBRA_OK; + break; + } + if (res != ZEBRA_OK) + break; + if (sysno) + break; + } + return res; +} + ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, struct ZebraRecStream *stream, - int delete_flag, + enum zebra_recctrl_action_t action, int test_mode, const char *recordType, zint *sysno, const char *match_criteria, const char *fname, - int force_update, - int allow_update, RecType recType, void *recTypeClientData, int *more) @@ -570,13 +600,19 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, extractCtrl.handle = zh; extractCtrl.match_criteria[0] = '\0'; extractCtrl.staticrank = 0; + extractCtrl.action = action; init_extractCtrl(zh, &extractCtrl); - + extract_set_store_data_prepare(&extractCtrl); r = (*recType->extract)(recTypeClientData, &extractCtrl); + if (action == action_update) + { + action = extractCtrl.action; + } + switch (r) { case RECCTRL_EXTRACT_EOF: @@ -660,13 +696,20 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, if (! *sysno) { /* new record */ - if (delete_flag) + 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); @@ -699,7 +742,7 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, /* record already exists */ zebra_rec_keys_t delkeys = zebra_rec_keys_open(); zebra_rec_keys_t sortKeys = zebra_rec_keys_open(); - if (!allow_update) + if (action == action_insert) { yaz_log (YLOG_LOG, "skipped %s %s " ZINT_FORMAT, recordType, pr_fname, (zint) start_offset); @@ -728,7 +771,7 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle zh, extract_flush_sort_keys(zh, *sysno, 0, sortKeys); extract_flush_record_keys(zh, *sysno, 0, delkeys, recordAttr->staticrank); - if (delete_flag) + if (action == action_delete) { /* record going to be deleted */ if (zebra_rec_keys_empty(delkeys)) @@ -756,7 +799,7 @@ ZEBRA_RES zebra_extract_record_stream(ZebraHandle 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); @@ -879,6 +922,8 @@ ZEBRA_RES zebra_extract_explain(void *handle, Record rec, data1_node *n) extractCtrl.flagShowRecords = 0; extractCtrl.match_criteria[0] = '\0'; extractCtrl.staticrank = 0; + extractCtrl.action = action_update; + extractCtrl.handle = handle; extractCtrl.first_record = 1;