-/* $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.
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 <string.h>
}
+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;
+};
-/* $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.
enum conf_sortkey_type type);
+int conf_service_field_id(struct conf_service *service, const char * name);
+
struct conf_server
{
-/* $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.
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 <string.h>
}
-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);
};
-/* $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.
struct record;
struct client;
-
+struct conf_service;
union data_types {
char *text;
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;
};
-/* $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.
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 ??