2 * Copyright (C) 1995-2001, Index Data
5 * $Id: logrpn.c,v 1.9 2003-01-06 08:20:29 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");
154 sprintf (str, "completeness=Incomplete subfield");
157 sprintf (str, "completeness=Complete subfield");
160 sprintf (str, "completeness=Complete field");
163 sprintf (str, "completeness");
172 sprintf (str + strlen(str), " (%d=%d)", type, value);
174 sprintf (str, "%d=%d", type, value);
178 * zlog_attributes: print attributes of term
180 static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
185 int num_attributes = t->attributes->num_attributes;
187 for (of = 0; of < num_attributes; of++)
189 const char *attset_name = "";
190 Z_AttributeElement *element;
191 element = t->attributes->attributes[of];
192 if (element->attributeSet)
195 attrset = oid_getentbyoid (element->attributeSet);
196 attset_name = attrset->desc;
198 switch (element->which)
200 case Z_AttributeValue_numeric:
201 attrStr (*element->attributeType,
202 *element->value.numeric, ast, str);
203 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
205 case Z_AttributeValue_complex:
206 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
207 level, "", attset_name, *element->attributeType);
208 for (i = 0; i<element->value.complex->num_list; i++)
210 if (element->value.complex->list[i]->which ==
211 Z_StringOrNumeric_string)
212 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
213 element->value.complex->list[i]->u.string);
214 else if (element->value.complex->list[i]->which ==
215 Z_StringOrNumeric_numeric)
216 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
217 *element->value.complex->list[i]->u.numeric);
221 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
222 level, "", attset_name);
227 static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
229 if (zs->which == Z_RPNStructure_complex)
231 Z_Operator *op = zs->u.complex->roperator;
232 const char *rstr = 0;
233 const char *unit = "private";
237 yaz_log (LOG_LOG, "%*.0s and", level, "");
240 yaz_log (LOG_LOG, "%*.0s or", level, "");
242 case Z_Operator_and_not:
243 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
245 case Z_Operator_prox:
246 if (op->u.prox->which == Z_ProximityOperator_known)
248 switch(*op->u.prox->u.known)
250 case Z_ProxUnit_character: unit = "character"; break;
251 case Z_ProxUnit_word: unit = "word"; break;
252 case Z_ProxUnit_sentence: unit = "sentence"; break;
253 case Z_ProxUnit_paragraph: unit = "paragraph"; break;
254 case Z_ProxUnit_section: unit = "section"; break;
255 case Z_ProxUnit_chapter: unit = "chapter"; break;
256 case Z_ProxUnit_document: unit = "document"; break;
257 case Z_ProxUnit_element: unit = "element"; break;
258 case Z_ProxUnit_subelement: unit = "subelement"; break;
259 case Z_ProxUnit_elementType: unit = "elementType"; break;
260 case Z_ProxUnit_byte: unit = "byte"; break;
261 default: unit = "unknown"; break;
264 rstr = relToStr(*op->u.prox->relationType);
265 yaz_log (LOG_LOG, "%*.0s prox excl=%s dist=%d order=%s "
267 level, "", op->u.prox->exclusion ?
268 (*op->u.prox->exclusion ? "T" : "F") : "N",
269 *op->u.prox->distance,
270 *op->u.prox->ordered ? "T" : "F",
271 rstr ? rstr : "unknown",
275 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
278 zlog_structure (zs->u.complex->s1, level+2, ast);
279 zlog_structure (zs->u.complex->s2, level+2, ast);
281 else if (zs->which == Z_RPNStructure_simple)
283 if (zs->u.simple->which == Z_Operand_APT)
285 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
287 switch (zapt->term->which)
290 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
291 zapt->term->u.general->len,
292 zapt->term->u.general->buf);
294 case Z_Term_characterString:
295 yaz_log (LOG_LOG, "%*.0s term '%s' (string)", level, "",
296 zapt->term->u.characterString);
299 yaz_log (LOG_LOG, "%*.0s term '%d' (numeric)", level, "",
300 *zapt->term->u.numeric);
303 yaz_log (LOG_LOG, "%*.0s term (null)", level, "");
306 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
308 zlog_attributes (zapt, level+2, ast);
310 else if (zs->u.simple->which == Z_Operand_resultSetId)
312 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
313 zs->u.simple->u.resultSetId);
316 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
319 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
322 void log_rpn_query (Z_RPNQuery *rpn)
327 attrset = oid_getentbyoid (rpn->attributeSetId);
330 ast = attrset->value;
331 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
336 yaz_log (LOG_LOG, "RPN query. Unknown type");
338 zlog_structure (rpn->RPNStructure, 0, ast);
341 void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
344 if (zapt->term->which == Z_Term_general)
346 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
347 zapt->term->u.general->len, zapt->term->u.general->buf);
350 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
351 zlog_attributes (zapt, level+2, ast);
354 void yaz_log_zquery (Z_Query *q)
356 static int cql_oid[] = {1, 2, 840, 10003, 16, 2, -1};
359 case Z_Query_type_1: case Z_Query_type_101:
360 log_rpn_query (q->u.type_1);
362 case Z_Query_type_104:
363 if (q->u.type_104->which == Z_External_CQL)
364 yaz_log (LOG_LOG, "CQL: %s", q->u.type_104->u.cql);