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