facet ID term map - take 1
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 2 Jul 2015 12:42:00 +0000 (14:42 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 2 Jul 2015 12:42:00 +0000 (14:42 +0200)
In this scenario if pz:facetmap has a split: prefix, eg
 <set name="pz:facetmap:split:subject" value="facet_05"/>
Then the subjects will be split into a normal display facet
and an ID - separated by first colon. This makes it possible
to limit _one_ target's native facet IDs but will not work
for anything else - because these definitions are target specific!!

perf/bash/pp2client.sh
src/session.c
src/termlists.c
src/termlists.h

index 03b0421..c39077d 100755 (executable)
@@ -93,6 +93,7 @@ if [ "$TIME" != "" ] ; then
 else
     wget -q -O ${TMP_DIR}$OF.show.xml "$H?command=show&session=$S&sort=relevance&start=0&num=100&block=1"
 fi
+wget -q -O ${TMP_DIR}$OF.termlist.xml "$H?command=termlist&session=$S"
 wget -q -O ${TMP_DIR}$OF.bytarget.xml "$H?command=bytarget&session=$S"
 wget -q -O ${TMP_DIR}$OF.stat.xml "$H?command=stat&session=$S"
 wget -q -O ${TMP_DIR}$OF.info.xml "$H?command=info"
index e67cd10..e7d5b9c 100644 (file)
@@ -207,9 +207,27 @@ void add_facet(struct session *s, const char *type, const char *value, int count
 {
     WRBUF facet_wrbuf = wrbuf_alloc();
     WRBUF display_wrbuf = wrbuf_alloc();
+    const char *id = 0;
+    size_t id_len = 0;
 
-    session_normalize_facet(s, type, value, display_wrbuf, facet_wrbuf);
+    yaz_log(YLOG_LOG, "add_facet type=%s value=%s count=%d",
+            type, value, count);
+
+    /* inspect pz:facetmap:split:name ?? */
+    if (!strncmp(type, "split:", 6))
+    {
+        const char *cp = strchr(value, ':');
+        if (cp)
+        {
+            id = value;
+            id_len = cp - value;
+            value = cp + 1;
+            yaz_log(YLOG_LOG, "strip id=%s value=%s", id, value);
+        }
+        type += 6;
+    }
 
+    session_normalize_facet(s, type, value, display_wrbuf, facet_wrbuf);
     if (wrbuf_len(facet_wrbuf))
     {
         struct named_termlist **tp = &s->termlists;
@@ -224,7 +242,7 @@ void add_facet(struct session *s, const char *type, const char *value, int count
             (*tp)->next = 0;
         }
         termlist_insert((*tp)->termlist, wrbuf_cstr(display_wrbuf),
-                        wrbuf_cstr(facet_wrbuf), count);
+                        wrbuf_cstr(facet_wrbuf), id, id_len, count);
     }
     wrbuf_destroy(facet_wrbuf);
     wrbuf_destroy(display_wrbuf);
@@ -1216,7 +1234,12 @@ void perform_termlist(struct http_channel *c, struct session *se,
                         wrbuf_puts(c->wrbuf, "<name>");
                         wrbuf_xmlputs(c->wrbuf, p[i]->display_term);
                         wrbuf_puts(c->wrbuf, "</name>");
-
+                        if (p[i]->id)
+                        {
+                            wrbuf_puts(c->wrbuf, "<value>");
+                            wrbuf_xmlputs(c->wrbuf, p[i]->id);
+                            wrbuf_puts(c->wrbuf, "</value>");
+                        }
                         wrbuf_printf(c->wrbuf,
                                      "<frequency>%d</frequency>",
                                      p[i]->frequency);
index 8f06a47..79e88ee 100644 (file)
@@ -62,7 +62,8 @@ struct termlist *termlist_create(NMEM nmem)
 }
 
 void termlist_insert(struct termlist *tl, const char *display_term,
-                     const char *norm_term, int freq)
+                     const char *norm_term, const char *id, size_t id_len,
+                     int freq)
 {
     unsigned int bucket;
     struct termlist_bucket **p;
@@ -87,6 +88,7 @@ void termlist_insert(struct termlist *tl, const char *display_term,
         new->term.norm_term = nmem_strdup(tl->nmem, buf);
         new->term.display_term = *display_term ?
             nmem_strdup(tl->nmem, display_term) : new->term.norm_term;
+        new->term.id = id ? nmem_strdupn(tl->nmem, id, id_len) : 0;
         new->term.frequency = freq;
         new->next = 0;
         *p = new;
index 8502e3e..0d5310a 100644 (file)
@@ -26,6 +26,7 @@ struct termlist_score
 {
     char *norm_term;
     char *display_term;
+    char *id;
     int frequency;
 };
 
@@ -33,7 +34,8 @@ struct termlist;
 
 struct termlist *termlist_create(NMEM nmem);
 void termlist_insert(struct termlist *tl, const char *display_term,
-                     const char *norm_term, int freq);
+                     const char *norm_term,
+                     const char *id, size_t id_len, int freq);
 struct termlist_score **termlist_highscore(struct termlist *tl, int *len,
                                            NMEM nmem);