1 /* $Id: logic.c,v 1.26 2007-04-27 12:17:04 marc Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 \brief high-level logic; mostly user sessions and settings
31 #include <sys/socket.h>
37 #include <yaz/marcdisp.h>
38 #include <yaz/comstack.h>
39 #include <yaz/tcpip.h>
40 #include <yaz/proto.h>
41 #include <yaz/readconf.h>
42 #include <yaz/pquery.h>
43 #include <yaz/otherinfo.h>
44 #include <yaz/yaz-util.h>
46 #include <yaz/query-charset.h>
47 #include <yaz/querytowrbuf.h>
48 #if YAZ_VERSIONL >= 0x020163
49 #include <yaz/oid_db.h>
58 #include <yaz/timing.h>
61 #include <netinet/in.h>
66 #include "termlists.h"
68 #include "relevance.h"
73 #include "normalize7bit.h"
77 // Note: Some things in this structure will eventually move to configuration
78 struct parameters global_parameters =
99 // Recursively traverse query structure to extract terms.
100 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num)
112 pull_terms(nmem, n->u.p[0], termlist, num);
113 pull_terms(nmem, n->u.p[1], termlist, num);
116 nmem_strsplit(nmem, " ", n->u.t.term, &words, &numwords);
117 for (i = 0; i < numwords; i++)
118 termlist[(*num)++] = words[i];
127 static void add_facet(struct session *s, const char *type, const char *value)
133 for (i = 0; i < s->num_termlists; i++)
134 if (!strcmp(s->termlists[i].name, type))
136 if (i == s->num_termlists)
138 if (i == SESSION_MAX_TERMLISTS)
140 yaz_log(YLOG_FATAL, "Too many termlists");
144 s->termlists[i].name = nmem_strdup(s->nmem, type);
145 s->termlists[i].termlist
146 = termlist_create(s->nmem, s->expected_maxrecs, 15);
147 s->num_termlists = i + 1;
149 termlist_insert(s->termlists[i].termlist, value);
152 xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
154 struct database_retrievalmap *m;
155 struct database *db = sdb->database;
159 // First normalize to XML
164 if (rec->which != Z_External_octet)
166 yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s",
170 buf = (char*) rec->u.octet_aligned->buf;
171 len = rec->u.octet_aligned->len;
172 if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0)
174 yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url);
178 yaz_marc_write_using_libxml2(sdb->yaz_marc, 1);
179 if (yaz_marc_write_xml(sdb->yaz_marc, &res,
180 "http://www.loc.gov/MARC21/slim", 0, 0) < 0)
182 yaz_log(YLOG_WARN, "Failed to encode as XML %s",
186 rdoc = xmlNewDoc((xmlChar *) "1.0");
187 xmlDocSetRootElement(rdoc, res);
193 "Unknown native_syntax in normalize_record from %s",
198 if (global_parameters.dump_records){
200 "Input Record (normalized) from %s\n----------------\n",
202 #if LIBXML_VERSION >= 20600
203 xmlDocFormatDump(stderr, rdoc, 1);
205 xmlDocDump(stderr, rdoc);
209 for (m = sdb->map; m; m = m->next){
215 new = xsltApplyStylesheet(m->stylesheet, rdoc, 0);
216 root= xmlDocGetRootElement(new);
217 if (!new || !root || !(root->children))
219 yaz_log(YLOG_WARN, "XSLT transformation failed from %s",
227 // do it another way to detect transformation errors right now
228 // but does not seem to work either!
230 xsltTransformContextPtr ctxt;
231 ctxt = xsltNewTransformContext(m->stylesheet, rdoc);
232 new = xsltApplyStylesheetUser(m->stylesheet, rdoc, 0, 0, 0, ctxt);
233 if ((ctxt->state == XSLT_STATE_ERROR) ||
234 (ctxt->state == XSLT_STATE_STOPPED)){
235 yaz_log(YLOG_WARN, "XSLT transformation failed from %s",
236 cl->database->database->url);
247 if (global_parameters.dump_records)
249 fprintf(stderr, "Record from %s\n----------------\n",
251 #if LIBXML_VERSION >= 20600
252 xmlDocFormatDump(stderr, rdoc, 1);
254 xmlDocDump(stderr, rdoc);
260 // Retrieve first defined value for 'name' for given database.
261 // Will be extended to take into account user associated with session
262 char *session_setting_oneval(struct session_database *db, int offset)
264 if (!db->settings[offset])
266 return db->settings[offset]->value;
271 // Initialize YAZ Map structures for MARC-based targets
272 static int prepare_yazmarc(struct session_database *sdb)
278 yaz_log(YLOG_WARN, "No settings for %s", sdb->database->url);
281 if ((s = session_setting_oneval(sdb, PZ_NATIVESYNTAX))
282 && !strncmp(s, "iso2709", 7))
284 char *encoding = "marc-8s", *e;
287 // See if a native encoding is specified
288 if ((e = strchr(s, ';')))
291 sdb->yaz_marc = yaz_marc_create();
292 yaz_marc_subfield_str(sdb->yaz_marc, "\t");
294 cm = yaz_iconv_open("utf-8", encoding);
298 "Unable to map from %s to UTF-8 for target %s",
299 encoding, sdb->database->url);
302 yaz_marc_iconv(sdb->yaz_marc, cm);
307 // Prepare XSLT stylesheets for record normalization
308 // Structures are allocated on the session_wide nmem to avoid having
309 // to recompute this for every search. This would lead
310 // to leaking if a single session was to repeatedly change the PZ_XSLT
311 // setting. However, this is not a realistic use scenario.
312 static int prepare_map(struct session *se, struct session_database *sdb)
318 yaz_log(YLOG_WARN, "No settings on %s", sdb->database->url);
321 if ((s = session_setting_oneval(sdb, PZ_XSLT)))
324 struct database_retrievalmap **m = &sdb->map;
327 nmem_strsplit(se->session_nmem, ",", s, &stylesheets, &num);
328 for (i = 0; i < num; i++)
330 (*m) = nmem_malloc(se->session_nmem, sizeof(**m));
332 if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i])))
334 yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s",
342 yaz_log(YLOG_WARN, "No Normalization stylesheet for target %s",
347 // This analyzes settings and recomputes any supporting data structures
349 static int prepare_session_database(struct session *se,
350 struct session_database *sdb)
355 "No settings associated with %s", sdb->database->url);
358 if (sdb->settings[PZ_NATIVESYNTAX] && !sdb->yaz_marc)
360 if (prepare_yazmarc(sdb) < 0)
363 if (sdb->settings[PZ_XSLT] && !sdb->map)
365 if (prepare_map(se, sdb) < 0)
372 void session_set_watch(struct session *s, int what,
373 session_watchfun fun, void *data)
375 s->watchlist[what].fun = fun;
376 s->watchlist[what].data = data;
379 void session_alert_watch(struct session *s, int what)
381 if (!s->watchlist[what].fun)
383 (*s->watchlist[what].fun)(s->watchlist[what].data);
384 s->watchlist[what].fun = 0;
385 s->watchlist[what].data = 0;
388 //callback for grep_databases
389 static void select_targets_callback(void *context, struct session_database *db)
391 struct session *se = (struct session*) context;
392 struct client *cl = client_create();
393 client_set_database(cl, db);
394 client_set_session(cl, se);
397 // Associates a set of clients with a session;
398 // Note: Session-databases represent databases with per-session
400 int select_targets(struct session *se, struct database_criterion *crit)
403 client_destroy(se->clients);
405 return session_grep_databases(se, crit, select_targets_callback);
408 int session_active_clients(struct session *s)
413 for (c = s->clients; c; c = client_next_in_session(c))
414 if (client_is_active(c))
420 // parses crit1=val1,crit2=val2|val3,...
421 static struct database_criterion *parse_filter(NMEM m, const char *buf)
423 struct database_criterion *res = 0;
430 nmem_strsplit(m, ",", buf, &values, &num);
431 for (i = 0; i < num; i++)
436 struct database_criterion *new = nmem_malloc(m, sizeof(*new));
437 char *eq = strchr(values[i], '=');
440 yaz_log(YLOG_WARN, "Missing equal-sign in filter");
444 new->name = values[i];
445 nmem_strsplit(m, "|", eq, &subvalues, &subnum);
447 for (subi = 0; subi < subnum; subi++)
449 struct database_criterion_value *newv
450 = nmem_malloc(m, sizeof(*newv));
451 newv->value = subvalues[subi];
452 newv->next = new->values;
461 char *search(struct session *se, char *query, char *filter)
463 int live_channels = 0;
465 struct database_criterion *criteria;
467 yaz_log(YLOG_DEBUG, "Search");
469 nmem_reset(se->nmem);
470 criteria = parse_filter(se->nmem, filter);
472 live_channels = select_targets(se, criteria);
475 int maxrecs = live_channels * global_parameters.toget;
476 se->num_termlists = 0;
477 se->reclist = reclist_create(se->nmem, maxrecs);
478 // This will be initialized in send_search()
479 se->total_records = se->total_hits = se->total_merged = 0;
480 se->expected_maxrecs = maxrecs;
487 for (cl = se->clients; cl; cl = client_next_in_session(cl))
489 if (prepare_session_database(se, client_get_database(cl)) < 0)
490 return "CONFIG_ERROR";
491 // Query must parse for all targets
492 if (client_parse_query(cl, query) < 0)
496 for (cl = se->clients; cl; cl = client_next_in_session(cl))
498 client_prep_connection(cl);
504 // Creates a new session_database object for a database
505 static void session_init_databases_fun(void *context, struct database *db)
507 struct session *se = (struct session *) context;
508 struct session_database *new = nmem_malloc(se->session_nmem, sizeof(*new));
509 int num = settings_num();
516 = nmem_malloc(se->session_nmem, sizeof(struct settings *) * num);
517 memset(new->settings, 0, sizeof(struct settings*) * num);
521 for (i = 0; i < num; i++)
522 new->settings[i] = db->settings[i];
524 new->next = se->databases;
528 // Doesn't free memory associated with sdb -- nmem takes care of that
529 static void session_database_destroy(struct session_database *sdb)
531 struct database_retrievalmap *m;
533 for (m = sdb->map; m; m = m->next)
534 xsltFreeStylesheet(m->stylesheet);
536 yaz_marc_destroy(sdb->yaz_marc);
539 // Initialize session_database list -- this represents this session's view
540 // of the database list -- subject to modification by the settings ws command
541 void session_init_databases(struct session *se)
544 grep_databases(se, 0, session_init_databases_fun);
547 // Probably session_init_databases_fun should be refactored instead of
549 static struct session_database *load_session_database(struct session *se,
552 struct database *db = find_database(id, 0);
554 session_init_databases_fun((void*) se, db);
555 // New sdb is head of se->databases list
556 return se->databases;
559 // Find an existing session database. If not found, load it
560 static struct session_database *find_session_database(struct session *se,
563 struct session_database *sdb;
565 for (sdb = se->databases; sdb; sdb = sdb->next)
566 if (!strcmp(sdb->database->url, id))
568 return load_session_database(se, id);
571 // Apply a session override to a database
572 void session_apply_setting(struct session *se, char *dbname, char *setting,
575 struct session_database *sdb = find_session_database(se, dbname);
576 struct setting *new = nmem_malloc(se->session_nmem, sizeof(*new));
577 int offset = settings_offset(setting);
581 yaz_log(YLOG_WARN, "Unknown setting %s", setting);
585 new->target = dbname;
588 new->next = sdb->settings[offset];
589 sdb->settings[offset] = new;
591 // Force later recompute of settings-driven data structures
592 // (happens when a search starts and client connections are prepared)
595 case PZ_NATIVESYNTAX:
598 yaz_marc_destroy(sdb->yaz_marc);
605 struct database_retrievalmap *m;
606 // We don't worry about the map structure -- it's in nmem
607 for (m = sdb->map; m; m = m->next)
608 xsltFreeStylesheet(m->stylesheet);
615 void destroy_session(struct session *s)
617 struct session_database *sdb;
619 yaz_log(YLOG_LOG, "Destroying session");
621 client_destroy(s->clients);
622 for (sdb = s->databases; sdb; sdb = sdb->next)
623 session_database_destroy(sdb);
624 nmem_destroy(s->nmem);
625 wrbuf_destroy(s->wrbuf);
628 struct session *new_session(NMEM nmem)
631 struct session *session = nmem_malloc(nmem, sizeof(*session));
633 yaz_log(YLOG_DEBUG, "New Pazpar2 session");
635 session->total_hits = 0;
636 session->total_records = 0;
637 session->num_termlists = 0;
638 session->reclist = 0;
639 session->requestid = -1;
640 session->clients = 0;
641 session->expected_maxrecs = 0;
642 session->session_nmem = nmem;
643 session->nmem = nmem_create();
644 session->wrbuf = wrbuf_alloc();
645 session_init_databases(session);
646 for (i = 0; i <= SESSION_WATCH_MAX; i++)
648 session->watchlist[i].data = 0;
649 session->watchlist[i].fun = 0;
655 struct hitsbytarget *hitsbytarget(struct session *se, int *count)
657 static struct hitsbytarget res[1000]; // FIXME MM
661 for (cl = se->clients; cl; cl = client_next_in_session(cl))
663 char *name = session_setting_oneval(client_get_database(cl), PZ_NAME);
665 res[*count].id = client_get_database(cl)->database->url;
666 res[*count].name = *name ? name : "Unknown";
667 res[*count].hits = client_get_hits(cl);
668 res[*count].records = client_get_num_records(cl);
669 res[*count].diagnostic = client_get_diagnostic(cl);
670 res[*count].state = client_get_state_str(cl);
671 res[*count].connected = client_get_connection(cl) ? 1 : 0;
678 struct termlist_score **termlist(struct session *s, const char *name, int *num)
682 for (i = 0; i < s->num_termlists; i++)
683 if (!strcmp((const char *) s->termlists[i].name, name))
684 return termlist_highscore(s->termlists[i].termlist, num);
688 #ifdef MISSING_HEADERS
689 void report_nmem_stats(void)
691 size_t in_use, is_free;
693 nmem_get_memory_in_use(&in_use);
694 nmem_get_memory_free(&is_free);
696 yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld",
697 (long) in_use, (long) is_free);
701 struct record_cluster *show_single(struct session *s, int id)
703 struct record_cluster *r;
705 reclist_rewind(s->reclist);
706 while ((r = reclist_read_record(s->reclist)))
712 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp,
713 int start, int *num, int *total, int *sumhits,
716 struct record_cluster **recs = nmem_malloc(nmem_show, *num
717 * sizeof(struct record_cluster *));
718 struct reclist_sortparms *spp;
721 yaz_timing_t t = yaz_timing_create();
724 for (spp = sp; spp; spp = spp->next)
725 if (spp->type == Metadata_sortkey_relevance)
727 relevance_prepare_read(s->relevance, s->reclist);
730 reclist_sort(s->reclist, sp);
732 *total = s->reclist->num_records;
733 *sumhits = s->total_hits;
735 for (i = 0; i < start; i++)
736 if (!reclist_read_record(s->reclist))
743 for (i = 0; i < *num; i++)
745 struct record_cluster *r = reclist_read_record(s->reclist);
755 yaz_log(YLOG_LOG, "show %6.5f %3.2f %3.2f",
756 yaz_timing_get_real(t), yaz_timing_get_user(t),
757 yaz_timing_get_sys(t));
758 yaz_timing_destroy(&t);
763 void statistics(struct session *se, struct statistics *stat)
768 memset(stat, 0, sizeof(*stat));
769 for (cl = se->clients; cl; cl = client_next_in_session(cl))
771 if (!client_get_connection(cl))
772 stat->num_no_connection++;
773 switch (client_get_state(cl))
775 case Client_Connecting: stat->num_connecting++; break;
776 case Client_Initializing: stat->num_initializing++; break;
777 case Client_Searching: stat->num_searching++; break;
778 case Client_Presenting: stat->num_presenting++; break;
779 case Client_Idle: stat->num_idle++; break;
780 case Client_Failed: stat->num_failed++; break;
781 case Client_Error: stat->num_error++; break;
786 stat->num_hits = se->total_hits;
787 stat->num_records = se->total_records;
789 stat->num_clients = count;
792 void start_http_listener(void)
795 struct conf_server *ser = global_parameters.server;
797 if (*global_parameters.listener_override)
798 strcpy(hp, global_parameters.listener_override);
801 strcpy(hp, ser->host ? ser->host : "");
806 sprintf(hp + strlen(hp), "%d", ser->port);
812 void start_proxy(void)
815 struct conf_server *ser = global_parameters.server;
817 if (*global_parameters.proxy_override)
818 strcpy(hp, global_parameters.proxy_override);
819 else if (ser->proxy_host || ser->proxy_port)
821 strcpy(hp, ser->proxy_host ? ser->proxy_host : "");
826 sprintf(hp + strlen(hp), "%d", ser->proxy_port);
832 http_set_proxyaddr(hp, ser->myurl ? ser->myurl : "");
835 void start_zproxy(void)
837 struct conf_server *ser = global_parameters.server;
839 if (*global_parameters.zproxy_override){
840 yaz_log(YLOG_LOG, "Z39.50 proxy %s",
841 global_parameters.zproxy_override);
845 else if (ser->zproxy_host || ser->zproxy_port)
849 strcpy(hp, ser->zproxy_host ? ser->zproxy_host : "");
850 if (ser->zproxy_port)
857 sprintf(hp + strlen(hp), "%d", ser->zproxy_port);
859 strcpy(global_parameters.zproxy_override, hp);
860 yaz_log(YLOG_LOG, "Z39.50 proxy %s",
861 global_parameters.zproxy_override);
868 // Master list of connections we're handling events to
869 static IOCHAN channel_list = 0;
870 void pazpar2_add_channel(IOCHAN chan)
872 chan->next = channel_list;
876 void pazpar2_event_loop()
878 event_loop(&channel_list);
881 struct record *ingest_record(struct client *cl, Z_External *rec,
884 xmlDoc *xdoc = normalize_record(client_get_database(cl), rec);
886 struct record *record;
887 struct record_cluster *cluster;
888 struct session *se = client_get_session(cl);
889 xmlChar *mergekey, *mergekey_norm;
892 struct conf_service *service = global_parameters.server->service;
897 root = xmlDocGetRootElement(xdoc);
898 if (!(mergekey = xmlGetProp(root, (xmlChar *) "mergekey")))
900 yaz_log(YLOG_WARN, "No mergekey found in record");
906 record = nmem_malloc(se->nmem, sizeof(struct record));
909 record->metadata = nmem_malloc(se->nmem,
910 sizeof(struct record_metadata*) * service->num_metadata);
911 memset(record->metadata, 0,
912 sizeof(struct record_metadata*) * service->num_metadata);
915 record = record_create(se->nmem,
916 service->num_metadata, service->num_sortkeys);
917 record_assign_client(record, cl);
920 mergekey_norm = (xmlChar *) nmem_strdup(se->nmem, (char*) mergekey);
922 normalize7bit_mergekey((char *) mergekey_norm, 0);
924 cluster = reclist_insert(se->reclist,
925 global_parameters.server->service,
926 record, (char *) mergekey_norm,
928 if (global_parameters.dump_records)
929 yaz_log(YLOG_LOG, "Cluster id %d from %s (#%d)", cluster->recid,
930 client_get_database(cl)->database->url, record_no);
933 /* no room for record */
937 relevance_newrec(se->relevance, cluster);
940 // now parsing XML record and adding data to cluster or record metadata
941 for (n = root->children; n; n = n->next)
949 if (n->type != XML_ELEMENT_NODE)
951 if (!strcmp((const char *) n->name, "metadata"))
953 struct conf_metadata *ser_md = 0;
954 struct conf_sortkey *ser_sk = 0;
955 struct record_metadata **wheretoput = 0;
956 struct record_metadata *rec_md = 0;
957 int md_field_id = -1;
958 int sk_field_id = -1;
961 type = xmlGetProp(n, (xmlChar *) "type");
962 value = xmlNodeListGetString(xdoc, n->children, 0);
968 // First, find out what field we're looking at
969 for (md_field_id = 0; md_field_id < service->num_metadata;
971 if (!strcmp((const char *) type,
972 service->metadata[md_field_id].name))
974 ser_md = &service->metadata[md_field_id];
975 if (ser_md->sortkey_offset >= 0){
976 sk_field_id = ser_md->sortkey_offset;
977 ser_sk = &service->sortkeys[sk_field_id];
985 "Ignoring unknown metadata element: %s", type);
991 = conf_service_metadata_field_id(service, (const char *) type);
995 "Ignoring unknown metadata element: %s", type);
999 ser_md = &service->metadata[md_field_id];
1001 if (ser_md->sortkey_offset >= 0){
1002 sk_field_id = ser_md->sortkey_offset;
1003 ser_sk = &service->sortkeys[sk_field_id];
1007 // Find out where we are putting it - based on merge or not
1008 if (ser_md->merge == Metadata_merge_no)
1009 wheretoput = &record->metadata[md_field_id];
1011 wheretoput = &cluster->metadata[md_field_id];
1013 // create new record_metadata
1015 rec_md = nmem_malloc(se->nmem, sizeof(struct record_metadata));
1018 rec_md = record_metadata_create(se->nmem);
1021 // and polulate with data:
1022 // type based charmapping decisions follow here
1023 if (ser_md->type == Metadata_type_generic)
1028 for (p = (char *) value; *p && isspace(*p); p++)
1030 for (pe = p + strlen(p) - 1;
1031 pe > p && strchr(" ,/.:([", *pe); pe--)
1034 char * p = (char *) value;
1035 p = normalize7bit_generic(p, " ,/.:([");
1038 rec_md->data.text = nmem_strdup(se->nmem, p);
1041 else if (ser_md->type == Metadata_type_year)
1043 if (extract7bit_years((char *) value, &first, &last) < 0)
1049 "Unknown type in metadata element %s", type);
1053 #if 0 // this test does not belong here.
1054 // the condition is enforced in the constructor
1055 // inside conf_metadata_assign()
1056 // and will _never_ occur
1057 if (ser_md->type == Metadata_type_year
1058 && ser_md->merge != Metadata_merge_range)
1060 yaz_log(YLOG_WARN, "Only range merging supported for years");
1066 // and polulate with data:
1067 // assign cluster or record based on merge action
1068 if (ser_md->merge == Metadata_merge_unique)
1070 struct record_metadata *mnode;
1071 for (mnode = *wheretoput; mnode; mnode = mnode->next)
1072 if (!strcmp((const char *) mnode->data.text,
1077 rec_md->next = *wheretoput;
1078 *wheretoput = rec_md;
1081 else if (ser_md->merge == Metadata_merge_longest)
1084 || strlen(rec_md->data.text)
1085 > strlen((*wheretoput)->data.text))
1087 *wheretoput = rec_md;
1090 char *s = nmem_strdup(se->nmem, rec_md->data.text);
1091 if (!cluster->sortkeys[sk_field_id])
1092 cluster->sortkeys[sk_field_id] =
1093 nmem_malloc(se->nmem,
1094 sizeof(union data_types));
1095 normalize7bit_mergekey(s,
1096 (ser_sk->type == Metadata_sortkey_skiparticle));
1097 cluster->sortkeys[sk_field_id]->text = s;
1101 else if (ser_md->merge == Metadata_merge_all
1102 || ser_md->merge == Metadata_merge_no)
1104 rec_md->next = *wheretoput;
1105 *wheretoput = rec_md;
1107 else if (ser_md->merge == Metadata_merge_range)
1110 #if 0 // this assert does not belong here.
1111 // the condition is enforced in the constructor
1112 // inside conf_metadata_assign()
1113 // and will _never_ occur
1114 assert(ser_md->type == Metadata_type_year);
1119 *wheretoput = rec_md;
1120 (*wheretoput)->data.number.min = first;
1121 (*wheretoput)->data.number.max = last;
1123 cluster->sortkeys[sk_field_id]
1128 if (first < (*wheretoput)->data.number.min)
1129 (*wheretoput)->data.number.min = first;
1130 if (last > (*wheretoput)->data.number.max)
1131 (*wheretoput)->data.number.max = last;
1136 union data_types *sdata
1137 = cluster->sortkeys[sk_field_id];
1138 yaz_log(YLOG_LOG, "SK range: %d-%d",
1139 sdata->number.min, sdata->number.max);
1144 #if 0 // this else is only entered when Metadata_merge_no
1145 // but I believe then we should _not_ pollute with log messages
1149 "Don't know how to merge on element name %s",
1154 // ranking of _all_ fields enabled ...
1156 relevance_countwords(se->relevance, cluster,
1157 (char *) value, ser_md->rank);
1159 // construct facets ...
1160 if (ser_md->termlist)
1162 if (ser_md->type == Metadata_type_year)
1165 sprintf(year, "%d", last);
1166 add_facet(se, (char *) type, year);
1169 sprintf(year, "%d", first);
1170 add_facet(se, (char *) type, year);
1174 add_facet(se, (char *) type, (char *) value);
1184 "Unexpected element %s in internal record", n->name);
1193 relevance_donerecord(se->relevance, cluster);
1194 se->total_records++;
1204 * indent-tabs-mode: nil
1206 * vim: shiftwidth=4 tabstop=8 expandtab