Do not warn about empty records
[idzebra-moved-to-github.git] / index / extract.c
index 84250b5..2f8e0fe 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: extract.c,v 1.172 2005-03-05 09:19:14 adam Exp $
+/* $Id: extract.c,v 1.177 2005-03-17 09:48:46 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);
@@ -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 = "<no file>";  /* make it printable if file is omitted */
@@ -913,16 +915,6 @@ int buffer_extract_record (ZebraHandle zh,
        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;
-    }
     /* match criteria */
     matchStr = NULL;
 
@@ -953,19 +945,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 1;
+    }
 
     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;
         }
-       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 +989,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 -1;
        }
 
         rec = rec_get (zh->reg->records, *sysno);
@@ -1004,8 +1007,9 @@ 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);
@@ -1026,14 +1030,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);
@@ -1048,14 +1057,18 @@ int buffer_extract_record (ZebraHandle zh,
             /* 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++;
@@ -1248,7 +1261,7 @@ void extract_flushRecordKeys (ZebraHandle zh, SYSNO sysno,
         (zh->reg->key_buf)[zh->reg->ptr_top - zh->reg->ptr_i] =
            (char*)zh->reg->key_buf + zh->reg->key_buf_used;
 
-       ch = key.mem[0];  /* ordinal for field/use/attribute */
+       ch = (int) key.mem[0];  /* ordinal for field/use/attribute */
 
        zh->reg->key_buf_used +=
            key_SU_encode (ch,((char*)zh->reg->key_buf) +