Updated footer comment
[idzebra-moved-to-github.git] / index / retrieve.c
index 78a489b..1dfae6f 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the Zebra server.
-   Copyright (C) 1995-2008 Index Data
+   Copyright (C) 1994-2009 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -269,7 +269,7 @@ static int sort_fetch(
         }
         zebra_sort_type(zh->reg->sort_index, ord);
         zebra_sort_sysno(zh->reg->sort_index, fi->sysno);
-        zebra_sort_read(zh->reg->sort_index, wrbuf_str);
+        zebra_sort_read(zh->reg->sort_index, 0, wrbuf_str);
 
         while (off != wrbuf_len(wrbuf_str))
         {
@@ -484,6 +484,41 @@ static void retrieve_puts_int(WRBUF wrbuf, const char *name,
 }
 
 
+static void snippet_check_fields(ZebraHandle zh, WRBUF wrbuf,
+                                 zebra_snippets *doc,
+                                 const zebra_snippet_word *doc_w,
+                                 const char *w_index_type)
+{
+    /* beginning of snippet. See which fields the snippet also
+       occur */
+    const zebra_snippet_word *w;
+    int no = 0;
+    for (w = zebra_snippets_constlist(doc); w; w = w->next)
+    {
+        /* same sequence but other field? */
+        if (w->seqno == doc_w->seqno && w->ord != doc_w->ord)
+        {
+            const char *index_type;
+            const char *db = 0;
+            const char *string_index = 0;
+            
+            zebraExplain_lookup_ord(zh->reg->zei, w->ord, 
+                                    &index_type, &db, &string_index);
+            /* only report for same index type */
+            if (!strcmp(w_index_type, index_type))
+            {
+                if (no == 0)
+                    wrbuf_printf(wrbuf, " fields=\"%s", string_index);
+                else
+                    wrbuf_printf(wrbuf, " %s", string_index);
+                no++;
+            }
+        }
+    }
+    if (no)
+        wrbuf_printf(wrbuf, "\"");
+}
+
 static void snippet_xml_record(ZebraHandle zh, WRBUF wrbuf, zebra_snippets *doc)
 {
     const zebra_snippet_word *doc_w;
@@ -503,8 +538,11 @@ static void snippet_xml_record(ZebraHandle zh, WRBUF wrbuf, zebra_snippets *doc)
 
             if (mark_state == 0)
             {
+                
                 wrbuf_printf(wrbuf, "  <snippet name=\"%s\"",  string_index);
-                wrbuf_printf(wrbuf, " type=\"%s\">", index_type);
+                wrbuf_printf(wrbuf, " type=\"%s\"", index_type);
+                snippet_check_fields(zh, wrbuf, doc, doc_w, index_type);
+                wrbuf_printf(wrbuf, ">");
             }
             if (doc_w->match)
                 wrbuf_puts(wrbuf, "<s>");
@@ -743,7 +781,7 @@ static int perform_facet_sort(ZebraHandle zh, int no_ord, int *ord_array,
             zebra_sort_type(zh->reg->sort_index, ord_array[ord_i]);
             
             wrbuf_rewind(w);
-            if (zebra_sort_read(zh->reg->sort_index, w))
+            if (zebra_sort_read(zh->reg->sort_index, 0, w))
             {
                 zebra_strmap_t sm = map_array[ord_i];
                 int off = 0;
@@ -1311,6 +1349,7 @@ int zebra_record_fetch(ZebraHandle zh, const char *setname,
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab