New result set model and modular ranking system. Moved towards
[idzebra-moved-to-github.git] / index / attribute.c
1 /*
2  * Copyright (C) 1994-1998, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: attribute.c,v $
7  * Revision 1.8  1998-03-05 08:45:11  adam
8  * New result set model and modular ranking system. Moved towards
9  * descent server API. System information stored as "SGML" records.
10  *
11  * Revision 1.7  1997/10/29 12:05:01  adam
12  * Server produces diagnostic "Unsupported Attribute Set" when appropriate.
13  *
14  * Revision 1.6  1997/09/17 12:19:11  adam
15  * Zebra version corresponds to YAZ version 1.4.
16  * Changed Zebra server so that it doesn't depend on global common_resource.
17  *
18  * Revision 1.5  1997/09/05 15:30:08  adam
19  * Changed prototype for chr_map_input - added const.
20  * Added support for C++, headers uses extern "C" for public definitions.
21  *
22  * Revision 1.4  1996/10/29 14:06:48  adam
23  * Include zebrautl.h instead of alexutil.h.
24  *
25  * Revision 1.3  1996/05/09 07:28:54  quinn
26  * Work towards phrases and multiple registers
27  *
28  * Revision 1.2  1995/11/15  19:13:07  adam
29  * Work on record management.
30  *
31  *
32  * This interface is used by other modules (the Z-server in particular)
33  * to normalize the attributes given in queries.
34  */
35
36 #include <stdio.h>
37
38 #include <log.h>
39 #include <res.h>
40 #include <zebrautl.h>
41 #include "zserver.h"
42
43 static void att_loadset(void *p, const char *n, const char *name)
44 {
45     data1_attset *cnew;
46     ZebraHandle zi = p;
47
48     if (!(cnew = data1_read_attset(zi->dh, (char*) name)))
49     {
50         logf(LOG_WARN|LOG_ERRNO, "%s", name);
51         return;
52     }
53     cnew->next = zi->registered_sets;
54     zi->registered_sets = cnew;
55 }
56
57 static void load_atts(ZebraHandle zi)
58 {
59     res_trav(zi->res, "attset", zi, att_loadset);
60 }
61
62 static data1_att *getatt(data1_attset *p, int att)
63 {
64     data1_att *a;
65
66     for (; p; p = p->next)
67     {
68         /* scan local set */
69         for (a = p->atts; a; a = a->next)
70             if (a->value == att)
71                 return a;
72         /* scan included sets */
73         if (p->children && (a = getatt(p->children, att)))
74             return a;
75     }
76     return 0;
77 }
78
79 int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att)
80 {
81     data1_att *r;
82     data1_attset *p;
83
84     if (!zi->registered_sets)
85         load_atts(zi);
86     for (p = zi->registered_sets; p; p = p->next)
87         if (p->reference == set)
88             break;
89     if (!p)
90         return -2;
91     if (!(r = getatt(p, att)))
92         return -1;
93     res->attset_ordinal = r->parent->ordinal;
94     res->local_attributes = r->locals;
95     return 0;
96 }