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