Metadata elements dynamically created from XSLT normalization output.
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 #ifndef PAZPAR2_H
2 #define PAZPAR2_H
3
4 struct record;
5
6 #include <netdb.h>
7
8 #include <libxslt/xsltutils.h>
9 #include <libxslt/transform.h>
10
11 #include <yaz/comstack.h>
12 #include <yaz/pquery.h>
13 #include <yaz/ccl.h>
14 #include <yaz/yaz-ccl.h>
15
16 #include "termlists.h"
17 #include "relevance.h"
18 #include "eventl.h"
19 #include "config.h"
20
21 struct client;
22
23 struct record_metadata {
24     union {
25         char *text;
26         struct {
27             int year1;
28             int year2;
29         } year;
30     } data;
31     struct record_metadata *next; // next item of this name
32 };
33
34 struct record {
35     struct client *client;
36     int target_offset;
37     struct record_metadata **metadata; // Array mirrors list of metadata fields in config
38     int relevance;
39     int *term_frequency_vec;
40     struct record *next;
41 };
42
43 struct record_cluster
44 {
45     struct record_metadata **metadata; // Array mirrors list of metadata fields in config
46     char *merge_key;
47     int relevance;
48     int *term_frequency_vec;
49     struct record *records;
50 };
51
52 struct connection;
53
54 // Represents a host (irrespective of databases)
55 struct host {
56     char *hostport;
57     char *ipport;
58     struct connection *connections; // All connections to this
59     struct host *next;
60 };
61
62 // Represents a (virtual) database on a host
63 struct database {
64     struct host *host;
65     char *url;
66     char **databases;
67     int errors;
68     struct conf_queryprofile *qprofile;
69     struct conf_retrievalprofile *rprofile;
70     struct database *next;
71 };
72
73
74 // Represents a physical, reusable  connection to a remote Z39.50 host
75 struct connection {
76     IOCHAN iochan;
77     COMSTACK link;
78     struct host *host;
79     struct client *client;
80     char *ibuf;
81     int ibufsize;
82     enum {
83         Conn_Connecting,
84         Conn_Open,
85         Conn_Waiting,
86     } state;
87     struct connection *next;
88 };
89
90 // Represents client state for a connection to one search target
91 struct client {
92     struct database *database;
93     struct connection *connection;
94     struct session *session;
95     int hits;
96     int records;
97     int setno;
98     int requestid;                              // ID of current outstanding request
99     int diagnostic;
100     enum client_state
101     {
102         Client_Connecting,
103         Client_Connected,
104         Client_Idle,
105         Client_Initializing,
106         Client_Searching,
107         Client_Presenting,
108         Client_Error,
109         Client_Failed,
110         Client_Disconnected,
111         Client_Stopped
112     } state;
113     struct client *next;
114 };
115
116 #define SESSION_WATCH_RECORDS   0
117 #define SESSION_WATCH_MAX       0
118
119 #define SESSION_MAX_TERMLISTS 10
120
121 typedef void (*session_watchfun)(void *data);
122
123 struct named_termlist
124 {
125     char *name;
126     struct termlist *termlist;
127 };
128
129 // End-user session
130 struct session {
131     struct client *clients;
132     int requestid; 
133     char query[1024];
134     NMEM nmem;          // Nmem for each operation (i.e. search)
135     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
136     int num_termlists;
137     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
138     struct relevance *relevance;
139     struct reclist *reclist;
140     struct {
141         void *data;
142         session_watchfun fun;
143     } watchlist[SESSION_WATCH_MAX + 1];
144     int expected_maxrecs;
145     int total_hits;
146     int total_records;
147 };
148
149 struct statistics {
150     int num_clients;
151     int num_no_connection;
152     int num_connecting;
153     int num_initializing;
154     int num_searching;
155     int num_presenting;
156     int num_idle;
157     int num_failed;
158     int num_error;
159     int num_hits;
160     int num_records;
161 };
162
163 struct hitsbytarget {
164     char id[256];
165     int hits;
166     int diagnostic;
167     int records;
168     char* state;
169     int connected;
170 };
171
172 struct parameters {
173     struct conf_server *server;
174     int dump_records;
175     int timeout;                /* operations timeout, in seconds */
176     char implementationId[128];
177     char implementationName[128];
178     char implementationVersion[128];
179     int target_timeout; // seconds
180     int session_timeout;
181     int toget;
182     int chunk;
183     CCL_bibset ccl_filter;
184     yaz_marc_t yaz_marc;
185     ODR odr_out;
186     ODR odr_in;
187 };
188
189 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
190 int select_targets(struct session *se);
191 struct session *new_session();
192 void destroy_session(struct session *s);
193 int load_targets(struct session *s, const char *fn);
194 void statistics(struct session *s, struct statistics *stat);
195 char *search(struct session *s, char *query);
196 struct record_cluster **show(struct session *s, int start, int *num, int *total,
197                      int *sumhits, NMEM nmem_show);
198 struct termlist_score **termlist(struct session *s, const char *name, int *num);
199 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
200 int session_active_clients(struct session *s);
201
202 #endif
203
204 /*
205  * Local variables:
206  * c-basic-offset: 4
207  * indent-tabs-mode: nil
208  * End:
209  * vim: shiftwidth=4 tabstop=8 expandtab
210  */