8197db7272cecd9bd95e9e3b74c3b34c66556107
[idzebra-moved-to-github.git] / index / zebraapi.h
1 /* $Id: zebraapi.h,v 1.25 2003-02-11 17:28:10 heikki 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 /* Retrieval Record Descriptor */
58 typedef struct {
59     int errCode;         /* non-zero if error when fetching this */
60     char *errString;     /* error string */
61     int position;        /* position of record in result set (1,2,..) */
62     char *buf;           /* record buffer (void pointer really) */
63     int len;             /* length */
64     oid_value format;    /* record syntax */
65     char *base; 
66 } ZebraRetrievalRecord;
67
68 /* Scan Term Descriptor */
69 typedef struct {
70     int occurrences;     /* scan term occurrences */
71     char *term;          /* scan term string */
72 } ZebraScanEntry;
73
74 typedef struct zebra_session *ZebraHandle;
75 typedef struct zebra_service *ZebraService;
76
77
78 /******
79  * Starting and stopping 
80  */
81
82 /* Start Zebra using file 'configName' (usually zebra.cfg) */
83 /* There should be exactly one ZebraService */
84 YAZ_EXPORT ZebraService zebra_start (const char *configName);
85
86 /* Close the whole Zebra */
87 YAZ_EXPORT void zebra_stop (ZebraService zs);
88
89
90 /* Open a ZebraHandle */
91 /* There should be one handle for each thred doing something */
92 /* with zebra, be that searching or indexing. In simple apps */
93 /* one handle is sufficient */
94 YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
95
96 /* Close handle */
97 YAZ_EXPORT void zebra_close (ZebraHandle zh);
98
99 /*********
100  * Error handling 
101  */
102
103 /* last error code */
104 YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
105
106 /* string representatio of above */
107 YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
108
109 /* extra information associated with error */
110 YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
111
112 /* get the result code and addinfo from zh */
113 YAZ_EXPORT void zebra_result (ZebraHandle zh, int *code, char **addinfo);
114 /* FIXME - why is this needed?? -H */
115
116
117 /**************
118  * Searching 
119  */
120
121 /* Search using RPN-Query */
122 YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output,
123                                   Z_RPNQuery *query,
124                                   const char *setname, int *hits);
125
126 /* Retrieve record(s) */
127 YAZ_EXPORT void zebra_records_retrieve (ZebraHandle zh, ODR stream,
128                        const char *setname, Z_RecordComposition *comp,
129                        oid_value input_format,
130                        int num_recs, ZebraRetrievalRecord *recs);
131
132 /* Delete Result Set(s) */
133 YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
134                                      int num_setnames, char **setnames,
135                                      int *statuses);
136
137
138 /* Browse */
139 YAZ_EXPORT void zebra_scan (ZebraHandle zh, ODR stream,
140                             Z_AttributesPlusTerm *zapt,
141                             oid_value attributeset,
142                             int *position, int *num_entries,
143                             ZebraScanEntry **list,
144                             int *is_partial);
145
146    
147           
148 /*********
149  * Other 
150  */
151                       
152 /* do authentication */
153 YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
154
155 /* Character normalisation on specific register .
156    This routine is subject to change - do not use. */
157 YAZ_EXPORT int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
158                                   const char *input_str, int input_len,
159                                   char *output_str, int output_len);
160
161
162 /******
163  * Admin 
164  */                   
165           
166 YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db);
167
168
169 YAZ_EXPORT void zebra_admin_shutdown (ZebraHandle zh);
170 YAZ_EXPORT void zebra_admin_start (ZebraHandle zh);
171
172 YAZ_EXPORT void zebra_shutdown (ZebraService zs);
173
174 YAZ_EXPORT void zebra_admin_import_begin (ZebraHandle zh, const char *database,
175                                           const char *record_type);
176
177 YAZ_EXPORT void zebra_admin_import_segment (ZebraHandle zh,
178                                             Z_Segment *segment);
179
180 void zebra_admin_import_end (ZebraHandle zh);
181
182 int zebra_admin_exchange_record (ZebraHandle zh,
183                                  const char *database,
184                                  const char *rec_buf,
185                                  size_t rec_len,
186                                  const char *recid_buf, size_t recid_len,
187                                  int action);
188
189 void zebra_begin_trans (ZebraHandle zh);
190 void zebra_end_trans (ZebraHandle zh);
191
192 int zebra_commit (ZebraHandle zh);
193
194 int zebra_init (ZebraHandle zh);
195 int zebra_compact (ZebraHandle zh);
196 void zebra_repository_update (ZebraHandle zh);
197 void zebra_repository_delete (ZebraHandle zh);
198 void zebra_repository_show (ZebraHandle zh);
199 int zebra_record_insert (ZebraHandle zh, const char *buf, int len);
200
201 YAZ_EXPORT void zebra_set_group (ZebraHandle zh, struct recordGroup *rg);
202
203
204 YAZ_EXPORT int zebra_resultSetTerms (ZebraHandle zh, const char *setname, 
205                                      int no, int *count, 
206                                      int *type, char *out, size_t *len);
207
208 YAZ_EXPORT void zebra_sort (ZebraHandle zh, ODR stream,
209                             int num_input_setnames,
210                             const char **input_setnames,
211                             const char *output_setname,
212                             Z_SortKeySpecList *sort_sequence,
213                             int *sort_status);
214
215
216 YAZ_EXPORT
217 int zebra_select_databases (ZebraHandle zh, int num_bases, 
218                             const char **basenames);
219
220 YAZ_EXPORT
221 int zebra_select_database (ZebraHandle zh, const char *basename);
222
223 YAZ_EXPORT
224 void zebra_shadow_enable (ZebraHandle zh, int value);
225
226 YAZ_EXPORT
227 void zebra_register_statistics (ZebraHandle zh, int dumpdict);
228
229 YAZ_EXPORT
230 int zebra_record_encoding (ZebraHandle zh, const char *encoding);
231
232 /* Resources */
233 YAZ_EXPORT
234 void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
235 YAZ_EXPORT
236 const char *zebra_get_resource(ZebraHandle zh, 
237                 const char *name, const char *defaultvalue);
238
239
240 YAZ_END_CDECL                                 
241 #endif