Generic sort mechanism. Sort supported by relevance, string, or string w/o lead.
[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 **databases;
70     int errors;
71     struct conf_queryprofile *qprofile;
72     struct conf_retrievalprofile *rprofile;
73     struct database *next;
74 };
75
76
77 // Represents a physical, reusable  connection to a remote Z39.50 host
78 struct connection {
79     IOCHAN iochan;
80     COMSTACK link;
81     struct host *host;
82     struct client *client;
83     char *ibuf;
84     int ibufsize;
85     enum {
86         Conn_Connecting,
87         Conn_Open,
88         Conn_Waiting,
89     } state;
90     struct connection *next;
91 };
92
93 // Represents client state for a connection to one search target
94 struct client {
95     struct database *database;
96     struct connection *connection;
97     struct session *session;
98     int hits;
99     int records;
100     int setno;
101     int requestid;                              // ID of current outstanding request
102     int diagnostic;
103     enum client_state
104     {
105         Client_Connecting,
106         Client_Connected,
107         Client_Idle,
108         Client_Initializing,
109         Client_Searching,
110         Client_Presenting,
111         Client_Error,
112         Client_Failed,
113         Client_Disconnected,
114         Client_Stopped
115     } state;
116     struct client *next;
117 };
118
119 #define SESSION_WATCH_RECORDS   0
120 #define SESSION_WATCH_MAX       0
121
122 #define SESSION_MAX_TERMLISTS 10
123
124 typedef void (*session_watchfun)(void *data);
125
126 struct named_termlist
127 {
128     char *name;
129     struct termlist *termlist;
130 };
131
132 // End-user session
133 struct session {
134     struct client *clients;
135     int requestid; 
136     char query[1024];
137     NMEM nmem;          // Nmem for each operation (i.e. search)
138     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
139     int num_termlists;
140     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
141     struct relevance *relevance;
142     struct reclist *reclist;
143     struct {
144         void *data;
145         session_watchfun fun;
146     } watchlist[SESSION_WATCH_MAX + 1];
147     int expected_maxrecs;
148     int total_hits;
149     int total_records;
150     int total_merged;
151 };
152
153 struct statistics {
154     int num_clients;
155     int num_no_connection;
156     int num_connecting;
157     int num_initializing;
158     int num_searching;
159     int num_presenting;
160     int num_idle;
161     int num_failed;
162     int num_error;
163     int num_hits;
164     int num_records;
165 };
166
167 struct hitsbytarget {
168     char id[256];
169     int hits;
170     int diagnostic;
171     int records;
172     char* state;
173     int connected;
174 };
175
176 struct parameters {
177     char proxy_override[128];
178     char listener_override[128];
179     struct conf_server *server;
180     int dump_records;
181     int timeout;                /* operations timeout, in seconds */
182     char implementationId[128];
183     char implementationName[128];
184     char implementationVersion[128];
185     int target_timeout; // seconds
186     int session_timeout;
187     int toget;
188     int chunk;
189     CCL_bibset ccl_filter;
190     yaz_marc_t yaz_marc;
191     ODR odr_out;
192     ODR odr_in;
193 };
194
195 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
196 int select_targets(struct session *se);
197 struct session *new_session();
198 void destroy_session(struct session *s);
199 int load_targets(struct session *s, const char *fn);
200 void statistics(struct session *s, struct statistics *stat);
201 char *search(struct session *s, char *query);
202 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
203         int *num, int *total, int *sumhits, NMEM nmem_show);
204 struct record_cluster *show_single(struct session *s, int id);
205 struct termlist_score **termlist(struct session *s, const char *name, int *num);
206 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
207 int session_active_clients(struct session *s);
208
209 #endif
210
211 /*
212  * Local variables:
213  * c-basic-offset: 4
214  * indent-tabs-mode: nil
215  * End:
216  * vim: shiftwidth=4 tabstop=8 expandtab
217  */