1 /* This file is part of Pazpar2.
2 Copyright (C) Index Data
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
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
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
20 #ifndef PAZPAR2_SESSION_H
21 #define PAZPAR2_SESSION_H
23 #include <yaz/comstack.h>
24 #include <yaz/pquery.h>
26 #include <yaz/yaz-ccl.h>
28 #include "facet_limit.h"
29 #include "relevance.h"
36 enum pazpar2_error_code {
40 PAZPAR2_MISSING_PARAMETER,
41 PAZPAR2_MALFORMED_PARAMETER_VALUE,
42 PAZPAR2_MALFORMED_PARAMETER_ENCODING,
43 PAZPAR2_MALFORMED_SETTING,
44 PAZPAR2_HITCOUNTS_FAILED,
45 PAZPAR2_RECORD_MISSING,
47 PAZPAR2_CONFIG_TARGET,
49 PAZPAR2_NOT_IMPLEMENTED,
51 PAZPAR2_ALREADY_BLOCKED,
56 // Represents a database as viewed from one session, possibly with settings overriden
58 struct session_database
60 struct database *database;
62 struct setting **settings;
63 normalize_record_t map;
64 struct session_database *next;
67 #define SESSION_WATCH_SHOW 0
68 #define SESSION_WATCH_RECORD 1
69 #define SESSION_WATCH_SHOW_PREF 2
70 #define SESSION_WATCH_TERMLIST 3
71 #define SESSION_WATCH_BYTARGET 4
72 #define SESSION_WATCH_MAX 4
74 typedef void (*session_watchfun)(void *data);
79 struct termlist *termlist;
80 struct named_termlist *next;
83 struct session_watchentry {
85 http_channel_observer_t obs;
93 struct conf_service *service; /* service in use for this session */
94 struct session_database *databases; // All databases, settings overriden
95 struct client_list *clients_active; // Clients connected for current search
96 struct client_list *clients_cached; // Clients in cache
97 NMEM session_nmem; // Nmem for session-permanent storage
98 NMEM nmem; // Nmem for each operation (i.e. search, result set, etc)
99 struct named_termlist *termlists;
100 struct relevance *relevance;
101 struct reclist *reclist;
104 struct session_watchentry watchlist[SESSION_WATCH_MAX + 1];
107 int number_of_warnings_unknown_elements;
108 int number_of_warnings_unknown_metadata;
109 normalize_cache_t normalize_cache;
110 YAZ_MUTEX session_mutex;
112 int settings_modified;
113 facet_limits_t facet_limits;
114 int clients_starting;
116 struct reclist_sortparms *sorted_results;
117 struct facet_id *facet_id_list;
122 int num_no_connection;
132 struct hitsbytarget {
136 Odr_int approximation;
145 char *suggestions_xml;
146 const char *query_type;
147 const char *query_data;
150 struct hitsbytarget *get_hitsbytarget(struct session *s, int *count, NMEM nmem);
151 struct session *session_create(NMEM nmem, struct conf_service *service,
152 unsigned session_id);
153 void session_destroy(struct session *s);
154 void session_init_databases(struct session *s);
155 void statistics(struct session *s, struct statistics *stat);
157 int sessions_get_count(void);
159 void session_sort(struct session *se, struct reclist_sortparms *sp,
160 const char *mergekey, const char *rank);
162 enum pazpar2_error_code session_search(struct session *s, const char *query,
163 const char *startrecs,
165 const char *filter, const char *limit,
166 const char **addinfo,
167 const char **addinfo2,
168 struct reclist_sortparms *sort_parm,
169 const char *mergekey,
171 struct record_cluster **show_range_start(struct session *s,
172 struct reclist_sortparms *sp,
174 int *num, int *total,
176 Odr_int *approximation,
177 void (*ready)(void *data),
178 struct http_channel *chan);
179 int session_fetch_more(struct session *s);
180 void show_range_stop(struct session *s, struct record_cluster **recs);
182 struct record_cluster *show_single_start(struct session *s, const char *id,
183 struct record_cluster **prev_r,
184 struct record_cluster **next_r);
185 void show_single_stop(struct session *s, struct record_cluster *rec);
186 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
187 int session_active_clients(struct session *s);
188 int session_is_preferred_clients_ready(struct session *s);
189 void session_apply_setting(struct session *se, const char *dbname,
190 const char *setting, const char *value);
191 const char *session_setting_oneval(struct session_database *db, int offset);
192 void session_stop(struct session *se);
194 int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem);
195 int ingest_xml_record(struct client *cl, xmlDoc *xdoc,
196 int record_no, NMEM nmem, int cached_copy);
197 void session_alert_watch(struct session *s, int what);
198 void add_facet(struct session *s, const char *type, const char *value, int count, struct client *cl);
200 int session_check_cluster_limit(struct session *se, struct record_cluster *rec);
202 void perform_termlist(struct http_channel *c, struct session *se, const char *name, int num, int version);
204 const char *session_lookup_id_facet(struct session *s, struct client *cl,
205 const char *type, const char *term);
207 void session_log(struct session *s, int level, const char *fmt, ...)
209 __attribute__ ((format (printf, 3, 4)))
217 * c-file-style: "Stroustrup"
218 * indent-tabs-mode: nil
220 * vim: shiftwidth=4 tabstop=8 expandtab