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