-/* $Id: config.c,v 1.24 2007-04-11 11:01:45 marc Exp $
+/* $Id: config.c,v 1.25 2007-04-19 11:57:53 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: config.c,v 1.24 2007-04-11 11:01:45 marc Exp $ */
+/* $Id: config.c,v 1.25 2007-04-19 11:57:53 marc Exp $ */
#include <string.h>
struct conf_config *config = 0;
+struct conf_service * conf_service_create(NMEM nmem)
+{
+ struct conf_service * service
+ = nmem_malloc(nmem, sizeof(struct conf_service));
+ service->num_metadata = 0;
+ service->metadata = 0;
+ service->num_sortkeys = 0;
+ service->sortkeys = 0;
+ return service;
+}
+
+
+struct conf_metadata * conf_metadata_create(NMEM nmem,
+ const char *name,
+ enum conf_metadata_type type,
+ enum conf_metadata_merge merge,
+ int brief,
+ int termlist,
+ int rank,
+ int sortkey_offset)
+{
+
+ struct conf_metadata * metadata
+ = nmem_malloc(nmem, sizeof(struct conf_metadata));
+
+ metadata->name = nmem_strdup(nmem, name);
+ metadata->type = type;
+ metadata->merge = merge;
+ metadata->brief = brief;
+ metadata->termlist = termlist;
+ metadata->rank = rank;
+ metadata->sortkey_offset = sortkey_offset;
+ return metadata;
+}
+
+struct conf_metadata* conf_service_add_metadata(NMEM nmem,
+ struct conf_service *service,
+ const char *name,
+ enum conf_metadata_type type,
+ enum conf_metadata_merge merge,
+ int brief,
+ int termlist,
+ int rank,
+ int sortkey_offset)
+{
+ struct conf_metadata * m = 0;
+
+ if (!service)
+ return m;
+
+ m = conf_metadata_create(nmem, name, type, merge,
+ brief, termlist, rank, sortkey_offset);
+
+ // Not finished, checked temporarily in for file move // if (m)
+
+ return m;
+}
+
+
+
+
/* Code to parse configuration file */
/* ==================================================== */
-/* $Id: config.h,v 1.17 2007-04-18 15:09:51 marc Exp $
+/* $Id: config.h,v 1.18 2007-04-19 11:57:53 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
Metadata_sortkey_string // Flat string
};
+enum conf_metadata_type
+ {
+ Metadata_type_generic, // Generic text field
+ Metadata_type_number, // A number
+ Metadata_type_year // A number
+ };
+
+enum conf_metadata_merge
+ {
+ Metadata_merge_no, // Don't 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
+ };
+
+
// Describes known metadata elements and how they are to be manipulated
// An array of these structure provides a 'map' against which
// discovered metadata elements are matched. It also governs storage,
// values >1 give additional significance to a field
int sortkey_offset; // -1 if it's not a sortkey, otherwise index
// into service/record_cluster->sortkey array
- enum
- {
- Metadata_type_generic, // Generic text field
- Metadata_type_number, // A number
- Metadata_type_year // A number
- } type;
- enum
- {
- Metadata_merge_no, // Don't 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
- } merge;
+ enum conf_metadata_type type;
+ enum conf_metadata_merge merge;
};
+
+struct conf_metadata * conf_metadata_create(NMEM nmem,
+ const char *name,
+ enum conf_metadata_type type,
+ enum conf_metadata_merge merge,
+ int brief,
+ int termlist,
+ int rank,
+ int sortkey_offset);
+
+
// Controls sorting
struct conf_sortkey
{
struct conf_sortkey *sortkeys;
};
+struct conf_service * conf_service_create(NMEM nmem);
+
+struct conf_metadata* conf_service_add_metadata(NMEM nmem,
+ struct conf_service *service,
+ const char *name,
+ enum conf_metadata_type type,
+ enum conf_metadata_merge merge,
+ int brief,
+ int termlist,
+ int rank,
+ int sortkey_offset);
+
+
struct conf_server
{
char *host;
-/* $Id: test_relevance.c,v 1.2 2007-04-17 13:30:24 marc Exp $
+/* $Id: test_relevance.c,v 1.3 2007-04-19 11:57:53 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
// {"ål", "økologi", "æble", 0};
struct record_cluster *cluster = 0;
- struct conf_service service;
+ struct conf_service *service = 0;
struct reclist *list = 0;
struct record *record = 0;
const char *mergekey = "amergekey";
rel = relevance_create(nmem, queryterms, numrecs);
list = reclist_create(nmem, numrecs);
+
+ service = conf_service_create(nmem);
// setting up service - sic!
// this should have been done by a nice service_create function !!!
- service.num_metadata = 1;
- service.metadata = 0;
- service.num_sortkeys = 0;
- service.sortkeys = 0;
- if (service.num_metadata)
- service.metadata
+ //service->num_metadata = 1;
+ //service->metadata = 0;
+ //service->num_sortkeys = 0;
+ //service->sortkeys = 0;
+
+
+ //if (service->num_metadata)
+ // service->metadata
+ // = nmem_malloc(nmem,
+ // sizeof(struct conf_metadata) * service->num_metadata);
+ //else
+ // service->metadata = 0;
+ //service->metadata->name = nmem_strdup(nmem, "aname");
+ //service->metadata->brief = 1;
+ //service->metadata->termlist = 1;
+ //service->metadata->rank = 1;
+ //service->metadata->type = Metadata_type_generic;
+ //service->metadata->type = Metadata_type_year;
+ //service->metadata->merge = Metadata_merge_no;
+ //service->metadata->merge = Metadata_merge_unique;
+ //service->metadata->merge = Metadata_merge_longest;
+ //service->metadata->merge = Metadata_merge_range;
+ //service->metadata->merge = Metadata_merge_all;
+
+ service->metadata
+ = conf_metadata_create(nmem, "name",
+ Metadata_type_generic, Metadata_merge_unique,
+ 1, 1, 1, 0);
+ service->num_metadata = 1;
+
+ conf_service_add_metadata(nmem, service, "name",
+ Metadata_type_generic, Metadata_merge_unique,
+ 1, 1, 1, 0);
+
+
+ if (service->num_sortkeys)
+ service->sortkeys
= nmem_malloc(nmem,
- sizeof(struct conf_metadata) * service.num_metadata);
+ sizeof(struct conf_sortkey) * service->num_sortkeys);
else
- service.metadata = 0;
- service.metadata->name = nmem_strdup(nmem, "aname");
- //service.metadata->brief = 1;
- //service.metadata->termlist = 1;
- //service.metadata->rank = 1;
- //service.metadata->type = Metadata_type_generic;
- //service.metadata->type = Metadata_type_year;
- //service.metadata->merge = Metadata_merge_no;
- //service.metadata->merge = Metadata_merge_unique;
- //service.metadata->merge = Metadata_merge_longest;
- //service.metadata->merge = Metadata_merge_range;
- //service.metadata->merge = Metadata_merge_all;
-
-
- if (service.num_sortkeys)
- service.sortkeys
- = nmem_malloc(nmem,
- sizeof(struct conf_sortkey) * service.num_sortkeys);
- else
- service.sortkeys = 0;
- // service.sortkeys.type = Metadata_sortkey_numeric;
- // service.sortkeys.type = Metadata_sortkey_skiparticle;
- // service.sortkeys.name = service.metadata->name;
- //service.metadata->sortkey_offset = sk_node;
+ service->sortkeys = 0;
+ // service->sortkeys.type = Metadata_sortkey_numeric;
+ // service->sortkeys.type = Metadata_sortkey_skiparticle;
+ // service->sortkeys.name = service->metadata->name;
+ //service->metadata->sortkey_offset = sk_node;
record->sortkeys = 0;
record->metadata
= nmem_malloc(nmem,
- sizeof(struct record_metadata*) * service.num_metadata);
+ sizeof(struct record_metadata*) * service->num_metadata);
memset(record->metadata, 0,
- sizeof(struct record_metadata*) * service.num_metadata);
+ sizeof(struct record_metadata*) * service->num_metadata);
// now we need to put some actual data into the record ... how ??
// insert one record into recordlist/cluster - what's a cluster, exactly??
- cluster = reclist_insert(list, &service, record, (char *)mergekey, &total);
+ cluster = reclist_insert(list, service, record, (char *)mergekey, &total);
relevance_newrec(rel, cluster);
//relevance_donerecord(rel, cluster);
// relevance_countwords(se->rel, cluster,
- // (char *) value, service.metadata->rank);
+ // (char *) value, service->metadata->rank);
//