From 3670a21abc40afe784b2127c4d831471761747a0 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Fri, 20 Apr 2007 14:37:17 +0000 Subject: [PATCH] started record constructors. still unfnished, but yet only used in test_relevance.c --- src/Makefile.am | 4 +-- src/config.c | 12 ++++--- src/record.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/record.h | 10 +++++- src/test_relevance.c | 55 ++++++++++++++++------------ 5 files changed, 148 insertions(+), 30 deletions(-) create mode 100644 src/record.c diff --git a/src/Makefile.am b/src/Makefile.am index adf0bf5..bf17578 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.11 2007-04-20 13:03:22 marc Exp $ +# $Id: Makefile.am,v 1.12 2007-04-20 14:37:17 marc Exp $ bin_PROGRAMS = pazpar2 check_PROGRAMS = test_config test_relevance test_sel_thread @@ -13,7 +13,7 @@ AM_CFLAGS = $(YAZINC) libpazpar2_a_SOURCES = config.c config.h eventl.c eventl.h \ http.c http_command.c http_command.h http.h \ logic.c pazpar2.h \ - record.h reclists.c reclists.h \ + record.h record.c reclists.c reclists.h \ relevance.c relevance.h termlists.c termlists.h \ util.c util.h zeerex.c zeerex.h database.c database.h \ settings.h settings.c sel_thread.c sel_thread.h diff --git a/src/config.c b/src/config.c index 18da89c..590794c 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.27 2007-04-20 11:00:29 marc Exp $ +/* $Id: config.c,v 1.28 2007-04-20 14:37:17 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.27 2007-04-20 11:00:29 marc Exp $ */ +/* $Id: config.c,v 1.28 2007-04-20 14:37:17 marc Exp $ */ #include @@ -88,8 +88,12 @@ struct conf_sortkey * conf_sortkey_assign(NMEM nmem, struct conf_service * conf_service_create(NMEM nmem, int num_metadata, int num_sortkeys) { - struct conf_service * service - = nmem_malloc(nmem, sizeof(struct conf_service)); + struct conf_service * service = 0; + + //assert(nmem); + + service = nmem_malloc(nmem, sizeof(struct conf_service)); + service->num_metadata = num_metadata; service->metadata = 0; if (service->num_metadata) diff --git a/src/record.c b/src/record.c new file mode 100644 index 0000000..277fd1b --- /dev/null +++ b/src/record.c @@ -0,0 +1,97 @@ +/* $Id: record.c,v 1.1 2007-04-20 14:37:17 marc Exp $ + Copyright (c) 2006-2007, Index Data. + +This file is part of Pazpar2. + +Pazpar2 is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Pazpar2; see the file LICENSE. If not, write to the +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 $ */ + + +#include + +#include +#include + +#if HAVE_CONFIG_H +#include +#endif + +//#define CONFIG_NOEXTERNS +#include "config.h" +#include "record.h" + + +struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys) +{ + struct record * record = 0; + + // assert(nmem); + + record = nmem_malloc(nmem, sizeof(struct record)); + + record->next = 0; + // which client should I use for record->client = cl; ?? + record->client = 0; + + record->metadata + = nmem_malloc(nmem, + sizeof(struct record_metadata*) * num_metadata); + memset(record->metadata, 0, + sizeof(struct record_metadata*) * num_metadata); + + record->sortkeys + = nmem_malloc(nmem, + sizeof(union data_types*) * num_sortkeys); + memset(record->metadata, 0, + sizeof(union data_types*) * num_sortkeys); + + + return record; +} + + +struct record_metadata * record_add_metadata_fieldno(NMEM nmem, + struct record * record, + int fieldno, + union data_types data) +{ + struct record_metadata * rmd = 0; + + if (!record || fieldno < 0 + || !record->metadata || !record->metadata[fieldno] ) + return 0; + + // construct new record_metadata + rmd = nmem_malloc(nmem, sizeof(struct record_metadata)); + rmd->data = data; + rmd->next = 0; + + // still needs to be assigned .. + + return rmd; + +}; + + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/record.h b/src/record.h index 1494285..bbba218 100644 --- a/src/record.h +++ b/src/record.h @@ -1,4 +1,4 @@ -/* $Id: record.h,v 1.1 2007-04-20 13:03:22 marc Exp $ +/* $Id: record.h,v 1.2 2007-04-20 14:37:17 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -47,6 +47,14 @@ struct record { struct record *next; // Next in cluster of merged records }; + +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_cluster { struct record_metadata **metadata; // Array mirrors list of metadata fields in config diff --git a/src/test_relevance.c b/src/test_relevance.c index fc5954d..66258b0 100644 --- a/src/test_relevance.c +++ b/src/test_relevance.c @@ -1,4 +1,4 @@ -/* $Id: test_relevance.c,v 1.4 2007-04-19 19:42:30 marc Exp $ +/* $Id: test_relevance.c,v 1.5 2007-04-20 14:37:17 marc Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -45,7 +45,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA //#include "pazpar2.h" #include "config.h" #include "relevance.h" - +#include "record.h" +#include "pazpar2.h" void test_relevance(int argc, char **argv) @@ -57,14 +58,16 @@ void test_relevance(int argc, char **argv) {"abe", "fisk", 0}; // {"ål", "økologi", "æble", 0}; - struct record_cluster *cluster = 0; + //struct record_cluster *cluster = 0; struct conf_service *service = 0; struct reclist *list = 0; struct record *record = 0; - const char *mergekey = "amergekey"; - int total = 0; + //const char *mergekey = "amergekey"; + //int total = 0; struct relevance *rel = 0; + struct client *client = 0; + rel = relevance_create(nmem, queryterms, numrecs); list = reclist_create(nmem, numrecs); @@ -87,24 +90,30 @@ void test_relevance(int argc, char **argv) 1, 1, 1, 0); -#if 0 - // preparing one record - // this should have been done by a nice record_create function - // why the heck does the record know which client it belongs to ?? - - - record = nmem_malloc(nmem, sizeof(struct record)); - record->next = 0; - // which client should I use for record->client = cl; ?? - record->client = 0; - // and which sortkeys data_types list should I use ?? - record->sortkeys = 0; - record->metadata - = nmem_malloc(nmem, - sizeof(struct record_metadata*) * service->num_metadata); - memset(record->metadata, 0, - sizeof(struct record_metadata*) * service->num_metadata); -#endif + // testing record things + record = record_create(nmem, 4, 1); + YAZ_CHECK(record); + + // why on earth do we have a client dangeling from the record ?? + record->client = client; + + //union data_types data; + //data.text = "sometext"; + + char * bla = "blabla"; + union data_types data; + data.text = bla; + + + union data_types data2; + data.number.min = 2; + data.number.max = 5; + + record_add_metadata_fieldno(nmem, record, 0, data); + record_add_metadata_fieldno(nmem, record, 0, data2); + + //record_add_metadata_text(nmem, record, 0, bla); + // now we need to put some actual data into the record ... how ?? // there is a hell of a lot spagetti code in logic.c ingest_record() -- 1.7.10.4