2 * Copyright (C) 1995-2000, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 2000-01-31 13:15:22 adam
8 * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
9 * that some characters are not surrounded by spaces in resulting term.
12 * Revision 1.3 1999/11/30 13:47:12 adam
13 * Improved installation. Moved header files to include/yaz.
15 * Revision 1.2 1999/08/27 09:40:33 adam
16 * Renamed logf function to yaz_log. Removed VC++ project files.
18 * Revision 1.1 1999/06/08 10:10:16 adam
19 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
21 * Revision 1.1 1998/11/16 16:02:35 adam
22 * Added loggin utilies, log_rpn_query and log_scan_term. These used
23 * to be part of Zebra.
27 * Old logs from zlogs.c:
29 * Revision 1.9 1998/10/13 20:36:02 adam
30 * Changed "indent" format string in log messages.
32 * Revision 1.8 1998/04/02 14:35:29 adam
33 * First version of Zebra that works with compiled ASN.1.
35 * Revision 1.7 1998/01/29 13:40:11 adam
36 * Better logging for scan service.
38 * Revision 1.6 1997/09/29 09:06:41 adam
39 * Removed static var to make this module thread safe.
41 * Revision 1.5 1997/04/30 08:56:07 quinn
44 * Revision 1.4 1996/10/08 09:41:25 quinn
47 * Revision 1.3 1996/03/20 09:36:40 adam
48 * Function dict_lookup_grep got extra parameter, init_pos, which marks
49 * from which position in pattern approximate pattern matching should occur.
50 * Approximate pattern matching is used in relevance=re-2.
52 * Revision 1.2 1996/01/03 16:22:11 quinn
55 * Revision 1.1 1995/11/16 17:00:55 adam
56 * Better logging of rpn query.
62 #include <yaz/logrpn.h>
64 static void attrStr (int type, int value, enum oid_value ast, char *str)
81 sprintf (str, "relation=Less than");
84 sprintf (str, "relation=Less than or equal");
87 sprintf (str, "relation=Equal");
90 sprintf (str, "relation=Greater or equal");
93 sprintf (str, "relation=Greater than");
96 sprintf (str, "relation=Not equal");
99 sprintf (str, "relation=Phonetic");
102 sprintf (str, "relation=Stem");
105 sprintf (str, "relation=Relevance");
108 sprintf (str, "relation=AlwaysMatches");
111 sprintf (str, "relation");
118 sprintf (str, "position=First in field");
121 sprintf (str, "position=First in any subfield");
124 sprintf (str, "position=Any position in field");
127 sprintf (str, "position");
134 sprintf (str, "structure=Phrase");
137 sprintf (str, "structure=Word");
140 sprintf (str, "structure=Key");
143 sprintf (str, "structure=Year");
146 sprintf (str, "structure=Date");
149 sprintf (str, "structure=Word list");
152 sprintf (str, "structure=Date (un)");
155 sprintf (str, "structure=Name (norm)");
158 sprintf (str, "structure=Name (un)");
161 sprintf (str, "structure=Structure");
164 sprintf (str, "structure=urx");
167 sprintf (str, "structure=free-form-text");
170 sprintf (str, "structure=document-text");
173 sprintf (str, "structure=local-number");
176 sprintf (str, "structure=string");
179 sprintf (str, "structure=numeric string");
182 sprintf (str, "structure");
189 sprintf (str, "truncation=Right");
192 sprintf (str, "truncation=Left");
195 sprintf (str, "truncation=Left&right");
198 sprintf (str, "truncation=Do not truncate");
201 sprintf (str, "truncation=Process #");
204 sprintf (str, "truncation=re-1");
207 sprintf (str, "truncation=re-2");
210 sprintf (str, "truncation");
217 sprintf (str, "completeness=Incomplete subfield");
220 sprintf (str, "completeness=Complete subfield");
223 sprintf (str, "completeness=Complete field");
226 sprintf (str, "completeness");
235 sprintf (str + strlen(str), " (%d=%d)", type, value);
237 sprintf (str, "%d=%d", type, value);
241 * zlog_attributes: print attributes of term
243 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
249 int num_attributes = t->attributes->num_attributes;
251 int num_attributes = t->num_attributes;
254 for (of = 0; of < num_attributes; of++)
256 const char *attset_name = "";
257 Z_AttributeElement *element;
259 element = t->attributes->attributes[of];
261 element = t->attributeList[of];
263 if (element->attributeSet)
266 attrset = oid_getentbyoid (element->attributeSet);
267 attset_name = attrset->desc;
269 switch (element->which)
271 case Z_AttributeValue_numeric:
272 attrStr (*element->attributeType,
273 *element->value.numeric, ast, str);
274 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
276 case Z_AttributeValue_complex:
277 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
278 level, "", attset_name, *element->attributeType);
279 for (i = 0; i<element->value.complex->num_list; i++)
281 if (element->value.complex->list[i]->which ==
282 Z_StringOrNumeric_string)
283 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
284 element->value.complex->list[i]->u.string);
285 else if (element->value.complex->list[i]->which ==
286 Z_StringOrNumeric_numeric)
287 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
288 *element->value.complex->list[i]->u.numeric);
292 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
293 level, "", attset_name);
298 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
300 if (zs->which == Z_RPNStructure_complex)
302 switch (zs->u.complex->roperator->which)
305 yaz_log (LOG_LOG, "%*.0s and", level, "");
308 yaz_log (LOG_LOG, "%*.0s or", level, "");
310 case Z_Operator_and_not:
311 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
314 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
317 zlog_structure (zs->u.complex->s1, level+2, ast);
318 zlog_structure (zs->u.complex->s2, level+2, ast);
320 else if (zs->which == Z_RPNStructure_simple)
322 if (zs->u.simple->which == Z_Operand_APT)
324 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
326 if (zapt->term->which == Z_Term_general)
328 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
329 zapt->term->u.general->len,
330 zapt->term->u.general->buf);
334 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
336 zlog_attributes (zapt, level+2, ast);
338 else if (zs->u.simple->which == Z_Operand_resultSetId)
340 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
341 zs->u.simple->u.resultSetId);
344 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
347 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
350 void log_rpn_query (Z_RPNQuery *rpn)
355 attrset = oid_getentbyoid (rpn->attributeSetId);
358 ast = attrset->value;
359 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
364 yaz_log (LOG_LOG, "RPN query. Unknown type");
366 zlog_structure (rpn->RPNStructure, 0, ast);
369 void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
372 if (zapt->term->which == Z_Term_general)
374 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
375 zapt->term->u.general->len, zapt->term->u.general->buf);
378 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
379 zlog_attributes (zapt, level+2, ast);