2 * Copyright (C) 1995-2003, Index Data
5 * $Id: logrpn.c,v 1.2 2004-09-13 09:23:33 adam Exp $
10 #include <yaz/logrpn.h>
12 static const char *relToStr(int v)
17 case 1: str = "Less than"; break;
18 case 2: str = "Less than or equal"; break;
19 case 3: str = "Equal"; break;
20 case 4: str = "Greater or equal"; break;
21 case 5: str = "Greater than"; break;
22 case 6: str = "Not equal"; break;
23 case 100: str = "Phonetic"; break;
24 case 101: str = "Stem"; break;
25 case 102: str = "Relevance"; break;
26 case 103: str = "AlwaysMatches"; break;
30 static void attrStr (int type, int value, enum oid_value ast, char *str)
45 rstr = relToStr(value);
47 sprintf (str, "relation=%s", rstr);
49 sprintf (str, "relation=%d", value);
55 sprintf (str, "position=First in field");
58 sprintf (str, "position=First in any subfield");
61 sprintf (str, "position=Any position in field");
64 sprintf (str, "position");
71 sprintf (str, "structure=Phrase");
74 sprintf (str, "structure=Word");
77 sprintf (str, "structure=Key");
80 sprintf (str, "structure=Year");
83 sprintf (str, "structure=Date");
86 sprintf (str, "structure=Word list");
89 sprintf (str, "structure=Date (un)");
92 sprintf (str, "structure=Name (norm)");
95 sprintf (str, "structure=Name (un)");
98 sprintf (str, "structure=Structure");
101 sprintf (str, "structure=urx");
104 sprintf (str, "structure=free-form-text");
107 sprintf (str, "structure=document-text");
110 sprintf (str, "structure=local-number");
113 sprintf (str, "structure=string");
116 sprintf (str, "structure=numeric string");
119 sprintf (str, "structure");
126 sprintf (str, "truncation=Right");
129 sprintf (str, "truncation=Left");
132 sprintf (str, "truncation=Left&right");
135 sprintf (str, "truncation=Do not truncate");
138 sprintf (str, "truncation=Process #");
141 sprintf (str, "truncation=re-1");
144 sprintf (str, "truncation=re-2");
147 sprintf (str, "truncation=CCL");
150 sprintf (str, "truncation");
157 sprintf (str, "completeness=Incomplete subfield");
160 sprintf (str, "completeness=Complete subfield");
163 sprintf (str, "completeness=Complete field");
166 sprintf (str, "completeness");
175 sprintf (str + strlen(str), " (%d=%d)", type, value);
177 sprintf (str, "%d=%d", type, value);
181 * zlog_attributes: print attributes of term
183 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
188 int num_attributes = t->attributes->num_attributes;
190 for (of = 0; of < num_attributes; of++)
192 const char *attset_name = "";
193 Z_AttributeElement *element;
194 element = t->attributes->attributes[of];
195 if (element->attributeSet)
198 attrset = oid_getentbyoid (element->attributeSet);
199 attset_name = attrset->desc;
201 switch (element->which)
203 case Z_AttributeValue_numeric:
204 attrStr (*element->attributeType,
205 *element->value.numeric, ast, str);
206 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
208 case Z_AttributeValue_complex:
209 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
210 level, "", attset_name, *element->attributeType);
211 for (i = 0; i<element->value.complex->num_list; i++)
213 if (element->value.complex->list[i]->which ==
214 Z_StringOrNumeric_string)
215 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
216 element->value.complex->list[i]->u.string);
217 else if (element->value.complex->list[i]->which ==
218 Z_StringOrNumeric_numeric)
219 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
220 *element->value.complex->list[i]->u.numeric);
224 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
225 level, "", attset_name);
230 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
232 if (zs->which == Z_RPNStructure_complex)
234 Z_Operator *op = zs->u.complex->roperator;
235 const char *rstr = 0;
236 const char *unit = "private";
240 yaz_log (LOG_LOG, "%*.0s and", level, "");
243 yaz_log (LOG_LOG, "%*.0s or", level, "");
245 case Z_Operator_and_not:
246 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
248 case Z_Operator_prox:
249 if (op->u.prox->which == Z_ProximityOperator_known)
251 switch(*op->u.prox->u.known)
253 case Z_ProxUnit_character: unit = "character"; break;
254 case Z_ProxUnit_word: unit = "word"; break;
255 case Z_ProxUnit_sentence: unit = "sentence"; break;
256 case Z_ProxUnit_paragraph: unit = "paragraph"; break;
257 case Z_ProxUnit_section: unit = "section"; break;
258 case Z_ProxUnit_chapter: unit = "chapter"; break;
259 case Z_ProxUnit_document: unit = "document"; break;
260 case Z_ProxUnit_element: unit = "element"; break;
261 case Z_ProxUnit_subelement: unit = "subelement"; break;
262 case Z_ProxUnit_elementType: unit = "elementType"; break;
263 case Z_ProxUnit_byte: unit = "byte"; break;
264 default: unit = "unknown"; break;
267 rstr = relToStr(*op->u.prox->relationType);
268 yaz_log (LOG_LOG, "%*.0s prox excl=%s dist=%d order=%s "
270 level, "", op->u.prox->exclusion ?
271 (*op->u.prox->exclusion ? "T" : "F") : "N",
272 *op->u.prox->distance,
273 *op->u.prox->ordered ? "T" : "F",
274 rstr ? rstr : "unknown",
278 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
281 zlog_structure (zs->u.complex->s1, level+2, ast);
282 zlog_structure (zs->u.complex->s2, level+2, ast);
284 else if (zs->which == Z_RPNStructure_simple)
286 if (zs->u.simple->which == Z_Operand_APT)
288 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
290 switch (zapt->term->which)
293 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
294 zapt->term->u.general->len,
295 zapt->term->u.general->buf);
297 case Z_Term_characterString:
298 yaz_log (LOG_LOG, "%*.0s term '%s' (string)", level, "",
299 zapt->term->u.characterString);
302 yaz_log (LOG_LOG, "%*.0s term '%d' (numeric)", level, "",
303 *zapt->term->u.numeric);
306 yaz_log (LOG_LOG, "%*.0s term (null)", level, "");
309 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
311 zlog_attributes (zapt, level+2, ast);
313 else if (zs->u.simple->which == Z_Operand_resultSetId)
315 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
316 zs->u.simple->u.resultSetId);
319 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
322 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
325 void log_rpn_query (Z_RPNQuery *rpn)
330 attrset = oid_getentbyoid (rpn->attributeSetId);
333 ast = attrset->value;
334 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
339 yaz_log (LOG_LOG, "RPN query. Unknown type");
341 zlog_structure (rpn->RPNStructure, 0, ast);
344 void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
347 if (zapt->term->which == Z_Term_general)
349 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
350 zapt->term->u.general->len, zapt->term->u.general->buf);
353 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
354 zlog_attributes (zapt, level+2, ast);
357 void yaz_log_zquery (Z_Query *q)
361 case Z_Query_type_1: case Z_Query_type_101:
362 log_rpn_query (q->u.type_1);
365 yaz_log(LOG_LOG, "CCL: %.*s", q->u.type_2->len, q->u.type_2->buf);
367 case Z_Query_type_100:
368 yaz_log(LOG_LOG, "Z39.58: %.*s", q->u.type_100->len,
371 case Z_Query_type_104:
372 if (q->u.type_104->which == Z_External_CQL)
373 yaz_log (LOG_LOG, "CQL: %s", q->u.type_104->u.cql);