From 8657ae057499422e02e3c460090dc3d2870ce5d4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 18 Jan 2013 13:39:40 +0100 Subject: [PATCH] New merge attribute type: 'first' which takes all metadata fields from first target that returns the particular field. --- doc/pazpar2_conf.xml | 5 +++++ src/pazpar2_config.c | 2 ++ src/pazpar2_config.h | 3 ++- src/session.c | 23 ++++++++++++++++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index a45d77d..fbd39fb 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -322,6 +322,11 @@ all elements), or 'no' (don't merge; this is the default); + + Pazpar 1.6.24 also offers a new value for merge, 'first', which + is like 'all' but only takes all from first database that returns + the particular metadata field. + diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index fa06db7..22e047d 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -385,6 +385,8 @@ static int parse_metadata(struct conf_service *service, xmlNode *n, merge = Metadata_merge_range; else if (!strcmp((const char *) xml_merge, "all")) merge = Metadata_merge_all; + else if (!strcmp((const char *) xml_merge, "first")) + merge = Metadata_merge_first; else { yaz_log(YLOG_FATAL, diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index 3487e36..c20bae6 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -41,7 +41,8 @@ enum conf_metadata_merge { Metadata_merge_unique, // Include unique elements in merged block Metadata_merge_longest, // Include the longest (strlen) value Metadata_merge_range, // Store value as a range of lowest-highest - Metadata_merge_all // Just include all elements found + Metadata_merge_all, // Just include all elements found + Metadata_merge_first // All from first target }; enum conf_sortkey_type { diff --git a/src/session.c b/src/session.c index 6071726..ec2f270 100644 --- a/src/session.c +++ b/src/session.c @@ -1781,6 +1781,7 @@ static int ingest_to_cluster(struct client *cl, struct conf_service *service = se->service; int term_factor = 1; struct record_cluster *cluster; + struct record_metadata **metadata0; struct session_database *sdb = client_get_database(cl); struct record *record = record_create(se->nmem, service->num_metadata, @@ -1876,6 +1877,11 @@ static int ingest_to_cluster(struct client *cl, relevance_newrec(se->relevance, cluster); + // original metadata, to check if first existence of a field + metadata0 = xmalloc(sizeof(*metadata0) * service->num_metadata); + memcpy(metadata0, cluster->metadata, + sizeof(*metadata0) * service->num_metadata); + // now parsing XML record and adding data to cluster or record metadata for (n = root->children; n; n = n->next) { @@ -1921,6 +1927,9 @@ static int ingest_to_cluster(struct client *cl, // merged metadata rec_md = record_metadata_init(se->nmem, (const char *) value, ser_md->type, 0); + + // see if the field was not in cluster already (from beginning) + if (!rec_md) continue; @@ -1929,9 +1938,16 @@ static int ingest_to_cluster(struct client *cl, wheretoput = &cluster->metadata[md_field_id]; - // and polulate with data: - // assign cluster or record based on merge action - if (ser_md->merge == Metadata_merge_unique) + if (ser_md->merge == Metadata_merge_first) + { + if (!metadata0[md_field_id]) + { + while (*wheretoput) + wheretoput = &(*wheretoput)->next; + *wheretoput = rec_md; + } + } + else if (ser_md->merge == Metadata_merge_unique) { while (*wheretoput) { @@ -2057,6 +2073,7 @@ static int ingest_to_cluster(struct client *cl, if (value) xmlFree(value); + xfree(metadata0); relevance_donerecord(se->relevance, cluster); se->total_records++; -- 1.7.10.4