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