-# $Id: Makefile.am,v 1.8 2007-04-16 13:58:20 marc Exp $
+# $Id: Makefile.am,v 1.9 2007-04-19 19:42:30 marc Exp $
bin_PROGRAMS = pazpar2
-check_PROGRAMS = test_relevance
+check_PROGRAMS = test_config test_relevance
TESTS = $(check_PROGRAMS)
noinst_LIBRARIES = libpazpar2.a
pazpar2_SOURCES = pazpar2.c
pazpar2_LDADD = libpazpar2.a $(YAZLIB)
+test_config_SOURCES = test_config.c
+test_config_LDADD = libpazpar2.a $(YAZLIB)
+
test_relevance_SOURCES = test_relevance.c
test_relevance_LDADD = libpazpar2.a $(YAZLIB)
+
-/* $Id: config.c,v 1.25 2007-04-19 11:57:53 marc Exp $
+/* $Id: config.c,v 1.26 2007-04-19 19:42:30 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: config.c,v 1.25 2007-04-19 11:57:53 marc Exp $ */
+/* $Id: config.c,v 1.26 2007-04-19 19:42:30 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,
+struct conf_metadata * conf_metadata_assign(NMEM nmem,
+ struct conf_metadata * metadata,
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
int rank,
int sortkey_offset)
{
-
- struct conf_metadata * metadata
- = nmem_malloc(nmem, sizeof(struct conf_metadata));
-
+ if (!nmem || !metadata || !name)
+ return 0;
+
metadata->name = nmem_strdup(nmem, name);
metadata->type = type;
metadata->merge = merge;
metadata->termlist = termlist;
metadata->rank = rank;
metadata->sortkey_offset = sortkey_offset;
+
return metadata;
}
-struct conf_metadata* conf_service_add_metadata(NMEM nmem,
+
+struct conf_sortkey * conf_sortkey_assign(NMEM nmem,
+ struct conf_sortkey * sortkey,
+ const char *name,
+ enum conf_sortkey_type type)
+{
+ if (!nmem || !sortkey || !name)
+ return 0;
+
+ sortkey->name = nmem_strdup(nmem, name);
+ sortkey->type = type;
+
+ return sortkey;
+}
+
+
+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));
+ service->num_metadata = num_metadata;
+ service->metadata = 0;
+ if (service->num_metadata)
+ service->metadata
+ = nmem_malloc(nmem,
+ sizeof(struct conf_metadata) * service->num_metadata);
+ service->num_sortkeys = num_sortkeys;
+ service->sortkeys = 0;
+ if (service->num_sortkeys)
+ service->sortkeys
+ = nmem_malloc(nmem,
+ sizeof(struct conf_sortkey) * service->num_sortkeys);
+ return service;
+}
+
+struct conf_metadata* conf_service_add_metadata(NMEM nmem,
struct conf_service *service,
+ int position,
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
int rank,
int sortkey_offset)
{
- struct conf_metadata * m = 0;
+ struct conf_metadata * md = 0;
- if (!service)
- return m;
+ if (!service || !service->metadata || !service->num_metadata
+ || position < 0 || !(position < service->num_metadata))
+ return 0;
- m = conf_metadata_create(nmem, name, type, merge,
+ //md = &((service->metadata)[position]);
+ md = service->metadata + position;
+ md = conf_metadata_assign(nmem, md, name, type, merge,
brief, termlist, rank, sortkey_offset);
+ return md;
+}
+
+
+struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
+ struct conf_service *service,
+ int position,
+ const char *name,
+ enum conf_sortkey_type type)
+{
+ struct conf_sortkey * sk = 0;
+
+ if (!service || !service->sortkeys || !service->num_sortkeys
+ || position < 0 || !(position < service->num_sortkeys))
+ return 0;
- // Not finished, checked temporarily in for file move // if (m)
+ //sk = &((service->sortkeys)[position]);
+ sk = service->sortkeys + position;
+ sk = conf_sortkey_assign(nmem, sk, name, type);
- return m;
+ return sk;
}
+
/* Code to parse configuration file */
/* ==================================================== */
-/* $Id: config.h,v 1.18 2007-04-19 11:57:53 marc Exp $
+/* $Id: config.h,v 1.19 2007-04-19 19:42:30 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
-enum conf_sortkey_type
-{
+#include <yaz/nmem.h>
+
+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
+};
+
+enum conf_sortkey_type {
Metadata_sortkey_relevance,
Metadata_sortkey_numeric, // Standard numerical sorting
Metadata_sortkey_skiparticle, // Skip leading article when sorting
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
};
-struct conf_metadata * conf_metadata_create(NMEM nmem,
+
+struct conf_metadata * conf_metadata_assign(NMEM nmem,
+ struct conf_metadata * metadata,
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
int sortkey_offset);
+
// Controls sorting
struct conf_sortkey
{
enum conf_sortkey_type type;
};
+struct conf_sortkey * conf_sortkey_assign(NMEM nmem,
+ struct conf_sortkey * sortkey,
+ const char *name,
+ enum conf_sortkey_type type);
+
+
+
// It is conceivable that there will eventually be several 'services'
// offered from one server, with separate configuration -- possibly
// more than one services associated with the same port. For now,
struct conf_sortkey *sortkeys;
};
-struct conf_service * conf_service_create(NMEM nmem);
+struct conf_service * conf_service_create(NMEM nmem,
+ int num_metadata, int num_sortkeys);
-struct conf_metadata* conf_service_add_metadata(NMEM nmem,
+struct conf_metadata* conf_service_add_metadata(NMEM nmem,
struct conf_service *service,
+ int position,
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
int rank,
int sortkey_offset);
+struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
+ struct conf_service *service,
+ int position,
+ const char *name,
+ enum conf_sortkey_type type);
+
+
struct conf_server
{
--- /dev/null
+/* $Id: test_config.c,v 1.1 2007-04-19 19:42:30 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.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <signal.h>
+#include <ctype.h>
+#include <assert.h>
+
+#if HAVE_CONFIG_H
+#include "cconfig.h"
+#endif
+
+#define USE_TIMING 0
+#if USE_TIMING
+#include <yaz/timing.h>
+#endif
+
+#include <yaz/test.h>
+
+
+//#include "pazpar2.h"
+#include "config.h"
+
+
+
+void test_conf_service(int argc, char **argv)
+{
+ NMEM nmem = nmem_create();
+
+ struct conf_service *service = 0;
+ service = conf_service_create(nmem, 4, 1);
+
+ YAZ_CHECK(service);
+
+ // expected metadata failures
+ YAZ_CHECK(!conf_service_add_metadata(0, service, 0, "dead_nmem",
+ Metadata_type_generic,
+ Metadata_merge_unique,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(!conf_service_add_metadata(nmem, 0, 0, "service_needed",
+ Metadata_type_generic,
+ Metadata_merge_unique,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(!conf_service_add_metadata(nmem, service, -1, "out_of_bounds",
+ Metadata_type_generic,
+ Metadata_merge_unique,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(!conf_service_add_metadata(nmem, service, 4, "out_of_bounds",
+ Metadata_type_generic,
+ Metadata_merge_unique,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(!conf_service_add_metadata(nmem, service, 0, 0, //missing name
+ Metadata_type_generic,
+ Metadata_merge_unique,
+ 1, 1, 1, 0));
+
+ // expected metadata sucesses
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
+ Metadata_type_generic,
+ Metadata_merge_unique,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
+ Metadata_type_generic,
+ Metadata_merge_longest,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
+ Metadata_type_number,
+ Metadata_merge_no,
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
+ Metadata_type_year,
+ Metadata_merge_range,
+ 1, 1, 1, 0));
+
+
+ // expected sortkey failures
+ YAZ_CHECK(!conf_service_add_sortkey(0, service, 0, "dead_nmem",
+ Metadata_sortkey_relevance));
+
+ YAZ_CHECK(!conf_service_add_sortkey(nmem, 0, 0, "service_neeeded",
+ Metadata_sortkey_numeric));
+
+ YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
+ Metadata_sortkey_skiparticle));
+
+ YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
+ Metadata_sortkey_string));
+
+ YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 1, "out_of_bounds",
+ Metadata_sortkey_relevance));
+
+ YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 0, 0, //missing name
+ Metadata_sortkey_relevance));
+
+
+ // expected sortkey sucess
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "title",
+ Metadata_sortkey_relevance));
+
+
+
+
+
+ nmem_destroy(nmem);
+
+ //YAZ_CHECK(0 == 0);
+ //YAZ_CHECK_EQ(0, 1);
+
+}
+
+
+int main(int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ YAZ_CHECK_LOG();
+
+ test_conf_service(argc, argv);
+
+ YAZ_CHECK_TERM;
+}
+
+
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
-/* $Id: test_relevance.c,v 1.3 2007-04-19 11:57:53 marc Exp $
+/* $Id: test_relevance.c,v 1.4 2007-04-19 19:42:30 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
//#include "pazpar2.h"
+#include "config.h"
#include "relevance.h"
-
-
-
-
-
void test_relevance(int argc, char **argv)
{
NMEM nmem = nmem_create();
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
- // = 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_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 = conf_service_create(nmem, 4, 1);
+ conf_service_add_metadata(nmem, service, 0, "title",
+ Metadata_type_generic, Metadata_merge_unique,
+ 1, 1, 1, 0);
+
+ conf_service_add_metadata(nmem, service, 1, "author",
+ Metadata_type_generic, Metadata_merge_longest,
+ 1, 1, 1, 0);
+
+ conf_service_add_metadata(nmem, service, 2, "isbn",
+ Metadata_type_number, Metadata_merge_no,
+ 1, 1, 1, 0);
+
+ conf_service_add_metadata(nmem, service, 3, "year",
+ Metadata_type_year, Metadata_merge_range,
+ 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 ??
+ // why the heck does the record know which client it belongs to ??
+
record = nmem_malloc(nmem, sizeof(struct record));
record->next = 0;
sizeof(struct record_metadata*) * service->num_metadata);
memset(record->metadata, 0,
sizeof(struct record_metadata*) * service->num_metadata);
-
+#endif
// 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()
//normalize_mergekey((char *) mergekey_norm, 0);
+#if 0
// insert one record into recordlist/cluster - what's a cluster, exactly??
cluster = reclist_insert(list, service, record, (char *)mergekey, &total);
-
-
relevance_newrec(rel, cluster);
-
+#endif
nmem_destroy(nmem);
- YAZ_CHECK(0 == 0);
- YAZ_CHECK_EQ(0, 1);
-
+ //YAZ_CHECK(0 == 0);
+ //YAZ_CHECK_EQ(0, 1);
}