Fix termlist for omitting name parameter
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 13 Dec 2011 13:35:42 +0000 (14:35 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 13 Dec 2011 13:35:42 +0000 (14:35 +0100)
Command termlist without name parameter should now return all
available termlist entries. Note that if name is given and that
refers to a non-existing termlist entry, no list is generated.
Previously an empty list was generated.

src/session.c
test/test_facets.urls
test/test_facets_11.res
test/test_facets_14.res
test/test_facets_17.res
test/test_facets_18.res
test/test_facets_24.res
test/test_facets_6.res

index 9706e0e..d388016 100644 (file)
@@ -1058,8 +1058,10 @@ void perform_termlist(struct http_channel *c, struct session *se,
     char **names;
     int num_names = 0;
 
-    if (name)
-        nmem_strsplit(nmem_tmp, ",", name, &names, &num_names);
+    if (!name)
+        name = "*";
+
+    nmem_strsplit(nmem_tmp, ",", name, &names, &num_names);
 
     session_enter(se);
 
@@ -1067,17 +1069,18 @@ void perform_termlist(struct http_channel *c, struct session *se,
     {
         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;
-            if (num_names > 0 && !strcmp(names[j], tname))
+            if (!strcmp(names[j], tname) || !strcmp(names[j], "*"))
             {
                 struct termlist_score **p = 0;
                 int len;
+
+                wrbuf_puts(c->wrbuf, "<list name=\"");
+                wrbuf_xmlputs(c->wrbuf, tname);
+                wrbuf_puts(c->wrbuf, "\">\n");
+
                 p = termlist_highscore(se->termlists[i].termlist, &len);
                 if (p)
                 {
@@ -1099,14 +1102,19 @@ void perform_termlist(struct http_channel *c, struct session *se,
                         wrbuf_puts(c->wrbuf, "</term>\n");
                     }
                 }
+                wrbuf_puts(c->wrbuf, "</list>\n");
             }
         }
         tname = "xtargets";
-        if (num_names > 0 && !strcmp(names[j], tname))
+        if (!strcmp(names[j], tname) || !strcmp(names[j], "*"))
         {
+            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);
index af9d74a..805ab95 100644 (file)
@@ -11,7 +11,7 @@ http://localhost:9763/search.pz2?session=1&command=bytarget
 http://localhost:9763/search.pz2?session=1&command=termlist&name=xtargets%2Cauthor%2Csubject%2Cdate%2Cmedium
 http://localhost:9763/search.pz2?session=1&command=search&query=8+and+computer
 http://localhost:9763/search.pz2?session=1&command=show&block=1
-http://localhost:9763/search.pz2?session=1&command=termlist&name=xtargets%2Cauthor%2Csubject%2Cdate%2Cmedium
+http://localhost:9763/search.pz2?session=1&command=termlist
 http://localhost:9763/search.pz2?session=1&command=search&query=6+and+computer
 http://localhost:9763/search.pz2?session=1&command=show
 http://localhost:9763/search.pz2?session=1&command=termlist&name=xtargets%2Cauthor%2Csubject%2Cdate%2Cmedium
index aaf0155..6045d02 100644 (file)
@@ -45,6 +45,4 @@
 <term><name>date8</name><frequency>20</frequency></term>
 <term><name>date9</name><frequency>10</frequency></term>
 </list>
-<list name="medium">
-</list>
 </termlist>
\ No newline at end of file
index 37b5a75..f750176 100644 (file)
@@ -45,6 +45,4 @@
 <term><name>date8</name><frequency>20</frequency></term>
 <term><name>date9</name><frequency>10</frequency></term>
 </list>
-<list name="medium">
-</list>
 </termlist>
\ No newline at end of file
index 00e11f8..7765713 100644 (file)
@@ -45,6 +45,4 @@
 <term><name>date8</name><frequency>20</frequency></term>
 <term><name>date9</name><frequency>10</frequency></term>
 </list>
-<list name="medium">
-</list>
 </termlist>
\ No newline at end of file
index 00e11f8..7765713 100644 (file)
@@ -45,6 +45,4 @@
 <term><name>date8</name><frequency>20</frequency></term>
 <term><name>date9</name><frequency>10</frequency></term>
 </list>
-<list name="medium">
-</list>
 </termlist>
\ No newline at end of file
index 598b204..512b81f 100644 (file)
@@ -40,6 +40,4 @@
 <term><name>date8</name><frequency>20</frequency></term>
 <term><name>date9</name><frequency>10</frequency></term>
 </list>
-<list name="medium">
-</list>
 </termlist>
\ No newline at end of file
index ebb8bb4..f78c7dc 100644 (file)
@@ -30,6 +30,4 @@
 <term><name>1973</name><frequency>1</frequency></term>
 <term><name>1980</name><frequency>1</frequency></term>
 </list>
-<list name="medium">
-</list>
 </termlist>
\ No newline at end of file