Bug fixes.
[idzebra-moved-to-github.git] / index / zsets.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: zsets.c,v $
7  * Revision 1.10  1995-10-30 15:08:08  adam
8  * Bug fixes.
9  *
10  * Revision 1.9  1995/10/17  18:02:14  adam
11  * New feature: databases. Implemented as prefix to words in dictionary.
12  *
13  * Revision 1.8  1995/10/10  13:59:25  adam
14  * Function rset_open changed its wflag parameter to general flags.
15  *
16  * Revision 1.7  1995/10/06  14:38:01  adam
17  * New result set method: r_score.
18  * Local no (sysno) and score is transferred to retrieveCtrl.
19  *
20  * Revision 1.6  1995/09/28  09:19:49  adam
21  * xfree/xmalloc used everywhere.
22  * Extract/retrieve method seems to work for text records.
23  *
24  * Revision 1.5  1995/09/27  16:17:32  adam
25  * More work on retrieve.
26  *
27  * Revision 1.4  1995/09/07  13:58:36  adam
28  * New parameter: result-set file descriptor (RSFD) to support multiple
29  * positions within the same result-set.
30  * Boolean operators: and, or, not implemented.
31  * Result-set references.
32  *
33  * Revision 1.3  1995/09/06  16:11:19  adam
34  * Option: only one word key per file.
35  *
36  * Revision 1.2  1995/09/06  10:33:04  adam
37  * More work on present. Some log messages removed.
38  *
39  * Revision 1.1  1995/09/05  15:28:40  adam
40  * More work on search engine.
41  *
42  */
43 #include <stdio.h>
44 #include <assert.h>
45 #include <unistd.h>
46
47 #include "zserver.h"
48 #include <rstemp.h>
49
50 ZServerSet *resultSetAdd (ZServerInfo *zi, const char *name, int ov, RSET rset)
51 {
52     ZServerSet *s;
53
54     for (s = zi->sets; s; s = s->next)
55         if (!strcmp (s->name, name))
56         {
57             if (!ov)
58                 return NULL;
59             rset_delete (s->rset);
60             s->rset = rset;
61             return s;
62         }
63     s = xmalloc (sizeof(*s));
64     s->next = zi->sets;
65     zi->sets = s;
66     s->name = xmalloc (strlen(name)+1);
67     strcpy (s->name, name);
68     s->rset = rset;
69     return s;
70 }
71
72 ZServerSet *resultSetGet (ZServerInfo *zi, const char *name)
73 {
74     ZServerSet *s;
75
76     for (s = zi->sets; s; s = s->next)
77         if (!strcmp (s->name, name))
78             return s;
79     return NULL;
80 }
81
82 ZServerSetSysno *resultSetSysnoGet (ZServerInfo *zi, const char *name, 
83                                     int num, int *positions)
84 {
85     ZServerSet *sset;
86     ZServerSetSysno *sr;
87     RSET rset;
88     int num_i = 0;
89     int position = 0;
90     int psysno = 0;
91     struct it_key key;
92     RSFD rfd;
93
94     if (!(sset = resultSetGet (zi, name)))
95         return NULL;
96     if (!(rset = sset->rset))
97         return NULL;
98     logf (LOG_DEBUG, "resultSetRecordGet");
99     sr = xmalloc (sizeof(*sr) * num);
100     rfd = rset_open (rset, RSETF_READ|RSETF_SORT_RANK);
101     while (rset_read (rset, rfd, &key))
102     {
103         if (key.sysno != psysno)
104         {
105             psysno = key.sysno;
106             position++;
107             assert (num_i < num);
108             if (position == positions[num_i])
109             {
110                 sr[num_i].sysno = psysno;
111                 rset_score (rset, rfd, &sr[num_i].score);
112                 if (++num_i == num)
113                     break;
114             }
115         }
116     }
117     rset_close (rset, rfd);
118     while (num_i < num)
119     {
120         sr[num_i].sysno = 0;
121         num_i++;
122     }
123     return sr;
124 }
125
126 void resultSetSysnoDel (ZServerInfo *zi, ZServerSetSysno *records, int num)
127 {
128     xfree (records);
129 }