Document rank may be dynamically defined in XSLT
[pazpar2-moved-to-github.git] / src / session.c
index f7f687d..60f3813 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2011 Index Data
+   Copyright (C) 2006-2012 Index Data
 
 Pazpar2 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
@@ -648,11 +648,9 @@ void session_sort(struct session *se, const char *field, int increasing)
     for (l = se->clients_active; l; l = l->next)
     {
         struct client *cl = l->client;
-        struct timeval tval;
-        if (client_prep_connection(cl, se->service->z3950_operation_timeout,
-                                   se->service->z3950_session_timeout,
-                                   se->service->server->iochan_man,
-                                   &tval))
+        if (client_get_state(cl) == Client_Connecting ||
+            client_get_state(cl) == Client_Idle ||
+            client_get_state(cl) == Client_Working)
             client_start_search(cl);
     }
     session_leave(se);
@@ -749,7 +747,7 @@ enum pazpar2_error_code session_search(struct session *se,
                 session_log(se, YLOG_LOG, "client REUSE %s", client_get_id(cl));
                 client_reingest(cl);
             }
-            else
+            else if (r)
             {
                 session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl));
                 client_start_search(cl);
@@ -1071,7 +1069,8 @@ void perform_termlist(struct http_channel *c, struct session *se,
     for (j = 0; j < num_names; j++)
     {
         const char *tname;
-        
+        int must_generate_empty = 1; /* bug 5350 */
+
         for (i = 0; i < se->num_termlists; i++)
         {
             tname = se->termlists[i].name;
@@ -1083,6 +1082,7 @@ void perform_termlist(struct http_channel *c, struct session *se,
                 wrbuf_puts(c->wrbuf, "<list name=\"");
                 wrbuf_xmlputs(c->wrbuf, tname);
                 wrbuf_puts(c->wrbuf, "\">\n");
+                must_generate_empty = 0;
 
                 p = termlist_highscore(se->termlists[i].termlist, &len);
                 if (p)
@@ -1117,6 +1117,13 @@ void perform_termlist(struct http_channel *c, struct session *se,
 
             targets_termlist_nb(c->wrbuf, se, num, c->nmem);
             wrbuf_puts(c->wrbuf, "</list>\n");
+            must_generate_empty = 0;
+        }
+        if (must_generate_empty)
+        {
+            wrbuf_puts(c->wrbuf, "<list name=\"");
+            wrbuf_xmlputs(c->wrbuf, names[j]);
+            wrbuf_puts(c->wrbuf, "\"/>\n");
         }
     }
     session_leave(se);
@@ -1756,6 +1763,8 @@ static int ingest_to_cluster(struct client *cl,
             struct record_metadata *rec_md = 0;
             int md_field_id = -1;
             int sk_field_id = -1;
+            int rank = 0;
+            xmlChar *rank_str = 0;
             
             type = xmlGetProp(n, (xmlChar *) "type");
             value = xmlNodeListGetString(xdoc, n->children, 1);
@@ -1769,6 +1778,15 @@ static int ingest_to_cluster(struct client *cl,
                 continue;
             
             ser_md = &service->metadata[md_field_id];
+
+            rank_str = xmlGetProp(n, (xmlChar *) "rank");
+            if (rank_str)
+            {
+                rank = atoi((const char *) rank_str);
+                xmlFree(rank_str);
+            }
+            else
+                rank = ser_md->rank;
             
             if (ser_md->sortkey_offset >= 0)
             {
@@ -1868,10 +1886,11 @@ static int ingest_to_cluster(struct client *cl,
 
 
             // ranking of _all_ fields enabled ... 
-            if (ser_md->rank)
+            if (rank)
+            {
                 relevance_countwords(se->relevance, cluster, 
-                                     (char *) value, ser_md->rank,
-                                     ser_md->name);
+                                     (char *) value, rank, ser_md->name);
+            }
 
             // construct facets ... unless the client already has reported them
             if (ser_md->termlist && !client_has_facet(cl, (char *) type))