Get target suggestions from client
[pazpar2-moved-to-github.git] / src / session.c
index 9de7ed9..c8f1df5 100644 (file)
@@ -921,6 +921,8 @@ struct session *new_session(NMEM nmem, struct conf_service *service,
     return session;
 }
 
+const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf);
+
 static struct hitsbytarget *hitsbytarget_nb(struct session *se,
                                             int *count, NMEM nmem)
 {
@@ -949,6 +951,9 @@ static struct hitsbytarget *hitsbytarget_nb(struct session *se,
         res[*count].connected  = client_get_connection(cl) ? 1 : 0;
         session_settings_dump(se, client_get_database(cl), w);
         res[*count].settings_xml = nmem_strdup(nmem, wrbuf_cstr(w));
+        wrbuf_rewind(w);
+        wrbuf_puts(w, "");
+        res[*count].suggestions_xml = nmem_strdup(nmem, client_get_suggestions_xml(cl, w));
         wrbuf_destroy(w);
         (*count)++;
     }
@@ -1045,6 +1050,11 @@ void perform_termlist(struct http_channel *c, struct session *se,
     for (j = 0; j < num_names; j++)
     {
         const char *tname;
+        
+        wrbuf_puts(c->wrbuf, "<list name=\"");
+        wrbuf_xmlputs(c->wrbuf, names[j]);
+        wrbuf_puts(c->wrbuf, "\">\n");
+
         for (i = 0; i < se->num_termlists; i++)
         {
             tname = se->termlists[i].name;
@@ -1056,9 +1066,6 @@ void perform_termlist(struct http_channel *c, struct session *se,
                 if (p)
                 {
                     int i;
-                    wrbuf_puts(c->wrbuf, "<list name=\"");
-                    wrbuf_xmlputs(c->wrbuf, tname);
-                    wrbuf_puts(c->wrbuf, "\">\n");
                     for (i = 0; i < len && i < num; i++)
                     {
                         // prevent sending empty term elements
@@ -1075,19 +1082,15 @@ void perform_termlist(struct http_channel *c, struct session *se,
                                      p[i]->frequency);
                         wrbuf_puts(c->wrbuf, "</term>\n");
                     }
-                    wrbuf_puts(c->wrbuf, "</list>\n");
                 }
             }
         }
         tname = "xtargets";
         if (num_names > 0 && !strcmp(names[j], tname))
         {
-            wrbuf_puts(c->wrbuf, "<list name=\"");
-            wrbuf_xmlputs(c->wrbuf, tname);
-            wrbuf_puts(c->wrbuf, "\">\n");
             targets_termlist_nb(c->wrbuf, se, num, c->nmem);
-            wrbuf_puts(c->wrbuf, "</list>\n");
         }
+        wrbuf_puts(c->wrbuf, "</list>\n");
     }
     session_leave(se);
     nmem_destroy(nmem_tmp);
@@ -1667,6 +1670,9 @@ static int ingest_to_cluster(struct client *cl,
             // merged metadata
             rec_md = record_metadata_init(se->nmem, (const char *) value,
                                           ser_md->type, 0);
+            if (!rec_md)
+                continue;
+
             wheretoput = &cluster->metadata[md_field_id];
 
             // and polulate with data: