From: Marc Cromme Date: Thu, 26 Apr 2007 11:41:26 +0000 (+0000) Subject: using record creator functions in production code in ingest_record() X-Git-Tag: PAZPAR2.1.0.0~203 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=7767486372ed58a84338f46c94242b942d18e8ba;p=pazpar2-moved-to-github.git using record creator functions in production code in ingest_record() --- diff --git a/src/logic.c b/src/logic.c index 624a474..16e27fe 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.22 2007-04-26 11:03:54 marc Exp $ +/* $Id: logic.c,v 1.23 2007-04-26 11:41:26 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -953,7 +953,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec, { xmlDoc *xdoc = normalize_record(client_get_database(cl), rec); xmlNode *root, *n; - struct record *res; + struct record *record; struct record_cluster *cluster; struct session *se = client_get_session(cl); xmlChar *mergekey, *mergekey_norm; @@ -972,21 +972,28 @@ struct record *ingest_record(struct client *cl, Z_External *rec, return 0; } - res = nmem_malloc(se->nmem, sizeof(struct record)); - res->next = 0; - res->client = cl; - res->metadata = nmem_malloc(se->nmem, +#if 0 + record = nmem_malloc(se->nmem, sizeof(struct record)); + record->next = 0; + record->client = cl; + record->metadata = nmem_malloc(se->nmem, sizeof(struct record_metadata*) * service->num_metadata); - memset(res->metadata, 0, + memset(record->metadata, 0, sizeof(struct record_metadata*) * service->num_metadata); +#else + record = record_create(se->nmem, + service->num_metadata, service->num_sortkeys); + record_assign_client(record, cl); +#endif + mergekey_norm = (xmlChar *) nmem_strdup(se->nmem, (char*) mergekey); xmlFree(mergekey); normalize_mergekey((char *) mergekey_norm, 0); cluster = reclist_insert(se->reclist, global_parameters.server->service, - res, (char *) mergekey_norm, + record, (char *) mergekey_norm, &se->total_merged); if (global_parameters.dump_records) yaz_log(YLOG_LOG, "Cluster id %d from %s (#%d)", cluster->recid, @@ -1024,6 +1031,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec, if (!type || !value) continue; +#if 0 // First, find out what field we're looking at for (md_field_id = 0; md_field_id < service->num_metadata; md_field_id++) @@ -1031,10 +1039,13 @@ struct record *ingest_record(struct client *cl, Z_External *rec, service->metadata[md_field_id].name)) { ser_md = &service->metadata[md_field_id]; - if (ser_md->sortkey_offset >= 0) - ser_sk = &service->sortkeys[ser_md->sortkey_offset]; + if (ser_md->sortkey_offset >= 0){ + sk_field_id = ser_md->sortkey_offset; + ser_sk = &service->sortkeys[sk_field_id]; + } break; } + if (!ser_md) { yaz_log(YLOG_WARN, @@ -1042,9 +1053,27 @@ struct record *ingest_record(struct client *cl, Z_External *rec, continue; } +#else + md_field_id + = conf_service_metadata_field_id(service, (const char *) type); + if (md_field_id < 0) + { + yaz_log(YLOG_WARN, + "Ignoring unknown metadata element: %s", type); + continue; + } + + ser_md = &service->metadata[md_field_id]; + + if (ser_md->sortkey_offset >= 0){ + sk_field_id = ser_md->sortkey_offset; + ser_sk = &service->sortkeys[sk_field_id]; + } +#endif + // Find out where we are putting it if (ser_md->merge == Metadata_merge_no) - wheretoput = &res->metadata[md_field_id]; + wheretoput = &record->metadata[md_field_id]; else wheretoput = &cluster->metadata[md_field_id]; @@ -1102,13 +1131,13 @@ struct record *ingest_record(struct client *cl, Z_External *rec, if (ser_sk) { char *s = nmem_strdup(se->nmem, newm->data.text); - if (!cluster->sortkeys[ser_md->sortkey_offset]) - cluster->sortkeys[ser_md->sortkey_offset] = + if (!cluster->sortkeys[sk_field_id]) + cluster->sortkeys[sk_field_id] = nmem_malloc(se->nmem, sizeof(union data_types)); normalize_mergekey(s, (ser_sk->type == Metadata_sortkey_skiparticle)); - cluster->sortkeys[ser_md->sortkey_offset]->text = s; + cluster->sortkeys[sk_field_id]->text = s; } } } @@ -1127,7 +1156,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec, (*wheretoput)->data.number.min = first; (*wheretoput)->data.number.max = last; if (ser_sk) - cluster->sortkeys[ser_md->sortkey_offset] + cluster->sortkeys[sk_field_id] = &newm->data; } else @@ -1138,10 +1167,10 @@ struct record *ingest_record(struct client *cl, Z_External *rec, (*wheretoput)->data.number.max = last; } #ifdef GAGA - if (sk) + if (ser_sk) { union data_types *sdata - = cluster->sortkeys[md->sortkey_offset]; + = cluster->sortkeys[sk_field_id]; yaz_log(YLOG_LOG, "SK range: %d-%d", sdata->number.min, sdata->number.max); } @@ -1189,7 +1218,7 @@ struct record *ingest_record(struct client *cl, Z_External *rec, relevance_donerecord(se->relevance, cluster); se->total_records++; - return res; + return record; } diff --git a/src/record.c b/src/record.c index 2ad01d2..b767d2d 100644 --- a/src/record.c +++ b/src/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.6 2007-04-24 22:19:19 marc Exp $ +/* $Id: record.c,v 1.7 2007-04-26 11:41:26 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -19,7 +19,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: record.c,v 1.6 2007-04-24 22:19:19 marc Exp $ */ +/* $Id: record.c,v 1.7 2007-04-26 11:41:26 marc Exp $ */ #include @@ -87,6 +87,13 @@ struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys) } +struct client * record_assign_client(struct record * record, + struct client * client) +{ + record->client = client; + return client; +} + struct record_metadata * record_metadata_insert(NMEM nmem, struct record_metadata ** rmd, union data_types data) diff --git a/src/record.h b/src/record.h index 2ef42b2..3984fe0 100644 --- a/src/record.h +++ b/src/record.h @@ -1,4 +1,4 @@ -/* $Id: record.h,v 1.6 2007-04-26 10:19:05 marc Exp $ +/* $Id: record.h,v 1.7 2007-04-26 11:41:26 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -79,6 +79,10 @@ struct record_metadata * record_add_metadata(NMEM nmem, union data_types data); +struct client * record_assign_client(struct record * record, + struct client *client); + + union data_types * record_assign_sortkey_field_id(NMEM nmem, struct record * record,