Merge remote-tracking branch 'origin/master' into ranking-h
[pazpar2-moved-to-github.git] / src / pazpar2_config.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2013 Index Data
3
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef PAZPAR2_CONFIG_H
21 #define PAZPAR2_CONFIG_H
22
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
25
26 #include "normalize_cache.h"
27 #include <yaz/nmem.h>
28 #include <yaz/mutex.h>
29 #include <yaz/ccl.h>
30 #include "charsets.h"
31 #include "http.h"
32 #include "database.h"
33 #include "host.h"
34
35 enum conf_metadata_type {
36     Metadata_type_generic,    // Generic text field
37     Metadata_type_year,        // A number
38     Metadata_type_date        // A number
39 };
40
41 enum conf_metadata_merge {
42     Metadata_merge_no,        // Don't merge
43     Metadata_merge_unique,    // Include unique elements in merged block
44     Metadata_merge_longest,   // Include the longest (strlen) value
45     Metadata_merge_range,     // Store value as a range of lowest-highest
46     Metadata_merge_all,       // Just include all elements found
47     Metadata_merge_first      // All from first target
48 };
49
50 enum conf_sortkey_type {
51     Metadata_sortkey_relevance,
52     Metadata_sortkey_relevance_h,   // Heikki's ranking
53     Metadata_sortkey_numeric,       // Standard numerical sorting
54     Metadata_sortkey_skiparticle,   // Skip leading article when sorting
55     Metadata_sortkey_string,        // Flat string
56     Metadata_sortkey_position       // Position
57 };
58
59 // This controls the ability to insert 'static' values from settings into retrieval recs
60 enum conf_setting_type {
61     Metadata_setting_no,
62     Metadata_setting_postproc,      // Insert setting value into normalized record
63     Metadata_setting_parameter      // Expose value to normalization stylesheets
64 };
65
66 enum conf_metadata_mergekey {
67     Metadata_mergekey_no,
68     Metadata_mergekey_optional,
69     Metadata_mergekey_required
70 };
71
72 // Describes known metadata elements and how they are to be manipulated
73 // An array of these structure provides a 'map' against which
74 // discovered metadata elements are matched. It also governs storage,
75 // to minimize number of cycles needed at various tages of processing
76 struct conf_metadata
77 {
78     char *name;  // The field name. Output by normalization stylesheet
79     int brief;   // Is this element to be returned in the brief format?
80     int termlist;// Is this field to be treated as a termlist for browsing?
81     const char *rank;
82     int sortkey_offset; // -1 if it's not a sortkey, otherwise index
83                         // into service/record_cluster->sortkey array
84     enum conf_metadata_type type;
85     enum conf_metadata_merge merge;
86     enum conf_setting_type setting; // Value is to be taken from session/db settings?
87     enum conf_metadata_mergekey mergekey;
88     char *facetrule;
89
90     char *limitmap;  // Should be expanded into service-wide default e.g. pz:limitmap:<name>=value setting
91     char *limitcluster;
92 };
93
94
95
96 // Controls sorting
97 struct conf_sortkey
98 {
99     char *name;
100     enum conf_sortkey_type type;
101 };
102
103 struct conf_server;
104
105 // It is conceivable that there will eventually be several 'services'
106 // offered from one server, with separate configuration -- possibly
107 // more than one services associated with the same port. For now,
108 // however, only a single service is possible.
109 struct conf_service
110 {
111     YAZ_MUTEX mutex;
112     int num_metadata;
113     struct conf_metadata *metadata;
114     int num_sortkeys;
115     struct conf_sortkey *sortkeys;
116     struct setting_dictionary *dictionary;
117     struct settings_array *settings;
118     struct conf_service *next;
119     char *id;
120     NMEM nmem;
121     int session_timeout;
122     int z3950_session_timeout;
123     int z3950_operation_timeout;
124     int rank_cluster;
125     int rank_debug;
126     double rank_follow;
127     double rank_lead;
128     int rank_length;
129     char *default_sort;
130
131     int ref_count;
132     /* duplicated from conf_server */
133     pp2_charset_fact_t charsets;
134
135     struct service_xslt *xslt_list;
136
137     CCL_bibset ccl_bibset;
138     struct database *databases;
139     struct conf_server *server;
140     char *xml_node;
141 };
142
143 int conf_service_metadata_field_id(struct conf_service *service, const char * name);
144
145 int conf_service_sortkey_field_id(struct conf_service *service, const char * name);
146
147 struct conf_server
148 {
149     char *host;
150     char *port;
151     char *proxy_host;
152     int proxy_port;
153     char *myurl;
154     char *settings_fname;
155     char *server_id;
156
157     pp2_charset_fact_t charsets;
158
159     struct conf_service *service;
160     struct conf_server *next;
161     struct conf_config *config;
162     http_server_t http_server;
163     iochan_man_t iochan_man;
164     database_hosts_t database_hosts;
165 };
166
167 struct conf_config *config_create(const char *fname, int verbose);
168 void config_destroy(struct conf_config *config);
169 void config_process_events(struct conf_config *config);
170 void info_services(struct conf_server *server, WRBUF w);
171
172 struct conf_service *locate_service(struct conf_server *server,
173                                     const char *service_id);
174
175 struct conf_service *service_create(struct conf_server *server,
176                                     xmlNode *node);
177 void service_incref(struct conf_service *service);
178 void service_destroy(struct conf_service *service);
179
180 int config_start_listeners(struct conf_config *conf,
181                            const char *listener_override,
182                            const char *record_fname);
183
184 void config_stop_listeners(struct conf_config *conf);
185
186 WRBUF conf_get_fname(struct conf_config *config, const char *fname);
187
188 #endif
189
190 /*
191  * Local variables:
192  * c-basic-offset: 4
193  * c-file-style: "Stroustrup"
194  * indent-tabs-mode: nil
195  * End:
196  * vim: shiftwidth=4 tabstop=8 expandtab
197  */
198