Implemented loadable filters.
[idzebra-moved-to-github.git] / index / retrieve.c
index 0fc202a..dffb20c 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: retrieve.c,v 1.20 2002-08-02 19:26:55 adam Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
+/* $Id: retrieve.c,v 1.25 2004-09-27 10:44:49 adam Exp $
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
 This file is part of the Zebra server.
@@ -20,8 +20,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
 */
 
-
-
 #include <stdio.h>
 #include <assert.h>
 
@@ -72,7 +70,7 @@ int zebra_record_int_read (void *fh, char *buf, size_t count)
     int l = fc->record_int_len - fc->record_int_pos;
     if (l <= 0)
         return 0;
-    l = (l < (int) count) ? l : count;
+    l = (l < (int) count) ? l : (int) count;
     memcpy (buf, fc->record_int_buf + fc->record_int_pos, l);
     fc->record_int_pos += l;
     return l;
@@ -84,7 +82,7 @@ void zebra_record_int_end (void *fh, off_t off)
     fc->offset_end = off;
 }
 
-int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
+int zebra_record_fetch (ZebraHandle zh, SYSNO sysno, int score, ODR stream,
                        oid_value input_format, Z_RecordComposition *comp,
                        oid_value *output_format, char **rec_bufp,
                        int *rec_lenp, char **basenamep)
@@ -93,16 +91,16 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
     char *fname, *file_type, *basename;
     RecType rt;
     struct recRetrieveCtrl retrieveCtrl;
-    char subType[128];
     struct zebra_fetch_control fc;
     RecordAttr *recordAttr;
     void *clientData;
+    int raw_mode = 0;
 
     rec = rec_get (zh->reg->records, sysno);
     if (!rec)
     {
-        logf (LOG_DEBUG, "rec_get fail on sysno=%d", sysno);
-       *basenamep = 0;
+        logf (LOG_DEBUG, "rec_get fail on sysno=" ZINT_FORMAT, sysno);
+        *basenamep = 0;
         return 14;
     }
     recordAttr = rec_init_attr (zh->reg->zei, rec);
@@ -117,15 +115,15 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
         comp->u.simple->which == Z_ElementSetNames_generic)
     {
         if (!strcmp (comp->u.simple->u.generic, "R"))
-            file_type = "text";
+           raw_mode = 1;
     }
-    if (!(rt = recType_byName (zh->reg->recTypes,
-                              file_type, subType, &clientData)))
+    if (!(rt = recType_byName (zh->reg->recTypes, zh->res,
+                              file_type, &clientData)))
     {
         logf (LOG_WARN, "Retrieve: Cannot handle type %s",  file_type);
        return 14;
     }
-    logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score);
+    logf (LOG_DEBUG, "retrieve localno=" ZINT_FORMAT " score=%d", sysno,score);
     retrieveCtrl.fh = &fc;
     fc.fd = -1;
     retrieveCtrl.fname = fname;
@@ -138,6 +136,15 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
         fc.record_int_buf = rec->info[recInfo_storeData];
         fc.record_int_pos = 0;
         logf (LOG_DEBUG, "Internal retrieve. %d bytes", fc.record_int_len);
+       if (raw_mode)
+       {
+            *output_format = VAL_SUTRS;
+            *rec_lenp = rec->size[recInfo_storeData];
+                   *rec_bufp = (char *) odr_malloc(stream, *rec_lenp);
+           memcpy(*rec_bufp, rec->info[recInfo_storeData], *rec_lenp);
+            rec_rm (&rec);
+           return 0;
+       }
     }
     else
     {
@@ -151,7 +158,6 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
         }
         else
             strcpy (full_rep, fname);
-        
 
         if ((fc.fd = open (full_rep, O_BINARY|O_RDONLY)) == -1)
         {
@@ -167,8 +173,17 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
         retrieveCtrl.tellf = zebra_record_ext_tell;
 
         zebra_record_ext_seek (retrieveCtrl.fh, 0);
+       if (raw_mode)
+       {
+            *output_format = VAL_SUTRS;
+            *rec_lenp = recordAttr->recordSize;
+                   *rec_bufp = (char *) odr_malloc(stream, *rec_lenp);
+           zebra_record_ext_read(&fc, *rec_bufp, *rec_lenp);
+            rec_rm (&rec);
+            close (fc.fd);
+           return 0;
+       }
     }
-    retrieveCtrl.subType = subType;
     retrieveCtrl.localno = sysno;
     retrieveCtrl.score = score;
     retrieveCtrl.recordSize = recordAttr->recordSize;