Sort by retrieval PAZ-1006
[pazpar2-moved-to-github.git] / src / pazpar2_config.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 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 "normalize_cache.h"
24
25 #include <yaz/nmem.h>
26 #include <yaz/mutex.h>
27 #include <yaz/ccl.h>
28 #include "charsets.h"
29 #include "http.h"
30 #include "database.h"
31 #include "host.h"
32
33 enum conf_metadata_type {
34     Metadata_type_generic,    // Generic text field
35     Metadata_type_year,       // year YYYY - YYYY
36     Metadata_type_date,       // date YYYYMMDD - YYYYMMDD
37     Metadata_type_float,      // float number
38     Metadata_type_skiparticle,
39     Metadata_type_relevance,
40     Metadata_type_position,
41     Metadata_type_retrieval,
42 };
43
44 enum conf_metadata_merge {
45     Metadata_merge_no,        // Don't merge
46     Metadata_merge_unique,    // Include unique elements in merged block
47     Metadata_merge_longest,   // Include the longest (strlen) value
48     Metadata_merge_range,     // Store value as a range of lowest-highest
49     Metadata_merge_all,       // Just include all elements found
50     Metadata_merge_first      // All from first target
51 };
52
53 // This controls the ability to insert 'static' values from settings into retrieval recs
54 enum conf_setting_type {
55     Metadata_setting_no,
56     Metadata_setting_postproc,      // Insert setting value into normalized record
57     Metadata_setting_parameter      // Expose value to normalization stylesheets
58 };
59
60 enum conf_metadata_mergekey {
61     Metadata_mergekey_no,
62     Metadata_mergekey_optional,
63     Metadata_mergekey_required
64 };
65
66 // Describes known metadata elements and how they are to be manipulated
67 // An array of these structure provides a 'map' against which
68 // discovered metadata elements are matched. It also governs storage,
69 // to minimize number of cycles needed at various tages of processing
70 struct conf_metadata
71 {
72     char *name;  // The field name. Output by normalization stylesheet
73     int brief;   // Is this element to be returned in the brief format?
74     int termlist;// Is this field to be treated as a termlist for browsing?
75     const char *rank;
76     int sortkey_offset; // -1 if it's not a sortkey, otherwise index
77                         // into service/record_cluster->sortkey array
78     enum conf_metadata_type type;
79     enum conf_metadata_merge merge;
80     enum conf_setting_type setting; // Value is to be taken from session/db settings?
81     enum conf_metadata_mergekey mergekey;
82     char *facetrule;
83
84     char *limitmap;  // Should be expanded into service-wide default e.g. pz:limitmap:<name>=value setting
85     char *limitcluster;
86     char *icurule;
87 };
88
89
90
91 // Controls sorting
92 struct conf_sortkey
93 {
94     char *name;
95     enum conf_metadata_type type;
96 };
97
98 struct conf_server;
99
100 // It is conceivable that there will eventually be several 'services'
101 // offered from one server, with separate configuration -- possibly
102 // more than one services associated with the same port. For now,
103 // however, only a single service is possible.
104 struct conf_service
105 {
106     YAZ_MUTEX mutex;
107     int num_metadata;
108     struct conf_metadata *metadata;
109     int num_sortkeys;
110     struct conf_sortkey *sortkeys;
111     struct setting_dictionary *dictionary;
112     struct settings_array *settings;
113     struct conf_service *next;
114     char *id;
115     NMEM nmem;
116     int session_timeout;
117     int z3950_session_timeout;
118     int z3950_operation_timeout;
119     int rank_cluster;
120     int rank_debug;
121     double rank_follow;
122     double rank_lead;
123     int rank_length;
124     char *default_sort;
125
126     int ref_count;
127     /* duplicated from conf_server */
128     pp2_charset_fact_t charsets;
129
130     struct service_xslt *xslt_list;
131
132     CCL_bibset ccl_bibset;
133     struct database *databases;
134     struct conf_server *server;
135     char *xml_node;
136 };
137
138 int conf_service_metadata_field_id(struct conf_service *service, const char * name);
139
140 int conf_service_sortkey_field_id(struct conf_service *service, const char * name);
141
142 struct conf_server
143 {
144     char *host;
145     char *port;
146     char *proxy_host;
147     int proxy_port;
148     char *myurl;
149     char *settings_fname;
150     char *server_id;
151
152     pp2_charset_fact_t charsets;
153
154     struct conf_service *service;
155     struct conf_server *next;
156     struct conf_config *config;
157     http_server_t http_server;
158     iochan_man_t iochan_man;
159     database_hosts_t database_hosts;
160 };
161
162 struct conf_config *config_create(const char *fname);
163 void config_destroy(struct conf_config *config);
164 void config_process_events(struct conf_config *config);
165 void info_services(struct conf_server *server, WRBUF w);
166
167 struct conf_service *locate_service(struct conf_server *server,
168                                     const char *service_id);
169
170 struct conf_service *service_create(struct conf_server *server,
171                                     xmlNode *node);
172 void service_incref(struct conf_service *service);
173 void service_destroy(struct conf_service *service);
174
175 int config_start_listeners(struct conf_config *conf,
176                            const char *listener_override,
177                            const char *record_fname);
178
179 void config_stop_listeners(struct conf_config *conf);
180
181 WRBUF conf_get_fname(struct conf_config *config, const char *fname);
182
183 #endif
184
185 /*
186  * Local variables:
187  * c-basic-offset: 4
188  * c-file-style: "Stroustrup"
189  * indent-tabs-mode: nil
190  * End:
191  * vim: shiftwidth=4 tabstop=8 expandtab
192  */
193