#include <yaz/querytowrbuf.h>
#include <yaz/oid_db.h>
#include <yaz/snprintf.h>
+#include <yaz/xml_get.h>
#define USE_TIMING 0
#if USE_TIMING
continue;
if (!strcmp((const char *) n->name, "metadata"))
{
- xmlChar *type = xmlGetProp(n, (xmlChar *) "type");
+ const char *type = yaz_xml_get_prop(n, "type");
if (type == NULL) {
yaz_log(YLOG_FATAL, "Missing type attribute on metadata element. Skipping!");
}
if (value)
xmlFree(value);
}
- xmlFree(type);
}
}
return no_found;
{
char *mergekey_norm = 0;
WRBUF norm_wr = wrbuf_alloc();
- xmlChar *mergekey;
+ const char *mergekey;
if (session_mergekey)
{
for (i = 0; i < num; i++)
get_mergekey_from_doc(doc, root, values[i], service, norm_wr);
}
- else if ((mergekey = xmlGetProp(root, (xmlChar *) "mergekey")))
+ else if ((mergekey = yaz_xml_get_prop(root, "mergekey")))
{
- mergekey_norm_wr(service->charsets, norm_wr, (const char *) mergekey);
- xmlFree(mergekey);
+ mergekey_norm_wr(service->charsets, norm_wr, mergekey);
}
else
{
continue;
if (!strcmp((const char *) n->name, "metadata"))
{
- xmlChar *type = xmlGetProp(n, (xmlChar *) "type");
+ const char *type = yaz_xml_get_prop(n, "type");
if (type)
{
size_t len;
}
xmlFree(value);
}
- xmlFree(type);
}
}
}
}
static int ingest_to_cluster(struct client *cl,
+ WRBUF wrbuf_disp,
+ WRBUF wrbuf_norm,
xmlDoc *xdoc,
xmlNode *root,
int record_no,
{
int ret = 0;
struct session *se = client_get_session(cl);
+ WRBUF wrbuf_disp, wrbuf_norm;
if (!check_record_filter(root, sdb))
{
record_no, sdb->database->id);
return 0;
}
+ wrbuf_disp = wrbuf_alloc();
+ wrbuf_norm = wrbuf_alloc();
session_enter(se, "ingest_sub_record");
if (client_get_session(cl) == se && se->relevance)
- ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekeys);
+ ret = ingest_to_cluster(cl, wrbuf_disp, wrbuf_norm,
+ xdoc, root, record_no, mergekeys);
session_leave(se, "ingest_sub_record");
-
+ wrbuf_destroy(wrbuf_norm);
+ wrbuf_destroy(wrbuf_disp);
return ret;
}
}
static int ingest_to_cluster(struct client *cl,
+ WRBUF wrbuf_disp,
+ WRBUF wrbuf_norm,
xmlDoc *xdoc,
xmlNode *root,
int record_no,
struct record_metadata_attr *merge_keys)
{
xmlNode *n;
- xmlChar *type = 0;
- xmlChar *value = 0;
struct session *se = client_get_session(cl);
struct conf_service *service = se->service;
int term_factor = 1;
for (n = root->children; n; n = n->next)
{
- if (type)
- xmlFree(type);
- if (value)
- xmlFree(value);
- type = value = 0;
-
if (n->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) n->name, "metadata"))
struct record_metadata **wheretoput = 0;
struct record_metadata *rec_md = 0;
int md_field_id = -1;
+ xmlChar *value0;
+ const char *type = yaz_xml_get_prop(n, "type");
- type = xmlGetProp(n, (xmlChar *) "type");
- value = xmlNodeListGetString(xdoc, n->children, 1);
if (!type)
continue;
- if (!value || !*value)
+ wrbuf_rewind(wrbuf_disp);
+ value0 = xmlNodeListGetString(xdoc, n->children, 1);
+ if (!value0 || !*value0)
{
- xmlChar *empty = xmlGetProp(n, (xmlChar *) "empty");
+ const char *empty = yaz_xml_get_prop(n, "empty");
if (!empty)
continue;
- if (value)
- xmlFree(value);
- value = empty;
+ wrbuf_puts(wrbuf_disp, (const char *) empty);
}
+ else
+ {
+ wrbuf_puts(wrbuf_disp, (const char *) value0);
+ }
+ if (value0)
+ xmlFree(value0);
md_field_id
= conf_service_metadata_field_id(service, (const char *) type);
if (md_field_id < 0)
ser_md = &service->metadata[md_field_id];
// non-merged metadata
- rec_md = record_metadata_init(se->nmem, (const char *) value,
+ rec_md = record_metadata_init(se->nmem, wrbuf_cstr(wrbuf_disp),
ser_md->type, n->properties);
if (!rec_md)
{
session_log(se, YLOG_WARN, "bad metadata data '%s' "
- "for element '%s'", value, type);
+ "for element '%s'", wrbuf_cstr(wrbuf_disp), type);
continue;
}
{
WRBUF w = wrbuf_alloc();
if (relevance_snippet(se->relevance,
- (char*) value, ser_md->name, w))
+ wrbuf_cstr(wrbuf_disp), ser_md->name, w))
rec_md->data.text.snippet = nmem_strdup(se->nmem,
wrbuf_cstr(w));
wrbuf_destroy(w);
if (check_limit_local(cl, record, record_no))
{
- if (type)
- xmlFree(type);
- if (value)
- xmlFree(value);
return -2;
}
cluster = reclist_insert(se->reclist, se->relevance, service, record,
merge_keys, &se->total_merged);
if (!cluster)
{
- if (type)
- xmlFree(type);
- if (value)
- xmlFree(value);
return 0; // complete match with existing record
}
// now parsing XML record and adding data to cluster or record metadata
for (n = root->children; n; n = n->next)
{
- if (type)
- xmlFree(type);
- if (value)
- xmlFree(value);
- type = value = 0;
-
if (n->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) n->name, "metadata"))
int md_field_id = -1;
int sk_field_id = -1;
const char *rank = 0;
- xmlChar *xml_rank = 0;
-
- type = xmlGetProp(n, (xmlChar *) "type");
- value = xmlNodeListGetString(xdoc, n->children, 1);
+ const char *xml_rank = 0;
+ const char *type = 0;
+ xmlChar *value0;
- if (!type || !value || !*value)
+ wrbuf_rewind(wrbuf_disp);
+ type = yaz_xml_get_prop(n, "type");
+ if (!type)
continue;
md_field_id
ser_sk = &service->sortkeys[sk_field_id];
}
+ value0 = xmlNodeListGetString(xdoc, n->children, 1);
+ if (!value0 || !*value0)
+ {
+ if (value0)
+ xmlFree(value0);
+ continue;
+ }
+ wrbuf_puts(wrbuf_disp, (const char *) value0);
+ xmlFree(value0);
+
+
// merged metadata
- rec_md = record_metadata_init(se->nmem, (const char *) value,
+ rec_md = record_metadata_init(se->nmem, wrbuf_cstr(wrbuf_disp),
ser_md->type, 0);
// see if the field was not in cluster already (from beginning)
}
else
{
- xml_rank = xmlGetProp(n, (xmlChar *) "rank");
+ xml_rank = yaz_xml_get_prop(n, "rank");
rank = xml_rank ? (const char *) xml_rank : ser_md->rank;
}
if (rank)
{
relevance_countwords(se->relevance, cluster,
- (char *) value, rank, ser_md->name);
+ wrbuf_cstr(wrbuf_disp),
+ rank, ser_md->name);
}
// construct facets ... unless the client already has reported them
if (ser_md->termlist && !client_has_facet(cl, (char *) type))
}
}
else
- add_facet(se, (char *) type, (char *) value, term_factor);
+ add_facet(se, type, wrbuf_cstr(wrbuf_disp), term_factor);
}
-
- // cleaning up
- if (xml_rank)
- xmlFree(xml_rank);
- xmlFree(type);
- xmlFree(value);
- type = value = 0;
}
else
{
se->number_of_warnings_unknown_elements++;
}
}
- if (type)
- xmlFree(type);
- if (value)
- xmlFree(value);
-
nmem_destroy(ingest_nmem);
xfree(metadata0);
relevance_donerecord(se->relevance, cluster);
#include <stdio.h>
#include <sys/types.h>
#include <yaz/dirent.h>
+#include <yaz/xml_get.h>
#include <stdlib.h>
#include <sys/stat.h>
struct setting *set))
{
int ret_val = 0; /* success */
- char *namea = (char *) xmlGetProp(n, (xmlChar *) "name");
- char *targeta = (char *) xmlGetProp(n, (xmlChar *) "target");
- char *valuea = (char *) xmlGetProp(n, (xmlChar *) "value");
- char *usera = (char *) xmlGetProp(n, (xmlChar *) "user");
- char *precedencea = (char *) xmlGetProp(n, (xmlChar *) "precedence");
+ const char *namea = yaz_xml_get_prop(n, "name");
+ const char *targeta = yaz_xml_get_prop(n, "target");
+ const char *valuea = yaz_xml_get_prop(n, "value");
+ const char *precedencea = yaz_xml_get_prop(n, "precedence");
for (n = n->children; n; n = n->next)
{
{
xmlNode *root = n->children;
struct setting set;
- char *name = (char *) xmlGetProp(n, (xmlChar *) "name");
- char *target = (char *) xmlGetProp(n, (xmlChar *) "target");
- char *value = (char *) xmlGetProp(n, (xmlChar *) "value");
- char *user = (char *) xmlGetProp(n, (xmlChar *) "user");
- char *precedence = (char *) xmlGetProp(n, (xmlChar *) "precedence");
+ const char *name = yaz_xml_get_prop(n, "name");
+ const char *target = yaz_xml_get_prop(n, "target");
+ const char *value = yaz_xml_get_prop(n, "value");
+ const char *precedence = yaz_xml_get_prop(n, "precedence");
xmlChar *buf_out = 0;
set.next = 0;
xmlDocSetRootElement(doc, xmlCopyNode(root, 1));
xmlDocDumpMemory(doc, &buf_out, &len_out);
/* xmlDocDumpMemory 0-terminates */
- set.value = (char *) buf_out;
+ set.value = (const char *) buf_out;
xmlFreeDoc(doc);
}
}
ret_val = -1;
}
xmlFree(buf_out);
- xmlFree(name);
- xmlFree(precedence);
- xmlFree(value);
- xmlFree(user);
- xmlFree(target);
}
else
{
ret_val = -1;
}
}
- xmlFree(namea);
- xmlFree(precedencea);
- xmlFree(valuea);
- xmlFree(usera);
- xmlFree(targeta);
return ret_val;
}