From: Marc Cromme Date: Thu, 19 Apr 2007 11:57:53 +0000 (+0000) Subject: started adding conf_service and conf-metadata constructors. not finished yet, just... X-Git-Tag: PAZPAR2.1.0.0~261 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=a8cb71c26ffe686497f563a38c7939c3e675bc89;p=pazpar2-moved-to-github.git started adding conf_service and conf-metadata constructors. not finished yet, just checked in for file moving. Do not use yet --- diff --git a/src/config.c b/src/config.c index eec1bc8..b09d47f 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $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. @@ -19,7 +19,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 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 @@ -44,6 +44,67 @@ static char confdir[256] = "."; 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 */ /* ==================================================== */ diff --git a/src/config.h b/src/config.h index a84b7de..33014df 100644 --- a/src/config.h +++ b/src/config.h @@ -1,4 +1,4 @@ -/* $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. @@ -34,6 +34,23 @@ enum conf_sortkey_type 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, @@ -48,22 +65,21 @@ struct conf_metadata // 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 { @@ -83,6 +99,19 @@ struct conf_service 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; diff --git a/src/test_relevance.c b/src/test_relevance.c index e9c5b1a..af391bf 100644 --- a/src/test_relevance.c +++ b/src/test_relevance.c @@ -1,4 +1,4 @@ -/* $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. @@ -62,7 +62,7 @@ void test_relevance(int argc, char **argv) // {"å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"; @@ -72,43 +72,57 @@ void test_relevance(int argc, char **argv) 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; @@ -124,9 +138,9 @@ void test_relevance(int argc, char **argv) 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 ?? @@ -255,7 +269,7 @@ void test_relevance(int argc, char **argv) // 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); @@ -271,7 +285,7 @@ void test_relevance(int argc, char **argv) //relevance_donerecord(rel, cluster); // relevance_countwords(se->rel, cluster, - // (char *) value, service.metadata->rank); + // (char *) value, service->metadata->rank); //