X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fextract.c;h=8f0cf0bef0b9a3e70df42aaffc72bdbc634d44ff;hb=f6dbdf7151bbdfaf47ec281a71ed6ef49b596f29;hp=04acd4b42331b6d3fdf75bb3ac3e408ae5eb5a76;hpb=8ed385caafd1d9695a5a9c0783f0dbe2a53f3e80;p=idzebra-moved-to-github.git diff --git a/index/extract.c b/index/extract.c index 04acd4b..8f0cf0b 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.173 2005-03-08 14:02:09 adam Exp $ +/* $Id: extract.c,v 1.178 2005-04-15 10:47:48 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -491,18 +491,6 @@ static int file_extract_record(ZebraHandle zh, } return 0; } - if (zh->reg->keys.buf_used == 0) - { - /* the extraction process returned no information - the record - is probably empty - unless flagShowRecords is in use */ - if (!zh->m_flag_rw) - return 1; - - if (zh->records_processed < zh->m_file_verbose_limit) - yaz_log (YLOG_WARN, "empty %s %s " PRINTF_OFF_T, zh->m_record_type, - fname, recordOffset); - return 1; - } if (extractCtrl.match_criteria[0]) matchStr = extractCtrl.match_criteria; } @@ -534,6 +522,18 @@ static int file_extract_record(ZebraHandle zh, } } } + if (! *sysno && zh->reg->keys.buf_used == 0) + { + /* the extraction process returned no information - the record + is probably empty - unless flagShowRecords is in use */ + if (!zh->m_flag_rw) + return 1; + + if (zh->records_processed < zh->m_file_verbose_limit) + yaz_log (YLOG_WARN, "empty %s %s " PRINTF_OFF_T, zh->m_record_type, + fname, recordOffset); + return 1; + } if (! *sysno) { @@ -577,7 +577,8 @@ static int file_extract_record(ZebraHandle zh, if (!force_update && recordAttr->runNumber == zebraExplain_runNumberIncrement (zh->reg->zei, 0)) { - yaz_log (YLOG_LOG, "run number = %d", recordAttr->runNumber); + yaz_log (YLOG_LOG, "run number = " ZINT_FORMAT, + recordAttr->runNumber); yaz_log (YLOG_LOG, "skipped %s %s " PRINTF_OFF_T, zh->m_record_type, fname, recordOffset); extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys); @@ -811,16 +812,16 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, If not, and a record is provided, then sysno is got from there */ -int buffer_extract_record (ZebraHandle zh, - const char *buf, size_t buf_size, - int delete_flag, - int test_mode, - const char *recordType, - SYSNO *sysno, - const char *match_criteria, - const char *fname, - int force_update, - int allow_update) +ZEBRA_RES buffer_extract_record (ZebraHandle zh, + const char *buf, size_t buf_size, + int delete_flag, + int test_mode, + const char *recordType, + SYSNO *sysno, + const char *match_criteria, + const char *fname, + int force_update, + int allow_update) { RecordAttr *recordAttr; struct recExtractCtrl extractCtrl; @@ -832,6 +833,7 @@ int buffer_extract_record (ZebraHandle zh, long recordOffset = 0; struct zebra_fetch_control fc; const char *pr_fname = fname; /* filename to print .. */ + int show_progress = zh->records_processed < zh->m_file_verbose_limit ? 1:0; if (!pr_fname) pr_fname = ""; /* make it printable if file is omitted */ @@ -858,17 +860,21 @@ int buffer_extract_record (ZebraHandle zh, { if (zebraExplain_newDatabase (zh->reg->zei, zh->basenames[0], zh->m_explain_database)) - return 0; + return ZEBRA_FAIL; } - if (recordType && *recordType) { + if (recordType && *recordType) + { yaz_log (YLOG_DEBUG, "Record type explicitly specified: %s", recordType); recType = recType_byName (zh->reg->recTypes, zh->res, recordType, &clientData); - } else { - if (!(zh->m_record_type)) { + } + else + { + if (!(zh->m_record_type)) + { yaz_log (YLOG_WARN, "No such record type defined"); - return 0; + return ZEBRA_FAIL; } yaz_log (YLOG_DEBUG, "Get record type from rgroup: %s",zh->m_record_type); recType = recType_byName (zh->reg->recTypes, zh->res, @@ -876,9 +882,10 @@ int buffer_extract_record (ZebraHandle zh, recordType = zh->m_record_type; } - if (!recType) { + if (!recType) + { yaz_log (YLOG_WARN, "No such record type: %s", zh->m_record_type); - return 0; + return ZEBRA_FAIL; } extractCtrl.init = extract_init; @@ -900,28 +907,18 @@ int buffer_extract_record (ZebraHandle zh, r = (*recType->extract)(clientData, &extractCtrl); if (r == RECCTRL_EXTRACT_EOF) - return 0; + return ZEBRA_FAIL; else if (r == RECCTRL_EXTRACT_ERROR_GENERIC) { /* error occured during extraction ... */ yaz_log (YLOG_WARN, "extract error: generic"); - return 0; + return ZEBRA_FAIL; } else if (r == RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER) { /* error occured during extraction ... */ yaz_log (YLOG_WARN, "extract error: no such filter"); - return 0; - } - if (zh->reg->keys.buf_used == 0) - { - /* the extraction process returned no information - the record - is probably empty - unless flagShowRecords is in use */ - if (test_mode) - return 1; - yaz_log (YLOG_WARN, "No keys generated for record"); - yaz_log (YLOG_WARN, " The file is probably empty"); - return 1; + return ZEBRA_FAIL; } /* match criteria */ matchStr = NULL; @@ -940,7 +937,7 @@ int buffer_extract_record (ZebraHandle zh, if (!matchStr) { yaz_log (YLOG_WARN, "Bad match criteria (recordID)"); - return 1; + return ZEBRA_FAIL; } } } @@ -953,19 +950,28 @@ int buffer_extract_record (ZebraHandle zh, } } } + if (zh->reg->keys.buf_used == 0) + { + /* 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 (delete_flag) { - yaz_log (YLOG_LOG, "delete %s %s %ld", recordType, - pr_fname, (long) recordOffset); + if (show_progress) + yaz_log (YLOG_LOG, "delete %s %s %ld", recordType, + pr_fname, (long) recordOffset); yaz_log (YLOG_WARN, "cannot delete record above (seems new)"); - return 1; + return ZEBRA_FAIL; } - yaz_log (YLOG_LOG, "add %s %s %ld", recordType, pr_fname, - (long) recordOffset); + if (show_progress) + yaz_log (YLOG_LOG, "add %s %s %ld", recordType, pr_fname, + (long) recordOffset); rec = rec_new (zh->reg->records); *sysno = rec->sysno; @@ -988,11 +994,13 @@ int buffer_extract_record (ZebraHandle zh, struct recKeys delkeys; struct sortKeys sortKeys; - if (!allow_update) { - yaz_log (YLOG_LOG, "skipped %s %s %ld", - recordType, pr_fname, (long) recordOffset); - logRecord(zh); - return -1; + if (!allow_update) + { + if (show_progress) + yaz_log (YLOG_LOG, "skipped %s %s %ld", + recordType, pr_fname, (long) recordOffset); + logRecord(zh); + return ZEBRA_FAIL; } rec = rec_get (zh->reg->records, *sysno); @@ -1004,12 +1012,13 @@ int buffer_extract_record (ZebraHandle zh, if (recordAttr->runNumber == zebraExplain_runNumberIncrement (zh->reg->zei, 0)) { - yaz_log (YLOG_LOG, "skipped %s %s %ld", recordType, - pr_fname, (long) recordOffset); + if (show_progress) + yaz_log (YLOG_LOG, "skipped %s %s %ld", recordType, + pr_fname, (long) recordOffset); extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys); rec_rm (&rec); logRecord(zh); - return -1; + return ZEBRA_FAIL; } } @@ -1026,14 +1035,19 @@ int buffer_extract_record (ZebraHandle zh, /* record going to be deleted */ if (!delkeys.buf_used) { - yaz_log (YLOG_LOG, "delete %s %s %ld", recordType, - pr_fname, (long) recordOffset); - yaz_log (YLOG_WARN, "cannot delete file above, storeKeys false"); - } + if (show_progress) + { + yaz_log (YLOG_LOG, "delete %s %s %ld", recordType, + pr_fname, (long) recordOffset); + yaz_log (YLOG_WARN, "cannot delete file above, " + "storeKeys false"); + } + } else { - yaz_log (YLOG_LOG, "delete %s %s %ld", recordType, - pr_fname, (long) recordOffset); + if (show_progress) + yaz_log (YLOG_LOG, "delete %s %s %ld", recordType, + pr_fname, (long) recordOffset); zh->records_deleted++; if (matchStr) dict_delete (zh->reg->matchDict, matchStr); @@ -1041,21 +1055,25 @@ int buffer_extract_record (ZebraHandle zh, } rec_rm (&rec); logRecord(zh); - return 0; + return ZEBRA_OK; } else { /* record going to be updated */ if (!delkeys.buf_used) { - yaz_log (YLOG_LOG, "update %s %s %ld", recordType, - pr_fname, (long) recordOffset); - yaz_log (YLOG_WARN, "cannot update file above, storeKeys false"); - } + if (show_progress) + { + yaz_log (YLOG_LOG, "update %s %s %ld", recordType, + pr_fname, (long) recordOffset); + yaz_log (YLOG_WARN, "cannot update file above, storeKeys false"); + } + } else { - yaz_log (YLOG_LOG, "update %s %s %ld", recordType, - pr_fname, (long) recordOffset); + if (show_progress) + yaz_log (YLOG_LOG, "update %s %s %ld", recordType, + pr_fname, (long) recordOffset); extract_flushSortKeys (zh, *sysno, 1, &zh->reg->sortKeys); extract_flushRecordKeys (zh, *sysno, 1, &zh->reg->keys); zh->records_updated++; @@ -1137,7 +1155,7 @@ int buffer_extract_record (ZebraHandle zh, /* commit this record */ rec_put (zh->reg->records, &rec); logRecord(zh); - return 0; + return ZEBRA_OK; } int explain_extract (void *handle, Record rec, data1_node *n)