Added 'virtual' facet named 'xtargets' to termlist command, which returns
[pazpar2-moved-to-github.git] / src / pazpar2.c
index 1f91e6a..66a1d12 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.8 2007-01-03 16:59:32 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.13 2007-01-04 20:00:58 quinn Exp $ */;
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <yaz/yaz-util.h>
 #include <yaz/nmem.h>
 
+#define USE_TIMING 0
+#if USE_TIMING
+#include <yaz/timing.h>
+#endif
+
 #include "pazpar2.h"
 #include "eventl.h"
 #include "command.h"
@@ -76,7 +81,6 @@ struct parameters global_parameters =
     0
 };
 
-
 static int send_apdu(struct client *c, Z_APDU *a)
 {
     struct connection *co = c->connection;
@@ -451,26 +455,35 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
         {
             xmlChar *type = xmlGetProp(n, "type");
             xmlChar *value = xmlNodeListGetString(xdoc, n->children, 0);
-            add_facet(se, type, value);
-            relevance_countwords(se->relevance, head, value, 1);
+            if (type && value)
+            {
+                add_facet(se, type, value);
+                relevance_countwords(se->relevance, head, value, 1);
+            }
             xmlFree(type);
             xmlFree(value);
         }
         else if (!strcmp(n->name, "metadata"))
         {
-            xmlChar *type = xmlGetProp(n, "type"), *value;
-            if (!strcmp(type, "title"))
-                res->title = nmem_strdup(se->nmem,
-                        value = xmlNodeListGetString(xdoc, n->children, 0));
-
-            relevance_countwords(se->relevance, head, value, 4);
+            xmlChar *type = xmlGetProp(n, "type");
+            if (type && !strcmp(type, "title"))
+            {
+                xmlChar *value = xmlNodeListGetString(xdoc, n->children, 0);
+                if (value)
+                {
+                    res->title = nmem_strdup(se->nmem, value);
+                    relevance_countwords(se->relevance, head, value, 4);
+                    xmlFree(value);
+                }
+            }
             xmlFree(type);
-            xmlFree(value);
         }
         else
             yaz_log(YLOG_WARN, "Unexpected element %s in internal record", n->name);
     }
 
+    xmlFreeDoc(xdoc);
+
     relevance_donerecord(se->relevance, head);
     se->total_records++;
 
@@ -479,6 +492,9 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
 
 static void ingest_records(struct client *cl, Z_Records *r)
 {
+#if USE_TIMING
+    yaz_timing_t t = yaz_timing_create();
+#endif
     struct record *rec;
     struct session *s = cl->session;
     Z_NamePlusRecordList *rlist;
@@ -503,6 +519,14 @@ static void ingest_records(struct client *cl, Z_Records *r)
     }
     if (s->watchlist[SESSION_WATCH_RECORDS].fun && rlist->num_records)
         session_alert_watch(s, SESSION_WATCH_RECORDS);
+
+#if USE_TIMING
+    yaz_timing_stop(t);
+    yaz_log(YLOG_LOG, "ingest_records %6.5f %3.2f %3.2f", 
+            yaz_timing_get_real(t), yaz_timing_get_user(t),
+            yaz_timing_get_sys(t));
+    yaz_timing_destroy(&t);
+#endif
 }
 
 static void do_presentResponse(IOCHAN i, Z_APDU *a)
@@ -1017,6 +1041,21 @@ int select_targets(struct session *se)
     return c;
 }
 
+int session_active_clients(struct session *s)
+{
+    struct client *c;
+    int res = 0;
+
+    for (c = s->clients; c; c = c->next)
+        if (c->connection && (c->state == Client_Connecting ||
+                    c->state == Client_Initializing ||
+                    c->state == Client_Searching ||
+                    c->state == Client_Presenting))
+            res++;
+
+    return res;
+}
+
 char *search(struct session *se, char *query)
 {
     int live_channels = 0;
@@ -1141,7 +1180,9 @@ struct record **show(struct session *s, int start, int *num, int *total,
     struct record **recs = nmem_malloc(nmem_show, *num 
                                        * sizeof(struct record *));
     int i;
-
+#if USE_TIMING    
+    yaz_timing_t t = yaz_timing_create();
+#endif
     relevance_prepare_read(s->relevance, s->reclist);
 
     *total = s->reclist->num_records;
@@ -1151,7 +1192,8 @@ struct record **show(struct session *s, int start, int *num, int *total,
         if (!reclist_read_record(s->reclist))
         {
             *num = 0;
-            return 0;
+            recs = 0;
+            break;
         }
 
     for (i = 0; i < *num; i++)
@@ -1164,6 +1206,13 @@ struct record **show(struct session *s, int start, int *num, int *total,
         }
         recs[i] = r;
     }
+#if USE_TIMING
+    yaz_timing_stop(t);
+    yaz_log(YLOG_LOG, "show %6.5f %3.2f %3.2f", 
+            yaz_timing_get_real(t), yaz_timing_get_user(t),
+            yaz_timing_get_sys(t));
+    yaz_timing_destroy(&t);
+#endif
     return recs;
 }