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