New optional argument, startrecs, for cmd=search
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2009 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 PAZPAR2_H
21 #define PAZPAR2_H
22
23 #include <yaz/comstack.h>
24 #include <yaz/pquery.h>
25 #include <yaz/ccl.h>
26 #include <yaz/yaz-ccl.h>
27
28 #include "termlists.h"
29 #include "reclists.h"
30 #include "pazpar2_config.h"
31 #include "http.h"
32
33 struct record;
34 struct client;
35
36
37 enum pazpar2_error_code {
38     PAZPAR2_NO_ERROR = 0,
39
40     PAZPAR2_NO_SESSION,
41     PAZPAR2_MISSING_PARAMETER,
42     PAZPAR2_MALFORMED_PARAMETER_VALUE,
43     PAZPAR2_MALFORMED_PARAMETER_ENCODING,
44     PAZPAR2_MALFORMED_SETTING,
45     PAZPAR2_HITCOUNTS_FAILED,
46     PAZPAR2_RECORD_MISSING,
47     PAZPAR2_NO_TARGETS,
48     PAZPAR2_CONFIG_TARGET,
49     PAZPAR2_RECORD_FAIL,
50     PAZPAR2_NOT_IMPLEMENTED,
51
52     PAZPAR2_LAST_ERROR
53 };
54
55 enum pazpar2_database_criterion_type {
56     PAZPAR2_STRING_MATCH,
57     PAZPAR2_SUBSTRING_MATCH
58 };
59
60 // Represents a (virtual) database on a host
61 struct database {
62     struct host *host;
63     char *url;
64     char **databases;
65     int errors;
66     struct zr_explain *explain;
67     struct setting **settings;
68     struct database *next;
69 };
70
71 struct database_criterion_value {
72     char *value;
73     struct database_criterion_value *next;
74 };
75
76 struct database_criterion {
77     char *name;
78     enum pazpar2_database_criterion_type type;
79     struct database_criterion_value *values;
80     struct database_criterion *next;
81 };
82
83 // Represents a database as viewed from one session, possibly with settings overriden
84 // for that session
85 struct session_database
86 {
87     struct database *database;
88     struct setting **settings;
89     normalize_record_t map;
90     struct session_database *next;
91 };
92
93
94
95 #define SESSION_WATCH_SHOW      0
96 #define SESSION_WATCH_RECORD    1
97 #define SESSION_WATCH_MAX       1
98
99 #define SESSION_MAX_TERMLISTS 10
100
101 typedef void (*session_watchfun)(void *data);
102
103 struct named_termlist
104 {
105     char *name;
106     struct termlist *termlist;
107 };
108
109 struct session_watchentry {
110     void *data;
111     http_channel_observer_t obs;
112     session_watchfun fun;
113 };
114
115 // End-user session
116 struct session {
117     struct conf_service *service; /* service in use for this session */
118     struct session_database *databases;  // All databases, settings overriden
119     struct client *clients;              // Clients connected for current search
120     NMEM session_nmem;  // Nmem for session-permanent storage
121     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
122     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
123     int num_termlists;
124     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
125     struct relevance *relevance;
126     struct reclist *reclist;
127     struct session_watchentry watchlist[SESSION_WATCH_MAX + 1];
128     int total_hits;
129     int total_records;
130     int total_merged;
131     int number_of_warnings_unknown_elements;
132     int number_of_warnings_unknown_metadata;
133     normalize_cache_t normalize_cache;
134 };
135
136 struct statistics {
137     int num_clients;
138     int num_no_connection;
139     int num_connecting;
140     int num_working;
141     int num_idle;
142     int num_failed;
143     int num_error;
144     int num_hits;
145     int num_records;
146 };
147
148 struct hitsbytarget {
149     char *id;
150     const char *name;
151     int hits;
152     int diagnostic;
153     int records;
154     const char *state;
155     int connected;
156 };
157
158 struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem);
159 int select_targets(struct session *se, struct database_criterion *crit);
160 struct session *new_session(NMEM nmem, struct conf_service *service);
161 void destroy_session(struct session *s);
162 void session_init_databases(struct session *s);
163 int load_targets(struct session *s, const char *fn);
164 void statistics(struct session *s, struct statistics *stat);
165 enum pazpar2_error_code search(struct session *s, const char *query,
166                                const char *startrecs, const char *maxrecs,
167                                const char *filter, const char **addinfo);
168 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
169         int *num, int *total, int *sumhits, NMEM nmem_show);
170 struct record_cluster *show_single(struct session *s, const char *id,
171                                    struct record_cluster **prev_r,
172                                    struct record_cluster **next_r);
173 struct termlist_score **termlist(struct session *s, const char *name, int *num);
174 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
175 int session_active_clients(struct session *s);
176 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
177 const char *session_setting_oneval(struct session_database *db, int offset);
178
179 void pazpar2_add_channel(IOCHAN c);
180 void pazpar2_event_loop(void);
181
182 int host_getaddrinfo(struct host *host);
183
184 struct record *ingest_record(struct client *cl, const char *rec,
185                              int record_no);
186 void session_alert_watch(struct session *s, int what);
187 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
188
189 #endif
190
191 /*
192  * Local variables:
193  * c-basic-offset: 4
194  * c-file-style: "Stroustrup"
195  * indent-tabs-mode: nil
196  * End:
197  * vim: shiftwidth=4 tabstop=8 expandtab
198  */
199