SOLR + facets: use Odr_int for counts
[yaz-moved-to-github.git] / src / solr.c
index 0fd1480..701e9f3 100644 (file)
@@ -59,8 +59,9 @@ static void yaz_solr_decode_result_docs(ODR o, xmlNodePtr ptr,
     for (node = ptr->children; node; node = node->next)
         if (node->type == XML_ELEMENT_NODE)
             sr->num_records++;
-
-    sr->records = odr_malloc(o, sizeof(*sr->records) * sr->num_records);
+    
+    if (sr->num_records)
+        sr->records = odr_malloc(o, sizeof(*sr->records) * sr->num_records);
 
     for (node = ptr->children; node; node = node->next)
     {
@@ -117,7 +118,7 @@ static int yaz_solr_decode_result(ODR o, xmlNodePtr ptr,
     return -1;
 }
 
-static const char *get_facet_term_count(xmlNodePtr node, int *freq)
+static const char *get_facet_term_count(xmlNodePtr node, Odr_int *freq)
 {
     const char *term = yaz_element_attribute_value_get(node, "int", "name");
     xmlNodePtr child;
@@ -130,7 +131,7 @@ static const char *get_facet_term_count(xmlNodePtr node, int *freq)
         if (child->type == XML_TEXT_NODE)
             wrbuf_puts(wrbuf, (const char *) child->content);
     }
-    *freq = atoi(wrbuf_cstr(wrbuf));
+    *freq = odr_atoi(wrbuf_cstr(wrbuf));
     wrbuf_destroy(wrbuf);
     return term;
 }
@@ -153,11 +154,10 @@ Z_FacetField *yaz_solr_decode_facet_field(ODR o, xmlNodePtr ptr,
     index = 0;
     for (node = ptr->children; node; node = node->next)
     {
-        int count = 0;
+        Odr_int count = 0;
         const char *term = get_facet_term_count(node, &count);
         facet_field_term_set(o, facet_field,
-                             facet_term_create(o, term_create(o, term), count),
-                             index);
+                             facet_term_create_cstr(o, term, count), index);
         index++;
     }
     return facet_field;