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