Merge branch 'protocol-version2' of ssh://git.indexdata.com/home/git/pub/pazpar2...
authorDennis Schafroth <dennis@indexdata.com>
Thu, 12 Apr 2012 16:14:14 +0000 (18:14 +0200)
committerDennis Schafroth <dennis@indexdata.com>
Thu, 12 Apr 2012 16:14:14 +0000 (18:14 +0200)
Conflicts:
src/session.c

Fixed.

1  2 
js/pz2.js
src/client.c
src/session.c

diff --combined js/pz2.js
+++ b/js/pz2.js
@@@ -126,6 -126,6 +126,8 @@@ var pz2 = function ( paramArray 
      if (this.useSessions && paramArray.autoInit !== false) {
          this.init(this.sessionId, this.serviceId);
      }
++    // Version parameter
++    this.version = paramArray.version || null;
  };
  
  pz2.prototype = 
                  "command": "termlist", 
                  "session": this.sessionID, 
                  "name": this.termKeys,
--                "windowid" : window.name
++                "windowid" : window.name, 
++              "version" : this.version
++      
              },
              function(data) {
                  if ( data.getElementsByTagName("termlist") ) {
                                      .childNodes[0].nodeValue || 'ERROR'
                              };
  
++                          // Only for xtargets: id, records, filtered
                              var termIdNode = 
                                  terms[j].getElementsByTagName("id");
                              if(terms[j].getElementsByTagName("id").length)
                                  term["id"] = 
                                      termIdNode[0].childNodes[0].nodeValue;
                              termList[listName][j] = term;
++
++                          var recordsNode  = terms[j].getElementsByTagName("records");
++                          if (recordsNode && recordsNode.length)
++                              term["records"] = recordsNode[0].childNodes[0].nodeValue;
++                              
++                          var filteredNode  = terms[j].getElementsByTagName("filtered");
++                          if (filteredNode && filteredNode.length)
++                              term["filtered"] = filteredNode[0].childNodes[0].nodeValue;
++                              
                          }
                      }
  
                "command": "bytarget", 
                "session": this.sessionID, 
                "block": 1,
--              "windowid" : window.name
++              "windowid" : window.name,
++              "version" : this.version
            },
              function(data) {
                  if ( data.getElementsByTagName("status")[0]
diff --combined src/client.c
@@@ -758,12 -758,13 +758,12 @@@ void client_start_search(struct client 
      const char *opt_preferred   = session_setting_oneval(sdb, PZ_PREFERRED);
      const char *extra_args      = session_setting_oneval(sdb, PZ_EXTRA_ARGS);
      const char *opt_present_chunk = session_setting_oneval(sdb, PZ_PRESENT_CHUNK);
 -    /* Default present chunk */
 -    int present_chunk = 20;
 +    ZOOM_query q;
 +    char maxrecs_str[24], startrecs_str[24], present_chunk_str[24];
 +    int present_chunk = 20; // Default chunk size
      if (opt_present_chunk && strcmp(opt_present_chunk,"")) {
          present_chunk = atoi(opt_present_chunk);
      }
 -    char maxrecs_str[24], startrecs_str[24], present_chunk_str[24];
 -    ZOOM_query q;
  
      assert(link);
  
@@@ -1326,6 -1327,14 +1326,14 @@@ Odr_int client_get_hits(struct client *
      return cl->hits;
  }
  
+ Odr_int client_get_approximation(struct client *cl)
+ {
+     int records = cl->record_offset + cl->filtered;
+     if (records > 0)
+         return cl->hits * cl->record_offset / records;
+     return cl->hits;
+ }
  int client_get_num_records(struct client *cl)
  {
      return cl->record_offset;
diff --combined src/session.c
@@@ -963,6 -963,7 +963,7 @@@ static struct hitsbytarget *hitsbytarge
          res[*count].id = client_get_id(cl);
          res[*count].name = *name ? name : "Unknown";
          res[*count].hits = client_get_hits(cl);
+         res[*count].approximation = client_get_approximation(cl);
          res[*count].records = client_get_num_records(cl);
          res[*count].filtered = client_get_num_records_filtered(cl);
          res[*count].diagnostic =
@@@ -1044,7 -1045,9 +1045,9 @@@ static int targets_termlist_nb(WRBUF wr
                       ht[i].hits);
  
          if (version >= 2) {
+             // Should not print if we know it isn't a approximation.
+             wrbuf_printf(wrbuf, "<approximation>" ODR_INT_PRINTF "</approximation>\n", ht[i].approximation);
 -            wrbuf_printf(wrbuf, "<records>%d</records>\n", ht[i].records);
 +            wrbuf_printf(wrbuf, "<records>%d</records>\n", ht[i].records - ht[i].filtered);
              wrbuf_printf(wrbuf, "<filtered>%d</filtered>\n", ht[i].filtered);
          }
  
@@@ -1186,7 -1189,7 +1189,7 @@@ void show_single_stop(struct session *s
  
  struct record_cluster **show_range_start(struct session *se,
                                           struct reclist_sortparms *sp, 
-                                          int start, int *num, int *total, Odr_int *sumhits)
+                                          int start, int *num, int *total, Odr_int *sumhits, Odr_int *approx_hits)
  {
      struct record_cluster **recs;
      struct reclist_sortparms *spp;
          *total = reclist_get_num_records(se->reclist);
  
          *sumhits = 0;
-         for (l = se->clients_active; l; l = l->next)
+         for (l = se->clients_active; l; l = l->next) {
              *sumhits += client_get_hits(l->client);
-         
+             *approx_hits += client_get_approximation(l->client);
+         }
          for (i = 0; i < start; i++)
              if (!reclist_read_record(se->reclist))
              {