Allow retrieval of Search Result-1 information in ZOOM by the use of
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 1 Nov 2005 15:08:01 +0000 (15:08 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 1 Nov 2005 15:08:01 +0000 (15:08 +0000)
options that are attached to a result set. ZOOM documentation updated
accordingly.

NEWS
doc/zoom.xml
src/zoom-c.c

diff --git a/NEWS b/NEWS
index 4cb318b..eb54190 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Allow retrieval of Search Result-1 information in ZOOM by the
+use of options that are attached to a result set. ZOOM documentation
+updated accordingly.
+
 Fixed bug #416: First/second comb characters not handled in the
 MARC-8 to UTF-8 conversion. Patch by Raj Patel.
 
index 8096140..d625e58 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $Id: zoom.xml,v 1.38 2005-09-07 11:53:25 adam Exp $ -->
+<!-- $Id: zoom.xml,v 1.39 2005-11-01 15:08:01 adam Exp $ -->
  <chapter id="zoom"><title>ZOOM</title>
   <para>
     &zoom; is an acronym for 'Z39.50 Object-Orientation Model' and is
      </tbody>
     </tgroup>
    </table>
+   <para>
+    For servers that support Search Info report, the following
+    options may be read using <function>ZOOM_resultset_get</function>.
+    This detailed information is read after a successful search has
+    completed.
+   </para>
+   <para>
+    This information is a list of of items, where each item is
+    information about a term or subquery. All items in the list 
+    are prefixed by 
+    <literal>SearchResult.</literal><replaceable>no</replaceable>
+    where no presents the item number (0=first, 1=second). 
+    Read <literal>SearchResult.size</literal> to determine the
+    number of items.
+   </para>
+   <table frame="top"><title>Search Info Report options</title>
+    <tgroup cols="2">
+     <colspec colwidth="4*" colname="name"></colspec>
+     <colspec colwidth="7*" colname="description"></colspec>
+     <thead>
+      <row>
+       <entry>Option</entry>
+       <entry>Description</entry>
+      </row>
+     </thead>
+     <tbody>
+      <row>
+       <entry>SearchResult.size</entry>
+       <entry>
+       number of search result entries. This option is-nonexistant
+       if no entries are returned by the server.
+       </entry>
+      </row>
+      <row>
+       <entry>SearchResult.<replaceable>no</replaceable>.subqueryId</entry>
+       <entry>sub query ID</entry>
+      </row>
+      <row>
+       <entry>SearchResult.<replaceable>no</replaceable>.subqueryCount</entry>
+       <entry>result count for item (number of hits)</entry>
+      </row>
+      <row>
+       <entry>SearchResult.<replaceable>no</replaceable>.subquery.term</entry>
+       <entry>subquery term</entry>
+      </row>
+      <row>
+       <entry>
+       SearchResult.<replaceable>no</replaceable>.interpretation.term
+       </entry>
+       <entry>interpretation term</entry>
+      </row>
+      <row>
+       <entry>
+       SearchResult.<replaceable>no</replaceable>.recommendation.term
+       </entry>
+       <entry>recommendation term</entry>
+      </row>
+     </tbody>
+    </tgroup>
+   </table>
    <sect2>
     <title>Z39.50 Protocol behavior</title>
     <para>
index 9fa1e49..3e5c65e 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: zoom-c.c,v 1.47 2005-10-17 12:29:44 mike Exp $
+ * $Id: zoom-c.c,v 1.48 2005-11-01 15:08:02 adam Exp $
  */
 /**
  * \file zoom-c.c
@@ -1045,7 +1045,7 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c)
         ZOOM_options_get(c->options, "implementationName"),
         odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
 
-    version = odr_strdup(c->odr_out, "$Revision: 1.47 $");
+    version = odr_strdup(c->odr_out, "$Revision: 1.48 $");
     if (strlen(version) > 10)   /* check for unexpanded CVS strings */
         version[strlen(version)-2] = '\0';
     ireq->implementationVersion = odr_prepend(c->odr_out,
@@ -2028,6 +2028,111 @@ static void handle_present_response (ZOOM_connection c, Z_PresentResponse *pr)
     handle_records (c, pr->records, 1);
 }
 
+static void handle_queryExpressionTerm(ZOOM_options opt, const char *name,
+                                       Z_Term *term)
+{
+    switch (term->which)
+    {
+    case Z_Term_general:
+        ZOOM_options_setl(opt, name,
+                          term->u.general->buf, term->u.general->len);
+        break;
+    case Z_Term_characterString:
+        ZOOM_options_set(opt, name, term->u.characterString);
+        break;
+    case Z_Term_numeric:
+        ZOOM_options_set_int(opt, name, *term->u.numeric);
+        break;
+    }
+}
+
+static void handle_queryExpression(ZOOM_options opt, const char *name,
+                                   Z_QueryExpression *exp)
+{
+    char opt_name[80];
+    
+    switch (exp->which)
+    {
+    case Z_QueryExpression_term:
+        if (exp->u.term && exp->u.term->queryTerm)
+        {
+            sprintf(opt_name, "%s.term", name);
+            handle_queryExpressionTerm(opt, opt_name, exp->u.term->queryTerm);
+        }
+        break;
+    case Z_QueryExpression_query:
+        break;
+    }
+}
+
+static void handle_searchResult(ZOOM_connection c, ZOOM_resultset resultset,
+                                Z_OtherInformation *o)
+{
+    int i;
+    for (i = 0; o && i < o->num_elements; i++)
+    {
+        if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
+        {
+            Z_External *ext = o->list[i]->information.externallyDefinedInfo;
+            
+            if (ext->which == Z_External_searchResult1)
+            {
+                int j;
+                Z_SearchInfoReport *sr = ext->u.searchResult1;
+                
+                if (sr->num)
+                    ZOOM_options_set_int(
+                        resultset->options, "SearchResult.size", sr->num);
+
+                for (j = 0; j < sr->num; j++)
+                {
+                    Z_SearchInfoReport_s *ent =
+                        ext->u.searchResult1->elements[j];
+                    char pref[80];
+                    
+                    sprintf(pref, "SearchResult.%d", j);
+
+                    if (ent->subqueryId)
+                    {
+                        char opt_name[80];
+                        sprintf(opt_name, "%s.subqueryId", pref);
+                        ZOOM_options_set(resultset->options, opt_name,
+                                         ent->subqueryId);
+                    }
+                    if (ent->subqueryExpression)
+                    {
+                        char opt_name[80];
+                        sprintf(opt_name, "%s.subquery", pref);
+                        handle_queryExpression(resultset->options, opt_name,
+                                               ent->subqueryExpression);
+                    }
+                    if (ent->subqueryInterpretation)
+                    {
+                        char opt_name[80];
+                        sprintf(opt_name, "%s.interpretation", pref);
+                        handle_queryExpression(resultset->options, opt_name,
+                                               ent->subqueryInterpretation);
+                    }
+                    if (ent->subqueryRecommendation)
+                    {
+                        char opt_name[80];
+                        sprintf(opt_name, "%s.recommendation", pref);
+                        handle_queryExpression(resultset->options, opt_name,
+                                               ent->subqueryRecommendation);
+                    }
+                    if (ent->subqueryCount)
+                    {
+                        char opt_name[80];
+                        sprintf(opt_name, "%s.subqueryCount", pref);
+                        ZOOM_options_set_int(resultset->options, opt_name,
+                                             *ent->subqueryCount);
+                    }                                             
+                }
+            }
+        }
+    }
+}
+
 static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr)
 {
     ZOOM_resultset resultset;
@@ -2035,12 +2140,14 @@ static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr)
 
     if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
         return ;
-    
+
     event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
     ZOOM_connection_put_event(c, event);
 
     resultset = c->tasks->u.search.resultset;
 
+    handle_searchResult(c, resultset, sr->additionalSearchInfo);
+
     resultset->size = *sr->resultCount;
     handle_records (c, sr->records, 0);
 }