updated test since non-used attributes are not longer printed out
authorMarc Cromme <marc@indexdata.dk>
Fri, 24 Nov 2006 12:21:31 +0000 (12:21 +0000)
committerMarc Cromme <marc@indexdata.dk>
Fri, 24 Nov 2006 12:21:31 +0000 (12:21 +0000)
index/retrieve.c
test/api/t16.c

index c37808b..19d217b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: retrieve.c,v 1.58 2006-11-24 11:35:23 adam Exp $
+/* $Id: retrieve.c,v 1.59 2006-11-24 12:21:31 marc Exp $
    Copyright (C) 1995-2006
    Index Data ApS
 
@@ -271,12 +271,18 @@ static void retrieve_puts_attr(WRBUF wrbuf, const char *name,
 {
     if (value)
     {
-        wrbuf_printf(wrbuf, "%s=\"", name);
+        wrbuf_printf(wrbuf, " %s=\"", name);
         wrbuf_xmlputs(wrbuf, value);
-        wrbuf_printf(wrbuf, "\"\n");
+        wrbuf_printf(wrbuf, "\"");
     }
 }
 
+static void retrieve_puts_attr_int(WRBUF wrbuf, const char *name,
+                               const int value)
+{
+    wrbuf_printf(wrbuf, " %s=\"%i\"", name, value);
+}
+
 static void retrieve_puts_str(WRBUF wrbuf, const char *name,
                                const char *value)
 {
@@ -284,6 +290,12 @@ static void retrieve_puts_str(WRBUF wrbuf, const char *name,
         wrbuf_printf(wrbuf, "%s %s\n", name, value);
 }
 
+static void retrieve_puts_int(WRBUF wrbuf, const char *name,
+                               const int value)
+{
+    wrbuf_printf(wrbuf, "%s %i\n", name, value);
+}
+
 int zebra_special_fetch(ZebraHandle zh, zint sysno, int score, ODR odr,
                            const char *elemsetname,
                            oid_value input_format,
@@ -367,23 +379,21 @@ int zebra_special_fetch(ZebraHandle zh, zint sysno, int score, ODR odr,
         {
             *output_format = VAL_TEXT_XML;
             
-            wrbuf_printf(
-                wrbuf, ZEBRA_XML_HEADER_STR
-                " sysno=\"" ZINT_FORMAT "\"", sysno);
+            wrbuf_printf(wrbuf, ZEBRA_XML_HEADER_STR
+                         " sysno=\"" ZINT_FORMAT "\"", sysno);
             retrieve_puts_attr(wrbuf, "base", rec->info[recInfo_databaseName]);
             retrieve_puts_attr(wrbuf, "file", rec->info[recInfo_filename]);
             retrieve_puts_attr(wrbuf, "type", rec->info[recInfo_fileType]);
-            
-            wrbuf_printf(
-                wrbuf,
-                " score=\"%i\""
-                " rank=\"" ZINT_FORMAT "\""
-                " size=\"%i\""
-                " set=\"zebra::%s\"/>\n",
-                score,
-                recordAttr->staticrank,
-                recordAttr->recordSize,
-                elemsetname);
+            if (score >= 0)
+                retrieve_puts_attr_int(wrbuf, "score", score);
+           
+            wrbuf_printf(wrbuf,
+                         " rank=\"" ZINT_FORMAT "\""
+                         " size=\"%i\""
+                         " set=\"zebra::%s\"/>\n",
+                         recordAttr->staticrank,
+                         recordAttr->recordSize,
+                         elemsetname);
         }
         else if (input_format == VAL_SUTRS)
         {
@@ -392,13 +402,13 @@ int zebra_special_fetch(ZebraHandle zh, zint sysno, int score, ODR odr,
             retrieve_puts_str(wrbuf, "base", rec->info[recInfo_databaseName]);
             retrieve_puts_str(wrbuf, "file", rec->info[recInfo_filename]);
             retrieve_puts_str(wrbuf, "type", rec->info[recInfo_fileType]);
+            if (score >= 0)
+                retrieve_puts_int(wrbuf, "score", score);
 
             wrbuf_printf(wrbuf,
-                         "score %i\n"
                          "rank " ZINT_FORMAT "\n"
                          "size %i\n"
                          "set zebra::%s\n",
-                         score,
                          recordAttr->staticrank,
                          recordAttr->recordSize,
                          elemsetname);
index 3070302..df32789 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t16.c,v 1.6 2006-11-23 09:03:51 marc Exp $
+/* $Id: t16.c,v 1.7 2006-11-24 12:21:31 marc Exp $
    Copyright (C) 1995-2006
    Index Data ApS
 
@@ -88,6 +88,9 @@ static void tst(int argc, char **argv)
     const char * zebra_xml_sysno 
         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::meta::sysno\"/>\n";
 
+    const char * zebra_xml_meta 
+        = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" base=\"Default\" type=\"grs.sgml\" rank=\"0\" size=\"41\" set=\"zebra::meta\"/>\n";
+
     const char * zebra_xml_index_title_p
         = "<record xmlns=\"http://www.indexdata.com/zebra/\" sysno=\"2\" set=\"zebra::index::title:p/\">\n"
 "  <index name=\"title\" type=\"p\" seq=\"4\">my title</index>\n"
@@ -118,7 +121,7 @@ static void tst(int argc, char **argv)
                                      zebra_xml_sysno), ZEBRA_OK);
     
     YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta", VAL_TEXT_XML,
-                                     "definitely not this"), ZEBRA_FAIL);
+                                     zebra_xml_meta), ZEBRA_OK);
     
     YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::index::title:p", 
                                      VAL_TEXT_XML,