source: trunk/gsdl/src/colservr/browsefilter.cpp@ 308

Last change on this file since 308 was 259, checked in by sjboddie, 25 years ago

lots of changes to lots of files - getting document action going

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/**********************************************************************
2 *
3 * browsefilter.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: browsefilter.cpp 259 1999-05-10 03:43:49Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.4 1999/05/10 03:43:47 sjboddie
15 lots of changes to lots of files - getting document action going
16
17 Revision 1.3 1999/04/30 02:00:45 sjboddie
18 lots of stuff to do with getting documentaction working
19
20 Revision 1.2 1999/04/19 23:56:05 rjmcnab
21 Finished the gdbm metadata stuff
22
23 Revision 1.1 1999/04/06 22:22:08 rjmcnab
24 Initial revision.
25
26 */
27
28
29#include "browsefilter.h"
30#include "fileutil.h"
31
32
33browsefilterclass::browsefilterclass () {
34 gdbmptr = NULL;
35
36 // -- onePerQuery StartResults integer
37 FilterOption_t filtopt;
38 filtopt.name = "StartResults";
39 filtopt.type = FilterOption_t::integert;
40 filtopt.repeatable = FilterOption_t::onePerQuery;
41 filtopt.defaultValue = "1";
42 filtopt.validValues.push_back("1");
43 filtopt.validValues.push_back("10000");
44 filterOptions["StartResults"] = filtopt;
45
46 // -- onePerQuery EndResults integer
47 filtopt.clear();
48 filtopt.name = "EndResults";
49 filtopt.type = FilterOption_t::integert;
50 filtopt.repeatable = FilterOption_t::onePerQuery;
51 filtopt.defaultValue = "10000";
52 filtopt.validValues.push_back("1");
53 filtopt.validValues.push_back("10000");
54 filterOptions["EndResults"] = filtopt;
55
56 // -- onePerQuery ParentNode string ("" will return the browsing available)
57 filtopt.clear();
58 filtopt.name = "ParentNode";
59 filtopt.type = FilterOption_t::stringt;
60 filtopt.repeatable = FilterOption_t::onePerQuery;
61 filtopt.defaultValue = "";
62 filterOptions["ParentNode"] = filtopt;
63}
64
65browsefilterclass::~browsefilterclass () {
66}
67
68bool browsefilterclass::init (ostream &logout) {
69 outconvertclass text_t2ascii;
70
71 if (!filterclass::init(logout)) return false;
72
73 // get the filename for the database and make sure it exists
74 gdbm_filename = filename_cat(collectdir,"index","text",collection);
75#ifdef _LITTLE_ENDIAN
76 gdbm_filename += ".ldb";
77#else
78 gdbm_filename += ".bdb";
79#endif
80 if (!file_exists(gdbm_filename)) {
81 logout << text_t2ascii
82 << "error: gdbm database \""
83 << gdbm_filename << "\" does not exist\n\n";
84 return false;
85 }
86
87 return true;
88}
89
90void browsefilterclass::filter (const FilterRequest_t &request,
91 FilterResponse_t &response,
92 comerror_t &err, ostream &logout) {
93 int numDocs = 0;
94 outconvertclass text_t2ascii;
95
96 response.clear ();
97 err = noError;
98 if (gdbmptr == NULL) {
99 // most likely a configuration problem
100 logout << text_t2ascii
101 << "configuration error: browsefilter contains a null gdbmclass\n\n";
102 err = configurationError;
103 return;
104 }
105
106 // open the database
107 gdbmptr->setlogout(&logout);
108 if (!gdbmptr->opendatabase (gdbm_filename)) {
109 // most likely a system problem (we have already checked that the
110 // gdbm database exists)
111 logout << text_t2ascii
112 << "system problem: open on gdbm database \""
113 << gdbm_filename << "\" failed\n\n";
114 err = systemProblem;
115 return;
116 }
117
118 // get the browse parameters
119 int startresults = filterOptions["StartResults"].defaultValue.getint();
120 int endresults = filterOptions["EndResults"].defaultValue.getint();
121 text_t parentnode = filterOptions["ParentNode"].defaultValue;
122 OptionValue_tarray::const_iterator options_here = request.filterOptions.begin();
123 OptionValue_tarray::const_iterator options_end = request.filterOptions.end();
124 while (options_here != options_end) {
125 if ((*options_here).name == "StartResults")
126 startresults = (*options_here).value.getint();
127 else if ((*options_here).name == "EndResults")
128 endresults = (*options_here).value.getint();
129 else if ((*options_here).name == "ParentNode")
130 parentnode = (*options_here).value;
131 else {
132 logout << text_t2ascii
133 << "warning: unknown browsefilter option \""
134 << (*options_here).name
135 << "\" ignored.\n\n";
136 }
137
138 options_here++;
139 }
140
141 infodbclass info;
142
143 // translate any ".fc", ".pr" etc. stuff in the parentnode
144 parentnode = gdbmptr->translate_OID (parentnode, info);
145
146 // adjust topmost browsing node
147 if (parentnode.empty()) parentnode = "browse";
148
149 // get the node
150 if ((request.filterResultOptions & FROID) ||
151 (request.filterResultOptions & FRmetadata)) {
152 if (!gdbmptr->getinfo(parentnode, info)) {
153 // didn't find the node
154 logout << text_t2ascii
155 << "warning: lookup for node \"" << parentnode
156 << "\" failed for browsefilter.\n\n";
157 } else {
158 // found the node
159
160 // replace " with the parent node name and split the contains string
161 // into the result set
162 text_tarray resultset;
163 text_t tmptext;
164 text_t &contains = info["contains"];
165 text_t::iterator contains_here = contains.begin();
166 text_t::iterator contains_end = contains.end();
167 while (contains_here != contains_end) {
168 if (*contains_here == '"') tmptext += parentnode;
169 else if (*contains_here == ';') {
170 if (!tmptext.empty()) resultset.push_back (tmptext);
171 tmptext.clear();
172 } else tmptext.push_back(*contains_here);
173
174 contains_here++;
175 }
176 // insert the last result in the set
177 if (!tmptext.empty()) resultset.push_back (tmptext);
178
179 // do an intersection with the input set
180 if (!request.docSet.empty()) {
181 intersect (resultset, request.docSet);
182 }
183
184 // create the response
185 numDocs = resultset.size();
186 int resultnum = 1;
187 ResultDocInfo_t resultdoc;
188 text_tarray::iterator result_here = resultset.begin();
189 text_tarray::iterator result_end = resultset.end();
190
191 while (result_here != result_end) {
192 if (resultnum > endresults) break;
193 if (resultnum >= startresults) {
194 resultdoc.OID = (*result_here);
195 response.docInfo.push_back(resultdoc);
196 }
197
198 resultnum++;
199 result_here++;
200 }
201 }
202 }
203
204 response.numDocs = numDocs;
205 response.isApprox = false;
206}
Note: See TracBrowser for help on using the repository browser.