-# $Id: Makefile.am,v 1.13 2007-04-21 12:00:54 adam Exp $
+# $Id: Makefile.am,v 1.14 2007-04-23 12:33:00 marc Exp $
bin_PROGRAMS = pazpar2
-check_PROGRAMS = test_config test_relevance test_sel_thread
+check_PROGRAMS = test_config test_record test_relevance test_sel_thread
TESTS = $(check_PROGRAMS)
noinst_LIBRARIES = libpazpar2.a
test_relevance_SOURCES = test_relevance.c
test_relevance_LDADD = libpazpar2.a $(YAZLIB)
+test_record_SOURCES = test_record.c
+test_record_LDADD = libpazpar2.a $(YAZLIB)
+
test_sel_thread_SOURCES = test_sel_thread.c
test_sel_thread_LDADD = libpazpar2.a $(YAZLIB)
-/* $Id: config.c,v 1.29 2007-04-23 08:48:50 marc Exp $
+/* $Id: config.c,v 1.30 2007-04-23 12:33:00 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: config.c,v 1.29 2007-04-23 08:48:50 marc Exp $ */
+/* $Id: config.c,v 1.30 2007-04-23 12:33:00 marc Exp $ */
#include <string.h>
}
-int conf_service_field_id(struct conf_service *service, const char * name)
+int conf_service_metadata_field_id(struct conf_service *service, const char * name)
{
int i = 0;
};
+int conf_service_sortkey_field_id(struct conf_service *service, const char * name)
+{
+ int i = 0;
+
+ if (!service || !service->sortkeys || !service->num_sortkeys)
+ return -1;
+
+ for(i = 0; i < service->num_sortkeys; i++) {
+ if (!strcmp(name, (service->sortkeys[i]).name))
+ return i;
+ }
+
+ return -1;
+};
+
+
/* Code to parse configuration file */
/* ==================================================== */
-/* $Id: config.h,v 1.20 2007-04-23 08:48:50 marc Exp $
+/* $Id: config.h,v 1.21 2007-04-23 12:33:00 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);
+int conf_service_metadata_field_id(struct conf_service *service, const char * name);
+
+int conf_service_sortkey_field_id(struct conf_service *service, const char * name);
struct conf_server
-/* $Id: record.c,v 1.2 2007-04-23 08:48:50 marc Exp $
+/* $Id: record.c,v 1.3 2007-04-23 12:33:00 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: record.c,v 1.2 2007-04-23 08:48:50 marc Exp $ */
+/* $Id: record.c,v 1.3 2007-04-23 12:33:00 marc Exp $ */
#include <string.h>
#include "record.h"
+
+union data_types * data_types_assign(NMEM nmem,
+ union data_types * data1,
+ union data_types data2)
+{
+ // assert(nmem);
+
+ if (!data1){
+ if (!nmem)
+ return 0;
+ else
+ data1 = nmem_malloc(nmem, sizeof(union data_types));
+ }
+
+ *data1 = data2;
+ return data1;
+}
+
+
struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys)
{
struct record * record = 0;
return tmp_rmd;
}
+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);
+}
+
struct record_metadata * record_add_metadata(NMEM nmem,
struct record * record,
if (!record || !record->metadata || !service || !name)
return 0;
- field_id = conf_service_field_id(service, name);
+ field_id = conf_service_metadata_field_id(service, name);
if (-1 == field_id)
return 0;
-struct record_metadata * record_add_metadata_field_id(NMEM nmem,
- struct record * record,
- int field_id,
- union data_types data)
+
+
+
+union data_types * record_assign_sortkey_field_id(NMEM nmem,
+ struct record * record,
+ int field_id,
+ union data_types data)
{
- if (field_id < 0 || !record || !record->metadata)
+ if (field_id < 0 || !record || !record->sortkeys)
return 0;
- return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
-};
+ return data_types_assign(nmem, record->sortkeys[field_id], data);
+}
+
+
+
+union data_types * record_assign_sortkey(NMEM nmem,
+ struct record * record,
+ struct conf_service * service,
+ const char * name,
+ union data_types data)
+{
+ int field_id = 0;
+
+ if (!record || !service || !name)
+ return 0;
+
+ field_id = conf_service_sortkey_field_id(service, name);
+
+ if (!(field_id < service->num_sortkeys))
+ return 0;
+
+ return record_assign_sortkey_field_id(nmem, record, field_id, data);
+}
+
/*
-/* $Id: record.h,v 1.3 2007-04-23 08:48:50 marc Exp $
+/* $Id: record.h,v 1.4 2007-04-23 12:33:00 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
} number;
};
+
+
struct record_metadata {
union data_types data;
// next item of this name
struct record_metadata *next;
};
+union data_types * data_types_assign(NMEM nmem,
+ union data_types * data1,
+ union data_types data2);
+
+
struct record {
struct client *client;
// Array mirrors list of metadata fields in config
union data_types data);
+
+union data_types * record_assign_sortkey_field_id(NMEM nmem,
+ struct record * record,
+ int field_id,
+ union data_types data);
+
+
+union data_types * record_assign_sortkey(NMEM nmem,
+ struct record * record,
+ struct conf_service * service,
+ const char * name,
+ union data_types data);
+
+
+
+
struct record_cluster
{
// Array mirrors list of metadata fields in config
-/* $Id: test_config.c,v 1.1 2007-04-19 19:42:30 marc Exp $
+/* $Id: test_config.c,v 1.2 2007-04-23 12:33:00 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
NMEM nmem = nmem_create();
struct conf_service *service = 0;
- service = conf_service_create(nmem, 4, 1);
+ service = conf_service_create(nmem, 4, 3);
YAZ_CHECK(service);
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",
+ YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 3, "out_of_bounds",
Metadata_sortkey_relevance));
YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 0, 0, //missing name
// expected sortkey sucess
- YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "title",
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
Metadata_sortkey_relevance));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 1, "title",
+ Metadata_sortkey_string));
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 2, "year",
+ Metadata_sortkey_numeric));
+
+
--- /dev/null
+/* $Id: test_record.c,v 1.1 2007-04-23 12:33:00 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"
+#include "record.h"
+//#include "pazpar2.h"
+
+
+void test_record(int argc, char **argv)
+{
+ NMEM nmem = nmem_create();
+
+ struct conf_service *service = 0;
+ struct record *record = 0;
+
+ struct client *client = 0;
+
+ service = conf_service_create(nmem, 4, 3);
+ YAZ_CHECK(service);
+
+ 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));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
+ Metadata_sortkey_relevance));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 1, "title",
+ Metadata_sortkey_string));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 2, "year",
+ Metadata_sortkey_numeric));
+
+
+
+
+ // testing record things
+ record = record_create(nmem, 4, 3);
+ YAZ_CHECK(record);
+
+ // why on earth do we have a client dangeling from the record ??
+ record->client = client;
+
+ char * bla = "blabla";
+ union data_types data_text;
+ data_text.text = bla;
+
+
+ union data_types data_num;
+ data_num.number.min = 2;
+ data_num.number.max = 5;
+
+ struct record_metadata * tmp_md = 0;
+ tmp_md = record_metadata_insert(nmem, &(record->metadata[0]), data_text);
+ YAZ_CHECK(tmp_md);
+ tmp_md = record_metadata_insert(nmem, &tmp_md, data_text);
+ YAZ_CHECK(tmp_md);
+
+ YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data_num));
+ YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data_num));
+
+ YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data_text));
+ YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data_text));
+
+
+ YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 0, data_text));
+ YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 1, data_text));
+ YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 2, data_num));
+
+ YAZ_CHECK(record_assign_sortkey(nmem, record, service, "relevance", data_text));
+ YAZ_CHECK(record_assign_sortkey(nmem, record, service, "title", data_text));
+ YAZ_CHECK(record_assign_sortkey(nmem, record, service, "year", data_num));
+
+
+
+
+ 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_record(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.6 2007-04-23 08:48:50 marc Exp $
+/* $Id: test_relevance.c,v 1.7 2007-04-23 12:33:00 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
rel = relevance_create(nmem, queryterms, numrecs);
+ YAZ_CHECK(rel);
+
list = reclist_create(nmem, numrecs);
+ YAZ_CHECK(list);
+
+ service = conf_service_create(nmem, 4, 3);
+ YAZ_CHECK(service);
- service = conf_service_create(nmem, 4, 1);
- conf_service_add_metadata(nmem, service, 0, "title",
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
Metadata_type_generic, Metadata_merge_unique,
- 1, 1, 1, 0);
+ 1, 1, 1, 0));
- conf_service_add_metadata(nmem, service, 1, "author",
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
Metadata_type_generic, Metadata_merge_longest,
- 1, 1, 1, 0);
+ 1, 1, 1, 0));
- conf_service_add_metadata(nmem, service, 2, "isbn",
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
Metadata_type_number, Metadata_merge_no,
- 1, 1, 1, 0);
+ 1, 1, 1, 0));
- conf_service_add_metadata(nmem, service, 3, "year",
+ YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
Metadata_type_year, Metadata_merge_range,
- 1, 1, 1, 0);
+ 1, 1, 1, 0));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
+ Metadata_sortkey_relevance));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 1, "title",
+ Metadata_sortkey_string));
+
+ YAZ_CHECK(conf_service_add_sortkey(nmem, service, 2, "year",
+ Metadata_sortkey_numeric));
+
+
// testing record things
- record = record_create(nmem, 4, 1);
+ record = record_create(nmem, 4, 3);
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 data_text;
+ data_text.text = bla;
- union data_types data2;
- data.number.min = 2;
- data.number.max = 5;
+ union data_types data_num;
+ data_num.number.min = 2;
+ data_num.number.max = 5;
struct record_metadata * tmp_md = 0;
- tmp_md = record_metadata_insert(nmem, &(record->metadata[0]), data);
+ tmp_md = record_metadata_insert(nmem, &(record->metadata[0]), data_text);
YAZ_CHECK(tmp_md);
- tmp_md = record_metadata_insert(nmem, &tmp_md, data);
+ tmp_md = record_metadata_insert(nmem, &tmp_md, data_text);
YAZ_CHECK(tmp_md);
- 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_field_id(nmem, record, 3, data_num));
+ YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data_num));
+
+ YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data_text));
+ YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data_text));
+
+
+ YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 0, data_text));
+ YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 1, data_text));
+ YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 2, data_num));
+
+ YAZ_CHECK(record_assign_sortkey(nmem, record, service, "relevance", data_text));
+ YAZ_CHECK(record_assign_sortkey(nmem, record, service, "title", data_text));
+ YAZ_CHECK(record_assign_sortkey(nmem, record, service, "year", data_num));
+
+
- 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 ??