1733617b1467fd89c42963bc27886cb6f4de74ba
[idzebra-moved-to-github.git] / include / zebraapi.h
1 /* $Id: zebraapi.h,v 1.4 2003-05-20 12:52:49 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 #ifndef ZEBRAAPI_H
24 #define ZEBRAAPI_H
25
26 #include <yaz/odr.h>
27 #include <yaz/oid.h>
28 #include <yaz/proto.h>
29 #include <zebraver.h>
30
31 /* Fixme! Compare string (ignore case) */
32 #ifdef WIN32
33 #define STRCASECMP      stricmp
34 #else
35 #define STRCASECMP      strcasecmp
36 #endif
37
38 YAZ_BEGIN_CDECL
39
40 struct recordGroup {
41     char  *groupName;
42     char  *databaseName;
43     char  *path;
44     char  *recordId;
45     char  *recordType;
46     int   flagStoreData;
47     int   flagStoreKeys;
48     int   flagRw;
49     int   fileVerboseLimit;
50     int   databaseNamePath;
51     int   explainDatabase;
52     int   followLinks;
53 };
54
55 typedef struct {
56   int processed;
57   int inserted;
58   int updated;
59   int deleted;
60   long utime;
61   long stime;
62 } ZebraTransactionStatus;
63
64 /* Retrieval Record Descriptor */
65 typedef struct {
66     int errCode;         /* non-zero if error when fetching this */
67     char *errString;     /* error string */
68     int position;        /* position of record in result set (1,2,..) */
69     char *buf;           /* record buffer (void pointer really) */
70     int len;             /* length */
71     oid_value format;    /* record syntax */
72     char *base; 
73     int  sysno;
74     int  score;
75 } ZebraRetrievalRecord;
76
77 /* Scan Term Descriptor */
78 typedef struct {
79     int occurrences;     /* scan term occurrences */
80     char *term;          /* scan term string */
81 } ZebraScanEntry;
82
83 typedef struct zebra_session *ZebraHandle;
84 typedef struct zebra_service *ZebraService;
85
86
87 /******
88  * Starting and stopping 
89  */
90
91 /* Start Zebra using file 'configName' (usually zebra.cfg) */
92 /* There should be exactly one ZebraService */
93 YAZ_EXPORT ZebraService zebra_start (const char *configName);
94
95 /* Close the whole Zebra */
96 YAZ_EXPORT void zebra_stop (ZebraService zs);
97
98
99 /* Open a ZebraHandle */
100 /* There should be one handle for each thred doing something */
101 /* with zebra, be that searching or indexing. In simple apps */
102 /* one handle is sufficient */
103 YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
104
105 /* Close handle */
106 YAZ_EXPORT void zebra_close (ZebraHandle zh);
107
108 /*********
109  * Error handling 
110  */
111
112 /* last error code */
113 YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
114
115 /* string representatio of above */
116 YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
117
118 /* extra information associated with error */
119 YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
120
121 /* get the result code and addinfo from zh */
122 YAZ_EXPORT void zebra_result (ZebraHandle zh, int *code, char **addinfo);
123 /* FIXME - why is this needed?? -H */
124
125
126 /**************
127  * Searching 
128  */
129
130 /* Search using RPN-Query */
131 YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output,
132                                   Z_RPNQuery *query,
133                                   const char *setname, int *hits);
134
135 YAZ_EXPORT int zebra_search_PQF (ZebraHandle zh, 
136                                  const char *pqf_query,
137                                  const char *setname);
138
139 /* Retrieve record(s) */
140 YAZ_EXPORT void zebra_records_retrieve (ZebraHandle zh, ODR stream,
141                        const char *setname, Z_RecordComposition *comp,
142                        oid_value input_format,
143                        int num_recs, ZebraRetrievalRecord *recs);
144
145 /* Delete Result Set(s) */
146 YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
147                                      int num_setnames, char **setnames,
148                                      int *statuses);
149
150
151 /* Browse */
152 YAZ_EXPORT void zebra_scan (ZebraHandle zh, ODR stream,
153                             Z_AttributesPlusTerm *zapt,
154                             oid_value attributeset,
155                             int *position, int *num_entries,
156                             ZebraScanEntry **list,
157                             int *is_partial);
158
159    
160           
161 /*********
162  * Other 
163  */
164                       
165 /* do authentication */
166 YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
167
168 /* Character normalisation on specific register .
169    This routine is subject to change - do not use. */
170 YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
171                                   const char *input_str, int input_len,
172                                   char *output_str, int output_len);
173
174
175 /******
176  * Admin 
177  */                   
178           
179 YAZ_EXPORT void zebra_create_database (ZebraHandle zh, const char *db);
180
181
182 YAZ_EXPORT void zebra_admin_shutdown (ZebraHandle zh);
183 YAZ_EXPORT void zebra_admin_start (ZebraHandle zh);
184
185 YAZ_EXPORT void zebra_shutdown (ZebraService zs);
186
187 YAZ_EXPORT void zebra_admin_import_begin (ZebraHandle zh, const char *database,
188                                           const char *record_type);
189
190 YAZ_EXPORT void zebra_admin_import_segment (ZebraHandle zh,
191                                             Z_Segment *segment);
192
193 void zebra_admin_import_end (ZebraHandle zh);
194
195 int zebra_admin_exchange_record (ZebraHandle zh,
196                                  const char *database,
197                                  const char *rec_buf,
198                                  size_t rec_len,
199                                  const char *recid_buf, size_t recid_len,
200                                  int action);
201
202 int zebra_begin_trans (ZebraHandle zh, int rw);
203 int zebra_end_trans (ZebraHandle zh);
204 int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *stat);
205
206 int zebra_commit (ZebraHandle zh);
207 int zebra_clean (ZebraHandle zh);
208
209 int zebra_init (ZebraHandle zh);
210 int zebra_compact (ZebraHandle zh);
211 void zebra_repository_update (ZebraHandle zh);
212 void zebra_repository_delete (ZebraHandle zh);
213 void zebra_repository_show (ZebraHandle zh);
214 int zebra_record_insert (ZebraHandle zh, const char *buf, int len);
215
216 YAZ_EXPORT void zebra_set_group (ZebraHandle zh, struct recordGroup *rg);
217
218
219 YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, 
220                                      int no, int *count, 
221                                      int *type, char *out, size_t *len);
222
223 YAZ_EXPORT void zebra_sort (ZebraHandle zh, ODR stream,
224                             int num_input_setnames,
225                             const char **input_setnames,
226                             const char *output_setname,
227                             Z_SortKeySpecList *sort_sequence,
228                             int *sort_status);
229
230
231 YAZ_EXPORT
232 int zebra_select_databases (ZebraHandle zh, int num_bases, 
233                             const char **basenames);
234
235 YAZ_EXPORT
236 int zebra_select_database (ZebraHandle zh, const char *basename);
237
238 YAZ_EXPORT
239 void zebra_shadow_enable (ZebraHandle zh, int value);
240
241 YAZ_EXPORT
242 void zebra_register_statistics (ZebraHandle zh, int dumpdict);
243
244 YAZ_EXPORT
245 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
246
247 /* Resources */
248 YAZ_EXPORT
249 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
250 YAZ_EXPORT
251 const char *zebra_get_resource(ZebraHandle zh, 
252                 const char *name, const char *defaultvalue);
253
254
255 YAZ_END_CDECL                                 
256 #endif