Fixed bug in zebraIndexUnlock. On NT, the lock files wasn't removed.
[idzebra-moved-to-github.git] / index / zlogs.c
1 /*
2  * Copyright (C) 1995-1998, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: zlogs.c,v $
7  * Revision 1.7  1998-01-29 13:40:11  adam
8  * Better logging for scan service.
9  *
10  * Revision 1.6  1997/09/29 09:06:41  adam
11  * Removed static var to make this module thread safe.
12  *
13  * Revision 1.5  1997/04/30 08:56:07  quinn
14  * null
15  *
16  * Revision 1.4  1996/10/08  09:41:25  quinn
17  * Fixed diagnostic.
18  *
19  * Revision 1.3  1996/03/20  09:36:40  adam
20  * Function dict_lookup_grep got extra parameter, init_pos, which marks
21  * from which position in pattern approximate pattern matching should occur.
22  * Approximate pattern matching is used in relevance=re-2.
23  *
24  * Revision 1.2  1996/01/03  16:22:11  quinn
25  * operator->roperator
26  *
27  * Revision 1.1  1995/11/16  17:00:55  adam
28  * Better logging of rpn query.
29  *
30  */
31 #include <stdio.h>
32 #include <assert.h>
33
34 #include "zserver.h"
35
36 static void attrStr (int type, int value, enum oid_value ast, char *str)
37 {
38     *str = '\0';
39     switch (ast)
40     {
41     case VAL_BIB1:
42     case VAL_EXP1:
43     case VAL_GILS:
44         switch (type)
45         {
46         case 1:
47             sprintf (str, "use");
48             break;
49         case 2:
50             switch (value)
51             {
52             case 1:
53                 sprintf (str, "relation=Less than");
54                 break;
55             case 2:
56                 sprintf (str, "relation=Less than or equal");
57                 break;
58             case 3:
59                 sprintf (str, "relation=Equal");
60                 break;
61             case 4:
62                 sprintf (str, "relation=Greater or equal");
63                 break;
64             case 5:
65                 sprintf (str, "relation=Greater than");
66                 break;
67             case 6:
68                 sprintf (str, "relation=Not equal");
69                 break;
70             case 100:
71                 sprintf (str, "relation=Phonetic");
72                 break;
73             case 101:
74                 sprintf (str, "relation=Stem");
75                 break;
76             case 102:
77                 sprintf (str, "relation=Relevance");
78                 break;
79             case 103:
80                 sprintf (str, "relation=AlwaysMatches");
81                 break;
82             default:
83                 sprintf (str, "relation");
84             }
85             break;
86         case 3:
87             switch (value)
88             {
89             case 1:
90                 sprintf (str, "position=First in field");
91                 break;
92             case 2:
93                 sprintf (str, "position=First in any subfield");
94                 break;
95             case 3:
96                 sprintf (str, "position=Any position in field");
97                 break;
98             default:
99                 sprintf (str, "position");
100             }
101             break;
102         case 4:
103             switch (value)
104             {
105             case 1:
106                 sprintf (str, "structure=Phrase");
107                 break;
108             case 2:
109                 sprintf (str, "structure=Word");
110                 break;
111             case 3:
112                 sprintf (str, "structure=Key");
113                 break;
114             case 4:
115                 sprintf (str, "structure=Year");
116                 break;
117             case 5:
118                 sprintf (str, "structure=Date");
119                 break;
120             case 6:
121                 sprintf (str, "structure=Word list");
122                 break;
123             case 100:
124                 sprintf (str, "structure=Date (un)");
125                 break;
126             case 101:
127                 sprintf (str, "structure=Name (norm)");
128                 break;
129             case 102:
130                 sprintf (str, "structure=Name (un)");
131                 break;
132             case 103:
133                 sprintf (str, "structure=Structure");
134                 break;
135             case 104:
136                 sprintf (str, "structure=urx");
137                 break;
138             case 105:
139                 sprintf (str, "structure=free-form-text");
140                 break;
141             case 106:
142                 sprintf (str, "structure=document-text");
143                 break;
144             case 107:
145                 sprintf (str, "structure=local-number");
146                 break;
147             case 108:
148                 sprintf (str, "structure=string");
149                 break;
150             case 109:
151                 sprintf (str, "structure=numeric string");
152                 break;
153             default:
154                 sprintf (str, "structure");
155             }
156             break;
157         case 5:
158             switch (value)
159             {
160             case 1:
161                 sprintf (str, "truncation=Right");
162                 break;
163             case 2:
164                 sprintf (str, "truncation=Left");
165                 break;
166             case 3:
167                 sprintf (str, "truncation=Left&right");
168                 break;
169             case 100:
170                 sprintf (str, "truncation=Do not truncate");
171                 break;
172             case 101:
173                 sprintf (str, "truncation=Process #");
174                 break;
175             case 102:
176                 sprintf (str, "truncation=re-1");
177                 break;
178             case 103:
179                 sprintf (str, "truncation=re-2");
180                 break;
181             default:
182                 sprintf (str, "truncation");
183             }
184             break;
185         case 6:
186             switch (value)
187             {
188             case 1:
189                 sprintf (str, "completeness=Incomplete subfield");
190                 break;
191             case 2:
192                 sprintf (str, "completeness=Complete subfield");
193                 break;
194             case 3:
195                 sprintf (str, "completeness=Complete field");
196                 break;
197             default:
198                 sprintf (str, "completeness");
199             }
200             break;
201         }
202         break;
203     default:
204         break;
205     }
206     if (*str)
207         sprintf (str + strlen(str), " (%d=%d)", type, value);
208     else
209         sprintf (str, "%d=%d", type, value);
210 }
211
212 /*
213  * zlog_attributes: print attributes of term
214  */
215 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
216                              enum oid_value ast)
217 {
218     int of, i;
219     char str[80];
220     for (of = 0; of < t->num_attributes; of++)
221     {
222         Z_AttributeElement *element;
223         element = t->attributeList[of];
224
225         switch (element->which) 
226         {
227         case Z_AttributeValue_numeric:
228             attrStr (*element->attributeType,
229                      *element->value.numeric, ast, str);
230             logf (LOG_LOG, "%*.s %s", level, "", str);
231             break;
232         case Z_AttributeValue_complex:
233             logf (LOG_LOG, "%*.s attributeType=%d complex", level, "",
234                   *element->attributeType);
235             for (i = 0; i<element->value.complex->num_list; i++)
236             {
237                 if (element->value.complex->list[i]->which ==
238                     Z_StringOrNumeric_string)
239                     logf (LOG_LOG, "%*.s  string: '%s'", level, "",
240                           element->value.complex->list[i]->u.string);
241                 else if (element->value.complex->list[i]->which ==
242                          Z_StringOrNumeric_numeric)
243                     logf (LOG_LOG, "%*.s  numeric: '%d'", level, "",
244                           *element->value.complex->list[i]->u.numeric);
245             }
246             break;
247         default:
248             logf (LOG_LOG, "%.*s attribute unknown", level, "");
249         }
250     }
251 }
252
253 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
254 {
255     if (zs->which == Z_RPNStructure_complex)
256     {
257         switch (zs->u.complex->roperator->which)
258         {
259         case Z_Operator_and:
260             logf (LOG_LOG, "%*.s and", level, "");
261             break;
262         case Z_Operator_or:
263             logf (LOG_LOG, "%*.s or", level, "");
264             break;
265         case Z_Operator_and_not:
266             logf (LOG_LOG, "%*.s and-not", level, "");
267             break;
268         default:
269             logf (LOG_LOG, "%*.s unknown complex", level, "");
270             return;
271         }
272         zlog_structure (zs->u.complex->s1, level+2, ast);
273         zlog_structure (zs->u.complex->s2, level+2, ast);
274     }
275     else if (zs->which == Z_RPNStructure_simple)
276     {
277         if (zs->u.simple->which == Z_Operand_APT)
278         {
279             Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
280
281             if (zapt->term->which == Z_Term_general) 
282             {
283                 logf (LOG_LOG, "%*.s term '%.*s' (general)", level, "",
284                       zapt->term->u.general->len, zapt->term->u.general->buf);
285             }
286             else
287             {
288                 logf (LOG_LOG, "%*.s term (not general)", level, "");
289             }
290             zlog_attributes (zapt, level+2, ast);
291         }
292         else if (zs->u.simple->which == Z_Operand_resultSetId)
293         {
294             logf (LOG_LOG, "%*.s set '%s'", level, "",
295                   zs->u.simple->u.resultSetId);
296         }
297         else
298             logf (LOG_LOG, "%*.s unknown simple structure", level, "");
299     }
300     else
301         logf (LOG_LOG, "%*.s unknown structure", level, "");
302 }
303
304 void zlog_rpn (Z_RPNQuery *rpn)
305 {
306     oident *attrset = oid_getentbyoid (rpn->attributeSetId);
307     enum oid_value ast;
308
309     ast = attrset->value;
310     logf (LOG_LOG, "RPN query. Type: %s", attrset->desc);
311     zlog_structure (rpn->RPNStructure, 0, ast);
312 }
313
314 void zlog_scan (Z_AttributesPlusTerm *zapt, oid_value ast)
315 {
316     int level = 0;
317     if (zapt->term->which == Z_Term_general) 
318     {
319         logf (LOG_LOG, "%*.s term '%.*s' (general)", level, "",
320               zapt->term->u.general->len, zapt->term->u.general->buf);
321     }
322     else
323         logf (LOG_LOG, "%*.s term (not general)", level, "");
324     zlog_attributes (zapt, level+2, ast);
325 }