0aab010613e2ce48062283ac09201eda0cabef2d
[pazpar2-moved-to-github.git] / pazpar2.h
1 #ifndef PAZPAR2_H
2 #define PAZPAR2_H
3
4 struct record;
5
6 #include <netdb.h>
7
8 #include <yaz/comstack.h>
9 #include <yaz/pquery.h>
10 #include "termlists.h"
11 #include "relevance.h"
12 #include "eventl.h"
13
14 #define MAX_DATABASES 512
15
16 struct record {
17     struct client *client;
18     int target_offset;
19     char *buf;
20     char *merge_key;
21     char *title;
22     int relevance;
23     int *term_frequency_vec;
24     struct record *next_cluster;
25 };
26
27 struct connection;
28
29 // Represents a host (irrespective of databases)
30 struct host {
31     char *hostport;
32     char *ipport;
33     struct connection *connections; // All connections to this
34     struct host *next;
35 };
36
37 // Represents a (virtual) database on a host
38 struct database {
39     struct host *host;
40     char *url;
41     char databases[MAX_DATABASES][128];
42     int errors;
43     struct database *next;
44 };
45
46 struct client;
47
48 // Represents a physical, reusable  connection to a remote Z39.50 host
49 struct connection {
50     IOCHAN iochan;
51     COMSTACK link;
52     struct host *host;
53     struct client *client;
54     char *ibuf;
55     int ibufsize;
56     enum {
57         Conn_Connecting,
58         Conn_Open,
59         Conn_Waiting,
60     } state;
61     struct connection *next;
62 };
63
64 // Represents client state for a connection to one search target
65 struct client {
66     struct database *database;
67     struct connection *connection;
68     struct session *session;
69     int hits;
70     int records;
71     int setno;
72     int requestid;                              // ID of current outstanding request
73     int diagnostic;
74     enum client_state
75     {
76         Client_Connecting,
77         Client_Connected,
78         Client_Idle,
79         Client_Initializing,
80         Client_Searching,
81         Client_Presenting,
82         Client_Error,
83         Client_Failed,
84         Client_Disconnected,
85         Client_Stopped
86     } state;
87     struct client *next;
88 };
89
90 // End-user session
91 struct session {
92     struct client *clients;
93     int requestid; 
94     char query[1024];
95     NMEM nmem;          // Nmem for each operation (i.e. search)
96     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
97     struct termlist *termlist;
98     struct relevance *relevance;
99     struct reclist *reclist;
100     int total_hits;
101     int total_records;
102 };
103
104 struct statistics {
105     int num_clients;
106     int num_no_connection;
107     int num_connecting;
108     int num_initializing;
109     int num_searching;
110     int num_presenting;
111     int num_idle;
112     int num_failed;
113     int num_error;
114     int num_hits;
115     int num_records;
116 };
117
118 struct hitsbytarget {
119     char id[256];
120     int hits;
121     int diagnostic;
122     int records;
123     char* state;
124     int connected;
125 };
126
127 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
128 int select_targets(struct session *se);
129 struct session *new_session();
130 void session_destroy(struct session *s);
131 int load_targets(struct session *s, const char *fn);
132 void statistics(struct session *s, struct statistics *stat);
133 char *search(struct session *s, char *query);
134 struct record **show(struct session *s, int start, int *num, int *total, int *sumhits);
135 struct termlist_score **termlist(struct session *s, int *num);
136
137 #endif
138
139 /*
140  * Local variables:
141  * c-basic-offset: 4
142  * indent-tabs-mode: nil
143  * End:
144  * vim: shiftwidth=4 tabstop=8 expandtab
145  */