6f529227a3da48fb37e26fc76f156354b0d7c2b3
[pazpar2-moved-to-github.git] / src / config.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2008 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 CONFIG_H
21 #define CONFIG_H
22
23 #include <libxslt/xslt.h>
24 #include <libxslt/transform.h>
25 #include <libxslt/xsltutils.h>
26
27 #include <yaz/nmem.h>
28 #include "charsets.h"
29
30 enum conf_metadata_type {
31     Metadata_type_generic,    // Generic text field
32     Metadata_type_number,     // A number
33     Metadata_type_year,        // A number
34     Metadata_type_date        // A number
35 };
36
37 enum conf_metadata_merge {
38     Metadata_merge_no,        // Don't merge
39     Metadata_merge_unique,    // Include unique elements in merged block
40     Metadata_merge_longest,   // Include the longest (strlen) value
41     Metadata_merge_range,     // Store value as a range of lowest-highest
42     Metadata_merge_all        // Just include all elements found
43 };
44
45 enum conf_sortkey_type {
46     Metadata_sortkey_relevance,
47     Metadata_sortkey_numeric,       // Standard numerical sorting
48     Metadata_sortkey_skiparticle,   // Skip leading article when sorting
49     Metadata_sortkey_string         // Flat string
50 };
51
52 // This controls the ability to insert 'static' values from settings into retrieval recs
53 enum conf_setting_type {
54     Metadata_setting_no,
55     Metadata_setting_postproc,      // Insert setting value into normalized record
56     Metadata_setting_parameter      // Expose value to normalization stylesheets
57 };
58
59 // Describes known metadata elements and how they are to be manipulated
60 // An array of these structure provides a 'map' against which
61 // discovered metadata elements are matched. It also governs storage,
62 // to minimize number of cycles needed at various tages of processing
63 struct conf_metadata 
64 {
65     char *name;  // The field name. Output by normalization stylesheet
66     int brief;   // Is this element to be returned in the brief format?
67     int termlist;// Is this field to be treated as a termlist for browsing?
68     int rank;    // Rank factor. 0 means don't use this field for ranking, 
69                  // 1 is default
70                  // values >1  give additional significance to a field
71     int sortkey_offset; // -1 if it's not a sortkey, otherwise index
72                         // into service/record_cluster->sortkey array
73     enum conf_metadata_type type;
74     enum conf_metadata_merge merge;
75     enum conf_setting_type setting; // Value is to be taken from session/db settings?
76 };
77
78
79
80 struct conf_metadata * conf_metadata_assign(NMEM nmem, 
81                                             struct conf_metadata * metadata,
82                                             const char *name,
83                                             enum conf_metadata_type type,
84                                             enum conf_metadata_merge merge,
85                                             enum conf_setting_type setting,
86                                             int brief,
87                                             int termlist,
88                                             int rank,
89                                             int sortkey_offset);
90
91
92
93 // Controls sorting
94 struct conf_sortkey
95 {
96     char *name;
97     enum conf_sortkey_type type;
98 };
99
100 struct conf_sortkey * conf_sortkey_assign(NMEM nmem, 
101                                             struct conf_sortkey * sortkey,
102                                             const char *name,
103                                             enum conf_sortkey_type type);
104
105
106
107 // It is conceivable that there will eventually be several 'services'
108 // offered from one server, with separate configuration -- possibly
109 // more than one services associated with the same port. For now,
110 // however, only a single service is possible.
111 struct conf_service
112 {
113     int num_metadata;
114     struct conf_metadata *metadata;
115     int num_sortkeys;
116     struct conf_sortkey *sortkeys;
117
118 };
119
120 struct conf_service * conf_service_create(NMEM nmem, 
121                                           int num_metadata, int num_sortkeys);
122
123
124 struct conf_metadata* conf_service_add_metadata(NMEM nmem, 
125                                                 struct conf_service *service,
126                                                 int field_id,
127                                                 const char *name,
128                                                 enum conf_metadata_type type,
129                                                 enum conf_metadata_merge merge,
130                                                 enum conf_setting_type setting,
131                                                 int brief,
132                                                 int termlist,
133                                                 int rank,
134                                                 int sortkey_offset);
135
136 struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
137                                                struct conf_service *service,
138                                                int field_id,
139                                                const char *name,
140                                                enum conf_sortkey_type type);
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
148 struct conf_server
149 {
150     char *host;
151     int port;
152     char *proxy_host;
153     int proxy_port;
154     char *myurl;
155     char *settings;
156
157     pp2_charset_t relevance_pct;
158     pp2_charset_t sort_pct;
159     pp2_charset_t mergekey_pct;
160
161     struct conf_service *service;
162     struct conf_server *next;
163 };
164
165 struct conf_targetprofiles
166 {
167     enum {
168         Targetprofiles_local
169     } type;
170     char *src;
171 };
172
173 struct conf_config
174 {
175     struct conf_server *servers;
176     struct conf_targetprofiles *targetprofiles;
177 };
178
179 #ifndef CONFIG_NOEXTERNS
180
181 extern struct conf_config *config;
182
183 #endif
184
185 int read_config(const char *fname);
186 xsltStylesheet *conf_load_stylesheet(const char *fname);
187
188 #endif
189
190 /*
191  * Local variables:
192  * c-basic-offset: 4
193  * indent-tabs-mode: nil
194  * End:
195  * vim: shiftwidth=4 tabstop=8 expandtab
196  */