From a715ede1c0c1e8cb98b65b6ad78b7193222eff05 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Mon, 23 Apr 2007 08:48:50 +0000 Subject: [PATCH] more records constructor work, no yet finished --- src/config.c | 18 ++++++++++++-- src/config.h | 4 +++- src/record.c | 65 +++++++++++++++++++++++++++++++++++++------------- src/record.h | 43 +++++++++++++++++++++++---------- src/test_relevance.c | 15 ++++++++---- 5 files changed, 110 insertions(+), 35 deletions(-) diff --git a/src/config.c b/src/config.c index 590794c..b054335 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.28 2007-04-20 14:37:17 marc Exp $ +/* $Id: config.c,v 1.29 2007-04-23 08:48:50 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: config.c,v 1.28 2007-04-20 14:37:17 marc Exp $ */ +/* $Id: config.c,v 1.29 2007-04-23 08:48:50 marc Exp $ */ #include @@ -154,6 +154,20 @@ struct conf_sortkey * conf_service_add_sortkey(NMEM nmem, } +int conf_service_field_id(struct conf_service *service, const char * name) +{ + int i = 0; + + if (!service || !service->metadata || !service->num_metadata) + return -1; + + for(i = 0; i < service->num_metadata; i++) { + if (!strcmp(name, (service->metadata[i]).name)) + return i; + } + + return -1; +}; diff --git a/src/config.h b/src/config.h index 4e1d1ad..a1a3448 100644 --- a/src/config.h +++ b/src/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.19 2007-04-19 19:42:30 marc Exp $ +/* $Id: config.h,v 1.20 2007-04-23 08:48:50 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -130,6 +130,8 @@ struct conf_sortkey * conf_service_add_sortkey(NMEM nmem, enum conf_sortkey_type type); +int conf_service_field_id(struct conf_service *service, const char * name); + struct conf_server { diff --git a/src/record.c b/src/record.c index 277fd1b..2d83012 100644 --- a/src/record.c +++ b/src/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.1 2007-04-20 14:37:17 marc Exp $ +/* $Id: record.c,v 1.2 2007-04-23 08:48:50 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.1 2007-04-20 14:37:17 marc Exp $ */ +/* $Id: record.c,v 1.2 2007-04-23 08:48:50 marc Exp $ */ #include @@ -65,26 +65,59 @@ struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys) } -struct record_metadata * record_add_metadata_fieldno(NMEM nmem, - struct record * record, - int fieldno, - union data_types data) +struct record_metadata * record_metadata_insert(NMEM nmem, + struct record_metadata ** rmd, + union data_types data) { - struct record_metadata * rmd = 0; - - if (!record || fieldno < 0 - || !record->metadata || !record->metadata[fieldno] ) + struct record_metadata * tmp_rmd = 0; + // assert(nmem); + + if(!rmd) return 0; - // construct new record_metadata - rmd = nmem_malloc(nmem, sizeof(struct record_metadata)); - rmd->data = data; - rmd->next = 0; + // construct new record_metadata + tmp_rmd = nmem_malloc(nmem, sizeof(struct record_metadata)); + tmp_rmd->data = data; + + + // insert in *rmd's place + tmp_rmd->next = *rmd; + *rmd = tmp_rmd; + + return tmp_rmd; +} + + +struct record_metadata * record_add_metadata(NMEM nmem, + struct record * record, + struct conf_service * service, + const char * name, + union data_types data) +{ + int field_id = 0; - // still needs to be assigned .. + if (!record || !record->metadata || !service || !name) + return 0; + + field_id = conf_service_field_id(service, name); - return rmd; + if (-1 == field_id) + return 0; + return record_metadata_insert(nmem, &(record->metadata[field_id]), data); +} + + + +struct record_metadata * record_add_metadata_field_id(NMEM nmem, + struct record * record, + int field_id, + union data_types data) +{ + if (field_id < 0 || !record || !record->metadata) + return 0; + + return record_metadata_insert(nmem, &(record->metadata[field_id]), data); }; diff --git a/src/record.h b/src/record.h index bbba218..9a34467 100644 --- a/src/record.h +++ b/src/record.h @@ -1,4 +1,4 @@ -/* $Id: record.h,v 1.2 2007-04-20 14:37:17 marc Exp $ +/* $Id: record.h,v 1.3 2007-04-23 08:48:50 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -25,7 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA struct record; struct client; - +struct conf_service; union data_types { char *text; @@ -37,32 +37,51 @@ union data_types { struct record_metadata { union data_types data; - struct record_metadata *next; // next item of this name + // next item of this name + struct record_metadata *next; }; struct record { struct client *client; - struct record_metadata **metadata; // Array mirrors list of metadata fields in config - union data_types **sortkeys; // Array mirrors list of sortkey fields in config - struct record *next; // Next in cluster of merged records + // Array mirrors list of metadata fields in config + struct record_metadata **metadata; + // Array mirrors list of sortkey fields in config + union data_types **sortkeys; + // Next in cluster of merged records + struct record *next; }; struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys); -struct record_metadata * record_add_metadata_fieldno(NMEM nmem, - struct record * record, - int fieldno, - union data_types data); +struct record_metadata * record_metadata_insert(NMEM nmem, + struct record_metadata ** rmd, + union data_types data); + + +struct record_metadata * record_add_metadata_field_id(NMEM nmem, + struct record * record, + int field_id, + union data_types data); + + +struct record_metadata * record_add_metadata(NMEM nmem, + struct record * record, + struct conf_service * service, + const char * name, + union data_types data); + struct record_cluster { - struct record_metadata **metadata; // Array mirrors list of metadata fields in config + // Array mirrors list of metadata fields in config + struct record_metadata **metadata; union data_types **sortkeys; char *merge_key; int relevance; int *term_frequency_vec; - int recid; // Set-specific ID for this record + // Set-specific ID for this record + int recid; struct record *records; }; diff --git a/src/test_relevance.c b/src/test_relevance.c index 66258b0..c903ac6 100644 --- a/src/test_relevance.c +++ b/src/test_relevance.c @@ -1,4 +1,4 @@ -/* $Id: test_relevance.c,v 1.5 2007-04-20 14:37:17 marc Exp $ +/* $Id: test_relevance.c,v 1.6 2007-04-23 08:48:50 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -109,10 +109,17 @@ void test_relevance(int argc, char **argv) data.number.min = 2; data.number.max = 5; - record_add_metadata_fieldno(nmem, record, 0, data); - record_add_metadata_fieldno(nmem, record, 0, data2); + struct record_metadata * tmp_md = 0; + tmp_md = record_metadata_insert(nmem, &(record->metadata[0]), data); + YAZ_CHECK(tmp_md); + tmp_md = record_metadata_insert(nmem, &tmp_md, data); + YAZ_CHECK(tmp_md); - //record_add_metadata_text(nmem, record, 0, bla); + YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data2)); + YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data2)); + + YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data)); + YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data)); // now we need to put some actual data into the record ... how ?? -- 1.7.10.4