source: main/tags/2.10/gsdl/src/colservr/browsefilter.cpp@ 32704

Last change on this file since 32704 was 534, checked in by sjboddie, 25 years ago

added gpl notice

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