1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * queryaction.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: queryaction.cpp 1279 2000-07-12 22:21:53Z sjboddie $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | /*
|
---|
29 | $Log$
|
---|
30 | Revision 1.36.4.1 2000/07/12 22:21:43 sjboddie
|
---|
31 | merged changes to trunk into New_Config_Format branch
|
---|
32 |
|
---|
33 | Revision 1.37 2000/07/05 21:49:34 sjboddie
|
---|
34 | Receptionist now caches collection information to avoid making multiple
|
---|
35 | get_collectinfo calls to collection server
|
---|
36 |
|
---|
37 | Revision 1.36 2000/02/21 21:57:48 sjboddie
|
---|
38 | actions are now configured with gsdlhome
|
---|
39 |
|
---|
40 | Revision 1.35 2000/02/17 02:35:04 sjboddie
|
---|
41 | tidied up search history stuff a bit - replaced strings with macros
|
---|
42 |
|
---|
43 | Revision 1.34 2000/02/15 22:53:52 kjm18
|
---|
44 | search history stuff added.
|
---|
45 |
|
---|
46 | Revision 1.33 2000/01/24 22:57:59 sjboddie
|
---|
47 | fixed bug in cross-collection searching, tidied up a bit
|
---|
48 |
|
---|
49 | Revision 1.32 1999/12/13 02:54:11 davidb
|
---|
50 | Support for cross collection searching (CCS)
|
---|
51 |
|
---|
52 | Revision 1.31 1999/12/05 21:22:33 sjboddie
|
---|
53 | tidied up cross-collection searching a bit
|
---|
54 |
|
---|
55 | Revision 1.30 1999/11/08 20:26:37 sjboddie
|
---|
56 | added multiplevalue option to cgiarginfo
|
---|
57 |
|
---|
58 | Revision 1.29 1999/11/04 20:29:53 sjboddie
|
---|
59 | small change to cross-collection searching
|
---|
60 |
|
---|
61 | Revision 1.28 1999/11/03 22:49:50 sjboddie
|
---|
62 | A few changes to cross-collection searching for fao
|
---|
63 |
|
---|
64 | Revision 1.27 1999/11/01 21:53:27 sjboddie
|
---|
65 | added cross-collection searching capability - still needs lots of
|
---|
66 | work but the basic functionality is there
|
---|
67 |
|
---|
68 | Revision 1.26 1999/10/10 08:14:10 sjboddie
|
---|
69 | - metadata now returns mp rather than array
|
---|
70 | - redesigned browsing support (although it's not finished so
|
---|
71 | won't currently work ;-)
|
---|
72 |
|
---|
73 | Revision 1.25 1999/09/24 04:49:39 sjboddie
|
---|
74 | fixed up the query selection boxes to display properly if there's only
|
---|
75 | a single index/sub-collection
|
---|
76 |
|
---|
77 | Revision 1.24 1999/09/22 03:44:31 sjboddie
|
---|
78 | EndResults query filter option may now take '-1' for 'all'
|
---|
79 |
|
---|
80 | Revision 1.23 1999/09/21 11:34:42 sjboddie
|
---|
81 | added Maxdocs queryfilter option which may be -1 for 'all'
|
---|
82 |
|
---|
83 | Revision 1.22 1999/09/07 23:08:51 rjmcnab
|
---|
84 | removed some compiler warnings
|
---|
85 |
|
---|
86 | Revision 1.21 1999/09/07 04:56:57 sjboddie
|
---|
87 | added GPL notice
|
---|
88 |
|
---|
89 | Revision 1.20 1999/08/25 04:47:55 sjboddie
|
---|
90 | added advanced search option - other minor changes
|
---|
91 |
|
---|
92 | Revision 1.19 1999/08/13 04:17:24 sjboddie
|
---|
93 | small change to do with new collection-level metadata
|
---|
94 |
|
---|
95 | Revision 1.18 1999/08/10 22:46:33 sjboddie
|
---|
96 | changed format option result to QueryResults and added QueryLinks option
|
---|
97 |
|
---|
98 | Revision 1.17 1999/07/30 02:24:42 sjboddie
|
---|
99 | added collectinfo argument to some functions
|
---|
100 |
|
---|
101 | Revision 1.16 1999/07/19 00:16:58 sjboddie
|
---|
102 | no longer display documents that don't match all phrases in query string
|
---|
103 |
|
---|
104 | Revision 1.15 1999/07/16 08:33:36 rjmcnab
|
---|
105 | Changed the logic for getting the results string slightly
|
---|
106 |
|
---|
107 | Revision 1.14 1999/07/16 03:41:29 sjboddie
|
---|
108 | changed isApprox
|
---|
109 |
|
---|
110 | Revision 1.13 1999/07/16 00:19:01 sjboddie
|
---|
111 | some changes to the way quoted queries are handled
|
---|
112 |
|
---|
113 | Revision 1.12 1999/07/09 02:17:55 rjmcnab
|
---|
114 | Setting macros needed for a second query.
|
---|
115 |
|
---|
116 | Revision 1.11 1999/07/07 06:13:10 rjmcnab
|
---|
117 | Added ability to combine two independant queries.
|
---|
118 |
|
---|
119 | Revision 1.10 1999/07/07 05:49:35 sjboddie
|
---|
120 | had another crack at the format string code - created a new formattools
|
---|
121 | module. It can now handle {If} and {Or} statements although there's a
|
---|
122 | bug preventing nested if's and or's.
|
---|
123 |
|
---|
124 | Revision 1.9 1999/07/01 22:48:46 sjboddie
|
---|
125 | had a go at getting a query result format string working
|
---|
126 |
|
---|
127 | Revision 1.8 1999/06/27 22:02:11 sjboddie
|
---|
128 | author is added to queryresults if there is one
|
---|
129 |
|
---|
130 | Revision 1.7 1999/06/26 01:10:18 rjmcnab
|
---|
131 | Made h, i, and n arguments saved in the compressed arguments.
|
---|
132 |
|
---|
133 | Revision 1.6 1999/06/24 05:12:25 sjboddie
|
---|
134 | lots of small changes
|
---|
135 |
|
---|
136 | Revision 1.5 1999/06/16 04:03:48 sjboddie
|
---|
137 | Now sets "cl" arg to "search" when going to a document from a search
|
---|
138 | results page. This allows the close book icon (in hierarchy toc) to
|
---|
139 | take you back to the results page if that's where you came from.
|
---|
140 | If you got to the document page somehow other than from a
|
---|
141 | classification or a search (i.e. if "cl" isn't set) then the close
|
---|
142 | book icon is disabled
|
---|
143 |
|
---|
144 | Revision 1.4 1999/06/16 02:08:38 sjboddie
|
---|
145 | got queryaction working
|
---|
146 |
|
---|
147 | Revision 1.3 1999/03/25 03:06:45 sjboddie
|
---|
148 |
|
---|
149 | altered receptionist slightly so it now passes *collectproto to
|
---|
150 | define_internal_macros and define_external_macros - need it
|
---|
151 | for browseaction
|
---|
152 |
|
---|
153 | Revision 1.2 1999/03/03 20:26:50 rjmcnab
|
---|
154 |
|
---|
155 | Modified stuff.
|
---|
156 |
|
---|
157 | Revision 1.1 1999/02/28 22:45:21 rjmcnab
|
---|
158 |
|
---|
159 | Initial revision.
|
---|
160 |
|
---|
161 | */
|
---|
162 |
|
---|
163 |
|
---|
164 | #include "queryaction.h"
|
---|
165 | #include "querytools.h"
|
---|
166 | #include "formattools.h"
|
---|
167 | #include "cgiutils.h"
|
---|
168 | #include "OIDtools.h"
|
---|
169 | //#include "infodbclass.h"
|
---|
170 | #include "fileutil.h"
|
---|
171 | #include "text_t.h"
|
---|
172 | #include "historydb.h"
|
---|
173 |
|
---|
174 | void colinfo_t::clear () {
|
---|
175 | formatlistptr = NULL;
|
---|
176 | browserptr = NULL;
|
---|
177 | }
|
---|
178 |
|
---|
179 | void QueryResult_t::clear() {
|
---|
180 | doc.clear();
|
---|
181 | collection.clear();
|
---|
182 | }
|
---|
183 |
|
---|
184 | queryaction::queryaction () {
|
---|
185 |
|
---|
186 | recpt = NULL;
|
---|
187 | num_phrases = 0;
|
---|
188 |
|
---|
189 | // this action uses cgi variable "a"
|
---|
190 | cgiarginfo arg_ainfo;
|
---|
191 | arg_ainfo.shortname = "a";
|
---|
192 | arg_ainfo.longname = "action";
|
---|
193 | arg_ainfo.multiplechar = true;
|
---|
194 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
195 | arg_ainfo.argdefault = "q";
|
---|
196 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
197 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
198 |
|
---|
199 | // "b" - 0 = simple, 1 = advanced
|
---|
200 | arg_ainfo.shortname = "b";
|
---|
201 | arg_ainfo.longname = "query mode";
|
---|
202 | arg_ainfo.multiplechar = false;
|
---|
203 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
204 | arg_ainfo.argdefault = "0";
|
---|
205 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
206 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
207 |
|
---|
208 | // "h"
|
---|
209 | arg_ainfo.shortname = "h";
|
---|
210 | arg_ainfo.longname = "main index";
|
---|
211 | arg_ainfo.multiplechar = true;
|
---|
212 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
213 | arg_ainfo.argdefault = "";
|
---|
214 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
215 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
216 |
|
---|
217 | // "h2"
|
---|
218 | arg_ainfo.shortname = "h2";
|
---|
219 | arg_ainfo.longname = "main index for second query";
|
---|
220 | arg_ainfo.multiplechar = true;
|
---|
221 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
222 | arg_ainfo.argdefault = "";
|
---|
223 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
224 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
225 |
|
---|
226 | // "j"
|
---|
227 | arg_ainfo.shortname = "j";
|
---|
228 | arg_ainfo.longname = "sub collection index";
|
---|
229 | arg_ainfo.multiplechar = true;
|
---|
230 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
231 | arg_ainfo.argdefault = "";
|
---|
232 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
233 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
234 |
|
---|
235 | // "j2"
|
---|
236 | arg_ainfo.shortname = "j2";
|
---|
237 | arg_ainfo.longname = "sub collection index for second query";
|
---|
238 | arg_ainfo.multiplechar = true;
|
---|
239 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
240 | arg_ainfo.argdefault = "";
|
---|
241 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
242 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
243 |
|
---|
244 | // "n"
|
---|
245 | arg_ainfo.shortname = "n";
|
---|
246 | arg_ainfo.longname = "language index";
|
---|
247 | arg_ainfo.multiplechar = true;
|
---|
248 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
249 | arg_ainfo.argdefault = "";
|
---|
250 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
251 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
252 |
|
---|
253 | // "n2"
|
---|
254 | arg_ainfo.shortname = "n2";
|
---|
255 | arg_ainfo.longname = "language index for second query";
|
---|
256 | arg_ainfo.multiplechar = true;
|
---|
257 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
258 | arg_ainfo.argdefault = "";
|
---|
259 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
260 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
261 |
|
---|
262 | // "q"
|
---|
263 | arg_ainfo.shortname = "q";
|
---|
264 | arg_ainfo.longname = "query string";
|
---|
265 | arg_ainfo.multiplechar = true;
|
---|
266 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
267 | arg_ainfo.argdefault = "";
|
---|
268 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
269 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
270 |
|
---|
271 | // "q2"
|
---|
272 | arg_ainfo.shortname = "q2";
|
---|
273 | arg_ainfo.longname = "query string for second query";
|
---|
274 | arg_ainfo.multiplechar = true;
|
---|
275 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
276 | arg_ainfo.argdefault = "";
|
---|
277 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
278 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
279 |
|
---|
280 | // "cq2" ""=don't combine, "and", "or", "not"
|
---|
281 | arg_ainfo.shortname = "cq2";
|
---|
282 | arg_ainfo.longname = "combine queries";
|
---|
283 | arg_ainfo.multiplechar = true;
|
---|
284 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
285 | arg_ainfo.argdefault = "";
|
---|
286 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
287 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
288 |
|
---|
289 | // "t" - 1 = ranked 0 = boolean
|
---|
290 | arg_ainfo.shortname = "t";
|
---|
291 | arg_ainfo.longname = "search type";
|
---|
292 | arg_ainfo.multiplechar = false;
|
---|
293 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
294 | arg_ainfo.argdefault = "1";
|
---|
295 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
296 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
297 |
|
---|
298 | // "k"
|
---|
299 | arg_ainfo.shortname = "k";
|
---|
300 | arg_ainfo.longname = "casefolding";
|
---|
301 | arg_ainfo.multiplechar = false;
|
---|
302 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
303 | arg_ainfo.argdefault = "1";
|
---|
304 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
305 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
306 |
|
---|
307 | // "s"
|
---|
308 | arg_ainfo.shortname = "s";
|
---|
309 | arg_ainfo.longname = "stemming";
|
---|
310 | arg_ainfo.multiplechar = false;
|
---|
311 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
312 | arg_ainfo.argdefault ="0";
|
---|
313 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
314 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
315 |
|
---|
316 | // "m"
|
---|
317 | arg_ainfo.shortname = "m";
|
---|
318 | arg_ainfo.longname = "maximum number of documents";
|
---|
319 | arg_ainfo.multiplechar = true;
|
---|
320 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
321 | arg_ainfo.argdefault = "50";
|
---|
322 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
323 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
324 |
|
---|
325 | // "o"
|
---|
326 | arg_ainfo.shortname = "o";
|
---|
327 | arg_ainfo.longname = "hits per page";
|
---|
328 | arg_ainfo.multiplechar = true;
|
---|
329 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
330 | arg_ainfo.argdefault = "20";
|
---|
331 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
332 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
333 |
|
---|
334 | // "r"
|
---|
335 | arg_ainfo.shortname = "r";
|
---|
336 | arg_ainfo.longname = "start results from";
|
---|
337 | arg_ainfo.multiplechar = true;
|
---|
338 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
339 | arg_ainfo.argdefault = "1";
|
---|
340 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
341 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
342 |
|
---|
343 | // "ccs"
|
---|
344 | arg_ainfo.shortname = "ccs";
|
---|
345 | arg_ainfo.longname = "cross collection searching";
|
---|
346 | arg_ainfo.multiplechar = false;
|
---|
347 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
348 | arg_ainfo.argdefault = "0";
|
---|
349 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
350 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
351 |
|
---|
352 | // "ccp"
|
---|
353 | arg_ainfo.shortname = "ccp";
|
---|
354 | arg_ainfo.longname = "cross collection page";
|
---|
355 | arg_ainfo.multiplechar = false;
|
---|
356 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
357 | arg_ainfo.argdefault = "0";
|
---|
358 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
359 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
360 |
|
---|
361 | // "cc"
|
---|
362 | arg_ainfo.shortname = "cc";
|
---|
363 | arg_ainfo.longname = "collections to search";
|
---|
364 | arg_ainfo.multiplechar = true;
|
---|
365 | arg_ainfo.multiplevalue = true;
|
---|
366 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
367 | arg_ainfo.argdefault = "";
|
---|
368 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
369 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
370 |
|
---|
371 | // "hd" history display - search history only displayed when
|
---|
372 | // this var set.
|
---|
373 | arg_ainfo.shortname = "hd";
|
---|
374 | arg_ainfo.longname = "history display";
|
---|
375 | arg_ainfo.multiplechar = false;
|
---|
376 | arg_ainfo.multiplevalue = false;
|
---|
377 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
378 | arg_ainfo.argdefault = "0";
|
---|
379 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
380 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
381 |
|
---|
382 |
|
---|
383 | // "hs" save - set to 1 in query form, so only save when submit
|
---|
384 | // query
|
---|
385 | // 0 = no save 1 = save
|
---|
386 | arg_ainfo.shortname = "hs";
|
---|
387 | arg_ainfo.longname = "history save";
|
---|
388 | arg_ainfo.multiplechar = false;
|
---|
389 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
390 | arg_ainfo.argdefault = "0";
|
---|
391 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
392 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
393 |
|
---|
394 |
|
---|
395 | // "hcl" compress the list (show only the last 5)
|
---|
396 | // 0 = expand, 1 = compress
|
---|
397 |
|
---|
398 | arg_ainfo.shortname = "hcl";
|
---|
399 | arg_ainfo.longname = "history compress list";
|
---|
400 | arg_ainfo.multiplechar = false;
|
---|
401 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
402 | arg_ainfo.argdefault = "1";
|
---|
403 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
404 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
405 |
|
---|
406 |
|
---|
407 |
|
---|
408 | }
|
---|
409 |
|
---|
410 | void queryaction::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
411 | action::configure (key, cfgline);
|
---|
412 | }
|
---|
413 |
|
---|
414 | bool queryaction::init (ostream &logout) {
|
---|
415 | return action::init (logout);
|
---|
416 | }
|
---|
417 |
|
---|
418 | bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
|
---|
419 | ostream &logout) {
|
---|
420 |
|
---|
421 | // check t argument
|
---|
422 | int arg_t = args.getintarg("t");
|
---|
423 | if (arg_t != 0 && arg_t != 1) {
|
---|
424 | logout << "Warning: \"t\" argument out of range (" << arg_t << ")\n";
|
---|
425 | cgiarginfo *tinfo = argsinfo.getarginfo ("t");
|
---|
426 | if (tinfo != NULL) args["t"] = tinfo->argdefault;
|
---|
427 | }
|
---|
428 |
|
---|
429 | // check k argument
|
---|
430 | int arg_k = args.getintarg("k");
|
---|
431 | if (arg_k != 0 && arg_k != 1) {
|
---|
432 | logout << "Warning: \"k\" argument out of range (" << arg_k << ")\n";
|
---|
433 | cgiarginfo *kinfo = argsinfo.getarginfo ("k");
|
---|
434 | if (kinfo != NULL) args["k"] = kinfo->argdefault;
|
---|
435 | }
|
---|
436 |
|
---|
437 | // check s argument
|
---|
438 | int arg_s = args.getintarg("s");
|
---|
439 | if (arg_s != 0 && arg_s != 1) {
|
---|
440 | logout << "Warning: \"s\" argument out of range (" << arg_s << ")\n";
|
---|
441 | cgiarginfo *sinfo = argsinfo.getarginfo ("s");
|
---|
442 | if (sinfo != NULL) args["s"] = sinfo->argdefault;
|
---|
443 | }
|
---|
444 |
|
---|
445 | // check m argument
|
---|
446 | int arg_m = args.getintarg("m");
|
---|
447 | if (arg_m < -1) {
|
---|
448 | logout << "Warning: \"m\" argument less than -1 (" << arg_m << ")\n";
|
---|
449 | cgiarginfo *minfo = argsinfo.getarginfo ("m");
|
---|
450 | if (minfo != NULL) args["m"] = minfo->argdefault;
|
---|
451 | }
|
---|
452 |
|
---|
453 | // check o argument
|
---|
454 | int arg_o = args.getintarg("o");
|
---|
455 | if (arg_o < -1) {
|
---|
456 | logout << "Warning: \"o\" argument less than -1 (" << arg_o << ")\n";
|
---|
457 | cgiarginfo *oinfo = argsinfo.getarginfo ("o");
|
---|
458 | if (oinfo != NULL) args["o"] = oinfo->argdefault;
|
---|
459 | }
|
---|
460 |
|
---|
461 | // check r argument
|
---|
462 | int arg_r = args.getintarg("r");
|
---|
463 | if (arg_r < 1) {
|
---|
464 | logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";
|
---|
465 | cgiarginfo *rinfo = argsinfo.getarginfo ("r");
|
---|
466 | if (rinfo != NULL) args["r"] = rinfo->argdefault;
|
---|
467 | }
|
---|
468 | //check hd argument
|
---|
469 | int arg_hd = args.getintarg("hd");
|
---|
470 | if (arg_hd !=0 && arg_hd !=1) {
|
---|
471 | logout << "Warning: \"hd\" argument out of range (" << arg_hd << ")\n";
|
---|
472 | cgiarginfo *hdinfo = argsinfo.getarginfo ("hd");
|
---|
473 | if (hdinfo != NULL) args["hd"] = hdinfo->argdefault;
|
---|
474 | }
|
---|
475 | //check hs argument
|
---|
476 | int arg_hs = args.getintarg("hs");
|
---|
477 | if (arg_hs !=0 && arg_hs !=1) {
|
---|
478 | logout << "Warning: \"hs\" argument out of range (" << arg_hs << ")\n";
|
---|
479 | cgiarginfo *hsinfo = argsinfo.getarginfo ("hs");
|
---|
480 | if (hsinfo != NULL) args["hs"] = hsinfo->argdefault;
|
---|
481 | }
|
---|
482 |
|
---|
483 | // chech hcl argument
|
---|
484 | int arg_hcl = args.getintarg("hcl");
|
---|
485 | if (arg_hcl !=0 && arg_hcl !=1) {
|
---|
486 | logout << "Warning: \"hcl\" argument out of range (" << arg_hcl << ")\n";
|
---|
487 | cgiarginfo *hclinfo = argsinfo.getarginfo ("hcl");
|
---|
488 | if (hclinfo != NULL) args["hcl"] = hclinfo->argdefault;
|
---|
489 | }
|
---|
490 |
|
---|
491 | return true;
|
---|
492 | }
|
---|
493 |
|
---|
494 | void queryaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
495 | response_t &response, text_t &response_data,
|
---|
496 | ostream &/*logout*/) {
|
---|
497 | response = content;
|
---|
498 | response_data = "text/html";
|
---|
499 | }
|
---|
500 |
|
---|
501 | void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
502 | recptprotolistclass * /*protos*/,
|
---|
503 | ostream &/*logout*/) {
|
---|
504 |
|
---|
505 | // define_internal_macros sets the following macros:
|
---|
506 |
|
---|
507 | // _quotedquery_ the part of the query string that was quoted for post-processing
|
---|
508 |
|
---|
509 |
|
---|
510 |
|
---|
511 | // The following macros are set later (in define_query_macros) as they can't be set until
|
---|
512 | // the query has been done.
|
---|
513 |
|
---|
514 | // _freqmsg_ the term frequency string
|
---|
515 |
|
---|
516 | // _resultline_ the "x documents matched the query" string
|
---|
517 |
|
---|
518 | // _prevfirst_ these are used when setting up the links to previous/next
|
---|
519 | // _prevlast_ pages of results (_thisfirst_ and _thislast_ are used to set
|
---|
520 | // _nextfirst_ the 'results x-x for query: xxxx' string in the title bar)
|
---|
521 | // _nextlast_
|
---|
522 | // _thisfirst_
|
---|
523 | // _thislast_
|
---|
524 |
|
---|
525 |
|
---|
526 | // get the quoted bits of the query string and set _quotedquery_
|
---|
527 | text_tarray phrases;
|
---|
528 | get_phrases (args["q"], phrases);
|
---|
529 | num_phrases = phrases.size();
|
---|
530 | text_tarray::const_iterator phere = phrases.begin();
|
---|
531 | text_tarray::const_iterator pend = phrases.end();
|
---|
532 | bool first = true;
|
---|
533 | text_t quotedquery;
|
---|
534 | while (phere != pend) {
|
---|
535 | if (!first)
|
---|
536 | if ((phere +1) == pend) quotedquery += " and ";
|
---|
537 | else quotedquery += ", ";
|
---|
538 |
|
---|
539 | quotedquery += "\"" + *phere + "\"";
|
---|
540 | first = false;
|
---|
541 | phere ++;
|
---|
542 | }
|
---|
543 | if (args.getintarg("s")) quotedquery += "_textstemon_";
|
---|
544 | disp.setmacro ("quotedquery", "query", quotedquery);
|
---|
545 | }
|
---|
546 |
|
---|
547 | // sets the selection box macros _hselection_, _jselection_, and _nselection_.
|
---|
548 | void queryaction::set_option_macro (const text_t ¯oname, text_t current_value,
|
---|
549 | const FilterOption_t &option, displayclass &disp) {
|
---|
550 |
|
---|
551 | if (option.validValues.empty()) return;
|
---|
552 | else if (option.validValues.size() == 1) {
|
---|
553 | disp.setmacro (macroname + "selection", "Global", "_" + option.defaultValue + "_");
|
---|
554 | return;
|
---|
555 | }
|
---|
556 | if (option.validValues.size() < 2) return;
|
---|
557 |
|
---|
558 | text_t macrovalue = "<select name=\"" + macroname + "\">\n";
|
---|
559 |
|
---|
560 | if (current_value.empty()) current_value = option.defaultValue;
|
---|
561 |
|
---|
562 | text_tarray::const_iterator thisvalue = option.validValues.begin();
|
---|
563 | text_tarray::const_iterator endvalue = option.validValues.end();
|
---|
564 |
|
---|
565 | while (thisvalue != endvalue) {
|
---|
566 | macrovalue += "<option value=\"" + *thisvalue + "\"";
|
---|
567 | if (*thisvalue == current_value)
|
---|
568 | macrovalue += " selected";
|
---|
569 | macrovalue += ">_" + *thisvalue + "_\n";
|
---|
570 | thisvalue ++;
|
---|
571 | }
|
---|
572 | macrovalue += "</select>\n";
|
---|
573 | disp.setmacro (macroname + "selection", "Global", macrovalue);
|
---|
574 | }
|
---|
575 |
|
---|
576 | void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args,
|
---|
577 | recptprotolistclass *protos, ostream &logout) {
|
---|
578 |
|
---|
579 | // define_external_macros sets the following macros:
|
---|
580 |
|
---|
581 | // some or all of these may not be required to be set
|
---|
582 | // _hselection_, _h2selection_ the selection box for the main part of the index
|
---|
583 | // _jselection_, _j2selection_ the selection box for the subcollection part of the index
|
---|
584 | // _nselection_, _n2selection_ the selection box for the language part of the index
|
---|
585 | // _cq2selection the selection box for combining two queries
|
---|
586 |
|
---|
587 |
|
---|
588 | // can't do anything if collectproto is null (i.e. no collection was specified)
|
---|
589 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
590 | if (collectproto == NULL) return;
|
---|
591 |
|
---|
592 | comerror_t err;
|
---|
593 | InfoFilterOptionsResponse_t response;
|
---|
594 | InfoFilterOptionsRequest_t request;
|
---|
595 | request.filterName = "QueryFilter";
|
---|
596 |
|
---|
597 | collectproto->get_filteroptions (args["c"], request, response, err, logout);
|
---|
598 | if (err == noError) {
|
---|
599 |
|
---|
600 | FilterOption_tmap::const_iterator it;
|
---|
601 | FilterOption_tmap::const_iterator end = response.filterOptions.end();
|
---|
602 |
|
---|
603 | // _hselection_ and _h2selection_ (Index)
|
---|
604 | it = response.filterOptions.find ("Index");
|
---|
605 | if (it != end) set_option_macro ("h", args["h"], (*it).second, disp);
|
---|
606 | if (it != end) set_option_macro ("h2", args["h2"], (*it).second, disp);
|
---|
607 |
|
---|
608 | // _jselection_ and _j2selection_ (Subcollection)
|
---|
609 | it = response.filterOptions.find ("Subcollection");
|
---|
610 | if (it != end) set_option_macro ("j", args["j"], (*it).second, disp);
|
---|
611 | if (it != end) set_option_macro ("j2", args["j2"], (*it).second, disp);
|
---|
612 |
|
---|
613 | // _nselection_ and _n2selection_ (Language)
|
---|
614 | it = response.filterOptions.find ("Language");
|
---|
615 | if (it != end) set_option_macro ("n", args["n"], (*it).second, disp);
|
---|
616 | if (it != end) set_option_macro ("n2", args["n2"], (*it).second, disp);
|
---|
617 |
|
---|
618 | // _cq2selection_ (CombineQuery)
|
---|
619 | it = response.filterOptions.find ("CombineQuery");
|
---|
620 | if (it != end) set_option_macro ("cq2", args["cq2"], (*it).second, disp);
|
---|
621 |
|
---|
622 | // define_history_macros(disp, args, protos, logout);
|
---|
623 | }
|
---|
624 | } // define external macros
|
---|
625 |
|
---|
626 | void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,
|
---|
627 | recptprotolistclass *protos, ostream &logout) {
|
---|
628 |
|
---|
629 | // defines the following macros
|
---|
630 |
|
---|
631 | // _searchhistorylist_
|
---|
632 |
|
---|
633 | text_t historylist;
|
---|
634 | int arghd = args.getintarg("hd");
|
---|
635 | if (arghd != 1) {
|
---|
636 | historylist="";
|
---|
637 | }
|
---|
638 | else {
|
---|
639 | historylist = "<!-- Search History List -->\n";
|
---|
640 |
|
---|
641 | text_t userid = args["z"];
|
---|
642 | text_tarray entries;
|
---|
643 | if (get_history_info (userid, entries, gsdlhome, logout)) {
|
---|
644 | int count = 1;
|
---|
645 | text_tarray::iterator here = entries.begin();
|
---|
646 | text_tarray::iterator end = entries.end();
|
---|
647 | int size=(int)entries.size();
|
---|
648 | if (args["hcl"]==1&&size>5) { // compress the list
|
---|
649 | here = end-5;
|
---|
650 | count=size-4;
|
---|
651 | }
|
---|
652 | historylist += "<table align=center width=500 border=0>\n";
|
---|
653 | historylist += "<tr><td width=300 align=center>";
|
---|
654 | historylist += "<a href=\"_httpclearhistory_\">_textclearhistory_</a></td>\n";
|
---|
655 |
|
---|
656 | if (size>5&&args["hcl"]==1) { //compress the list, show the expand button
|
---|
657 |
|
---|
658 | historylist += "<td><a href=\"_gwcgi_?e=_compressedoptions_&a=q&hcl=0\">_textexpand_</a></td>\n";
|
---|
659 | }
|
---|
660 | else if (size >5 && args["hcl"]==0) { // expand the list, show contract button
|
---|
661 | historylist += "<td><a href=\"_gwcgi_?e=_compressedoptions_&a=q&hcl=1\">_textcontract_</a></td>\n";
|
---|
662 | }
|
---|
663 | historylist += "</table>\n";
|
---|
664 | historylist += "<table align=center width=500 border=1>\n<tr><th colspan=4 align=center>";
|
---|
665 | historylist += "_textsearchhistory_</th></tr>\n";
|
---|
666 | historylist += "<tr><th width=40>#</th>\n<th width=340>_textquery_</th>\n";
|
---|
667 | historylist += "<th width=60>_textresults_</th><th width=60>_textview_</th></tr>\n";
|
---|
668 |
|
---|
669 | while (here !=end ) {
|
---|
670 | text_t c;
|
---|
671 | text_t query;
|
---|
672 | text_t numdocs;
|
---|
673 | text_t cgiargs;
|
---|
674 | text_t userinfo;
|
---|
675 | split_saved_query(*here,c, numdocs, cgiargs);
|
---|
676 | parse_saved_args(cgiargs, "q", query); // get query string out
|
---|
677 | decode_cgi_arg(query); // un cgisafe it
|
---|
678 |
|
---|
679 | format_user_info(cgiargs, userinfo, protos, logout);
|
---|
680 |
|
---|
681 | historylist += "<tr> <td width=40 align=center>"+c+"</td>\n";
|
---|
682 | historylist += "<td width=340 align=left>"+query+"</td><td width=60 align=center>"+numdocs+"</td>\n";
|
---|
683 | historylist += "<td width=60 align=center><a href=\"_gwcgi_?e=_compressedoptions_&";
|
---|
684 | historylist += *here+"\"><img name=\"display\" src=\"_httpicondisplay_\" width=_widthdisplay_ ";
|
---|
685 | historylist += "height=_heightdisplay_ border=\"0\" alt=\"" + userinfo +"\"></a></td></tr>\n";
|
---|
686 | here++;
|
---|
687 | count++;
|
---|
688 | }
|
---|
689 | historylist+="</table>\n\n";
|
---|
690 |
|
---|
691 | } // if
|
---|
692 | else {
|
---|
693 | historylist += "_textnohistory_";
|
---|
694 | }
|
---|
695 | historylist += "<p><! ---- end of history list ----->\n";
|
---|
696 | } // else display list
|
---|
697 | disp.setmacro("searchhistorylist", "query", historylist);
|
---|
698 |
|
---|
699 | } // define history macros
|
---|
700 |
|
---|
701 | void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos,
|
---|
702 | displayclass &disp, outconvertclass &outconvert,
|
---|
703 | ostream &textout, ostream &logout) {
|
---|
704 |
|
---|
705 | ColInfoResponse_t *cinfo = NULL;
|
---|
706 | comerror_t err;
|
---|
707 | InfoFilterOptionsResponse_t fresponse;
|
---|
708 | InfoFilterOptionsRequest_t frequest;
|
---|
709 | frequest.filterName = "QueryFilter";
|
---|
710 |
|
---|
711 | text_t &index = args["h"];
|
---|
712 | text_t &subcollection = args["j"];
|
---|
713 | text_t &language = args["n"];
|
---|
714 |
|
---|
715 | text_tset collections;
|
---|
716 | text_t arg_cc = args["cc"];
|
---|
717 | decode_cgi_arg (arg_cc);
|
---|
718 | splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
|
---|
719 |
|
---|
720 | textout << outconvert << disp << "_query:header_\n"
|
---|
721 | << "<center>_navigationbar_</center><br>\n"
|
---|
722 | << "<form name=QueryForm method=get action=\"_gwcgi_\">\n"
|
---|
723 | << "<input type=hidden name=a value=\"q\">\n"
|
---|
724 | << "<input type=hidden name=e value=\"_compressedoptions_\">\n"
|
---|
725 | << "<input type=hidden name=ccp value=\"1\">\n"
|
---|
726 | << "<center><table width=_pagewidth_><tr valign=top>\n"
|
---|
727 | << "<td>Select collections to search for \"" << args["q"]
|
---|
728 | << "\" <i>(index=" << index << " subcollection=" << subcollection
|
---|
729 | << " language=" << language << ")</i></td>\n"
|
---|
730 | << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n"
|
---|
731 | << "</tr></table></center>\n"
|
---|
732 | << "<center><table width=_pagewidth_>\n"
|
---|
733 | << "<tr><td>\n";
|
---|
734 |
|
---|
735 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
736 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
737 | while (rprotolist_here != rprotolist_end) {
|
---|
738 | if ((*rprotolist_here).p != NULL) {
|
---|
739 |
|
---|
740 | text_tarray collist;
|
---|
741 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
742 | if (err == noError) {
|
---|
743 | text_tarray::iterator collist_here = collist.begin();
|
---|
744 | text_tarray::iterator collist_end = collist.end();
|
---|
745 | while (collist_here != collist_end) {
|
---|
746 |
|
---|
747 | cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
748 | // if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) {
|
---|
749 | if (cinfo != NULL && (cinfo->buildDate > 0)) {
|
---|
750 |
|
---|
751 | (*rprotolist_here).p->get_filteroptions (*collist_here, frequest, fresponse, err, logout);
|
---|
752 | if (err == noError) {
|
---|
753 |
|
---|
754 | FilterOption_tmap::const_iterator it;
|
---|
755 | FilterOption_tmap::const_iterator end = fresponse.filterOptions.end();
|
---|
756 | if (!index.empty()) {
|
---|
757 | it = fresponse.filterOptions.find ("Index");
|
---|
758 | if (it == end) {collist_here ++; continue;}
|
---|
759 | text_tarray::const_iterator there = (*it).second.validValues.begin();
|
---|
760 | text_tarray::const_iterator tend = (*it).second.validValues.end();
|
---|
761 | while (there != tend) {
|
---|
762 | if (*there == index) break;
|
---|
763 | there ++;
|
---|
764 | }
|
---|
765 | if (there == tend) {collist_here++; continue;}
|
---|
766 | }
|
---|
767 | if (!subcollection.empty()) {
|
---|
768 | it = fresponse.filterOptions.find ("Subcollection");
|
---|
769 | if (it == end) {collist_here++; continue;}
|
---|
770 | text_tarray::const_iterator there = (*it).second.validValues.begin();
|
---|
771 | text_tarray::const_iterator tend = (*it).second.validValues.end();
|
---|
772 | while (there != tend) {
|
---|
773 | if (*there == subcollection) break;
|
---|
774 | there ++;
|
---|
775 | }
|
---|
776 | if (there == tend) {collist_here++; continue;}
|
---|
777 | }
|
---|
778 | if (!language.empty()) {
|
---|
779 | it = fresponse.filterOptions.find ("Language");
|
---|
780 | if (it == end) {collist_here++; continue;}
|
---|
781 | text_tarray::const_iterator there = (*it).second.validValues.begin();
|
---|
782 | text_tarray::const_iterator tend = (*it).second.validValues.end();
|
---|
783 | while (there != tend) {
|
---|
784 | if (*there == language) break;
|
---|
785 | there ++;
|
---|
786 | }
|
---|
787 | if (there == tend) {collist_here++; continue;}
|
---|
788 | }
|
---|
789 |
|
---|
790 | // we've got a matching collection
|
---|
791 | textout << "<input type=checkbox";
|
---|
792 |
|
---|
793 | text_tset::const_iterator t = collections.find (*collist_here);
|
---|
794 | if (t != collections.end()) textout << " checked";
|
---|
795 |
|
---|
796 | textout << outconvert
|
---|
797 | << " name=cc value=\"" << *collist_here << "\">";
|
---|
798 |
|
---|
799 | if (!cinfo->collectionmeta["collectionname"].empty())
|
---|
800 | textout << outconvert << disp << cinfo->collectionmeta["collectionname"];
|
---|
801 | else
|
---|
802 | textout << outconvert << *collist_here;
|
---|
803 |
|
---|
804 | textout << "<br>\n";
|
---|
805 |
|
---|
806 | }
|
---|
807 | }
|
---|
808 | collist_here ++;
|
---|
809 | }
|
---|
810 | }
|
---|
811 | }
|
---|
812 | rprotolist_here ++;
|
---|
813 | }
|
---|
814 | textout << outconvert << disp
|
---|
815 | << "</td></tr></table></center>\n"
|
---|
816 | << "</form>\n"
|
---|
817 | << "_query:footer_\n";
|
---|
818 |
|
---|
819 | }
|
---|
820 |
|
---|
821 | bool queryaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
822 | browsermapclass *browsers, displayclass &disp,
|
---|
823 | outconvertclass &outconvert, ostream &textout,
|
---|
824 | ostream &logout) {
|
---|
825 |
|
---|
826 | if (recpt == NULL) {
|
---|
827 | logout << "ERROR (queryaction::do_action): This action does not contain information\n"
|
---|
828 | << " about any receptionists. The method set_receptionist was probably\n"
|
---|
829 | << " not called from the module which instantiated this action.\n";
|
---|
830 | return true;
|
---|
831 | }
|
---|
832 |
|
---|
833 |
|
---|
834 | if (args["ccs"] == "1") {
|
---|
835 | if (!args["cc"].empty()) {
|
---|
836 | // query the selected collections
|
---|
837 | text_t::const_iterator b = args["cc"].begin();
|
---|
838 | text_t::const_iterator e = args["cc"].end();
|
---|
839 | if (findchar (b, e, ',') != e) {
|
---|
840 | if (!search_multiple_collections (args, protos, browsers, disp, outconvert,
|
---|
841 | textout, logout)) return false;
|
---|
842 | return true;
|
---|
843 | } else {
|
---|
844 | if (!search_single_collection (args, args["cc"], protos, browsers, disp,
|
---|
845 | outconvert, textout, logout)) return false;
|
---|
846 | return true;
|
---|
847 | }
|
---|
848 | }
|
---|
849 | }
|
---|
850 |
|
---|
851 | // simply query the current collection
|
---|
852 | if (!search_single_collection (args, args["c"], protos, browsers, disp,
|
---|
853 | outconvert, textout, logout)) return false;
|
---|
854 | return true;
|
---|
855 | }
|
---|
856 |
|
---|
857 | bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos,
|
---|
858 | browsermapclass *browsers, displayclass &disp,
|
---|
859 | outconvertclass &outconvert, ostream &textout,
|
---|
860 | ostream &logout) {
|
---|
861 |
|
---|
862 | text_tarray collections;
|
---|
863 |
|
---|
864 | text_t arg_cc = args["cc"];
|
---|
865 | decode_cgi_arg (arg_cc);
|
---|
866 | splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
|
---|
867 |
|
---|
868 | if (collections.empty()) {
|
---|
869 | logout << "queryaction::search_multiple_collections: No collections "
|
---|
870 | << "set for doing multiple query - will search current collection\n";
|
---|
871 | textout << outconvert << disp << "_query:textwarningnocollections_\n";
|
---|
872 | return search_single_collection (args, args["c"], protos, browsers, disp,
|
---|
873 | outconvert, textout, logout);
|
---|
874 | }
|
---|
875 |
|
---|
876 | // queryaction uses "VList" browser to display results,
|
---|
877 | // a queries clasification is "Search"
|
---|
878 | text_t browsertype = "VList";
|
---|
879 | text_t classification = "Search";
|
---|
880 |
|
---|
881 | QueryResult_tset results;
|
---|
882 | map<text_t, colinfo_t, lttext_t> colinfomap;
|
---|
883 |
|
---|
884 | ColInfoResponse_t *cinfo = NULL;
|
---|
885 | comerror_t err;
|
---|
886 | FilterRequest_t request;
|
---|
887 | FilterResponse_t response;
|
---|
888 | request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking;
|
---|
889 | text_t formattedstring = args["q"];
|
---|
890 | text_t freqmsg = "_textfreqmsg1_";
|
---|
891 | int numdocs = 0;
|
---|
892 | isapprox isApprox = Exact;
|
---|
893 |
|
---|
894 | format_querystring (formattedstring, args.getintarg("b"));
|
---|
895 | set_queryfilter_options (request, formattedstring, args);
|
---|
896 |
|
---|
897 | // need to retrieve maxdocs matches for each collection
|
---|
898 | // (will eventually want to tidy this up, do so caching etc.)
|
---|
899 | OptionValue_t option;
|
---|
900 | option.name = "StartResults";
|
---|
901 | option.value = "1";
|
---|
902 | request.filterOptions.push_back (option);
|
---|
903 |
|
---|
904 | option.name = "EndResults";
|
---|
905 | option.value = args["m"];
|
---|
906 | request.filterOptions.push_back (option);
|
---|
907 |
|
---|
908 | text_tarray::iterator col_here = collections.begin();
|
---|
909 | text_tarray::iterator col_end = collections.end();
|
---|
910 |
|
---|
911 | map<text_t, int, lttext_t> termfreqs;
|
---|
912 | while (col_here != col_end) {
|
---|
913 |
|
---|
914 | request.fields.erase (request.fields.begin(), request.fields.end());
|
---|
915 | request.getParents = false;
|
---|
916 |
|
---|
917 | recptproto *collectproto = protos->getrecptproto (*col_here, logout);
|
---|
918 | if (collectproto == NULL) {
|
---|
919 | logout << outconvert << "queryaction::search_multiple_collections: " << *col_here
|
---|
920 | << " collection has a NULL collectproto, ignoring\n";
|
---|
921 | col_here ++;
|
---|
922 | continue;
|
---|
923 | }
|
---|
924 | cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
|
---|
925 | if (cinfo == NULL) {
|
---|
926 | logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL\n";
|
---|
927 | col_here ++;
|
---|
928 | continue;
|
---|
929 | }
|
---|
930 |
|
---|
931 | browserclass *bptr = browsers->getbrowser (browsertype);
|
---|
932 |
|
---|
933 | // get the formatstring if there is one
|
---|
934 | text_t formatstring;
|
---|
935 | if (!get_formatstring (classification, browsertype,
|
---|
936 | cinfo->format, formatstring))
|
---|
937 | formatstring = bptr->get_default_formatstring();
|
---|
938 |
|
---|
939 | bptr->load_metadata_defaults (request.fields);
|
---|
940 |
|
---|
941 | format_t *formatlistptr = new format_t();
|
---|
942 | parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
|
---|
943 |
|
---|
944 | colinfo_t thiscolinfo;
|
---|
945 | thiscolinfo.formatlistptr = formatlistptr;
|
---|
946 | thiscolinfo.browserptr = bptr;
|
---|
947 | colinfomap[*col_here] = thiscolinfo;
|
---|
948 |
|
---|
949 | // do the query
|
---|
950 | collectproto->filter (*col_here, request, response, err, logout);
|
---|
951 | if (err != noError) {
|
---|
952 | outconvertclass text_t2ascii;
|
---|
953 | logout << text_t2ascii
|
---|
954 | << "queryaction::search_multiple_collections: call to QueryFilter failed "
|
---|
955 | << "for " << *col_here << " collection (" << get_comerror_string (err) << ")\n";
|
---|
956 | return false;
|
---|
957 | }
|
---|
958 |
|
---|
959 | if (isApprox == Exact)
|
---|
960 | isApprox = response.isApprox;
|
---|
961 | else if (isApprox == MoreThan)
|
---|
962 | if (response.isApprox == Approximate)
|
---|
963 | isApprox = response.isApprox;
|
---|
964 |
|
---|
965 | TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
|
---|
966 | TermInfo_tarray::const_iterator end_term = response.termInfo.end();
|
---|
967 | while (this_term != end_term) {
|
---|
968 | termfreqs[(*this_term).term] += (*this_term).freq;
|
---|
969 | if ((col_here+1) == col_end) {
|
---|
970 | freqmsg += (*this_term).term + ": " + termfreqs[(*this_term).term];
|
---|
971 | if ((this_term+1) != end_term) freqmsg += ", ";
|
---|
972 | }
|
---|
973 | this_term ++;
|
---|
974 | }
|
---|
975 |
|
---|
976 | if (response.numDocs > 0) {
|
---|
977 | numdocs += response.numDocs;
|
---|
978 |
|
---|
979 | QueryResult_t thisresult;
|
---|
980 | thisresult.collection = *col_here;
|
---|
981 | ResultDocInfo_tarray::iterator doc_here = response.docInfo.begin();
|
---|
982 | ResultDocInfo_tarray::iterator doc_end = response.docInfo.end();
|
---|
983 | while (doc_here != doc_end) {
|
---|
984 | thisresult.doc = *doc_here;
|
---|
985 | results.insert (thisresult);
|
---|
986 | doc_here ++;
|
---|
987 | }
|
---|
988 | }
|
---|
989 | col_here ++;
|
---|
990 | }
|
---|
991 |
|
---|
992 | disp.setmacro ("freqmsg", "query", freqmsg);
|
---|
993 |
|
---|
994 | text_t resline;
|
---|
995 | if (num_phrases > 0) isApprox = Exact;
|
---|
996 | if (isApprox == Approximate) resline = "_textapprox_";
|
---|
997 | else if (isApprox == MoreThan) resline = "_textmorethan_";
|
---|
998 |
|
---|
999 | if (numdocs == 0) resline = "_textnodocs_";
|
---|
1000 | else if (numdocs == 1) resline += "_text1doc_";
|
---|
1001 | else resline += text_t(numdocs) + " _textlotsdocs_";
|
---|
1002 | disp.setmacro("resultline", "query", resline);
|
---|
1003 |
|
---|
1004 | QueryResult_tset::iterator res_here = results.begin();
|
---|
1005 | QueryResult_tset::iterator res_end = results.end();
|
---|
1006 | text_tset metadata; // empty !!
|
---|
1007 | bool getParents = false; // don't care !!
|
---|
1008 | recptproto *collectproto = NULL;
|
---|
1009 | bool use_table;
|
---|
1010 | ResultDocInfo_t thisdoc;
|
---|
1011 | format_t *formatlistptr = NULL;
|
---|
1012 | browserclass *browserptr = NULL;
|
---|
1013 |
|
---|
1014 | int maxdocs = args.getintarg("m");
|
---|
1015 | int firstdoc = args.getintarg("r");
|
---|
1016 | int hitsperpage = args.getintarg("o");
|
---|
1017 | if (numdocs > maxdocs) numdocs = maxdocs;
|
---|
1018 | if (hitsperpage == -1) hitsperpage = numdocs;
|
---|
1019 |
|
---|
1020 | // set up _thisfirst_ and _thislast_ macros
|
---|
1021 | disp.setmacro ("thisfirst", "query", firstdoc);
|
---|
1022 | int thislast = firstdoc + (hitsperpage - 1);
|
---|
1023 | if (thislast > numdocs) thislast = numdocs;
|
---|
1024 | disp.setmacro ("thislast", "query", thislast);
|
---|
1025 |
|
---|
1026 | // set up _prevfirst_ and _prevlast_ macros
|
---|
1027 | if (firstdoc > 1) {
|
---|
1028 | disp.setmacro ("prevlast", "query", firstdoc - 1);
|
---|
1029 | int prevfirst = firstdoc - hitsperpage;
|
---|
1030 | if (prevfirst < 1) prevfirst = 1;
|
---|
1031 | disp.setmacro ("prevfirst", "query", prevfirst);
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | // set up _nextfirst_ and _nextlast_ macros
|
---|
1035 | if (thislast < numdocs) {
|
---|
1036 | disp.setmacro ("nextfirst", "query", thislast + 1);
|
---|
1037 | int nextlast = thislast + hitsperpage;
|
---|
1038 | if (nextlast > numdocs) nextlast = numdocs;
|
---|
1039 | disp.setmacro ("nextlast", "query", nextlast);
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | textout << outconvert << disp << "_query:header_\n"
|
---|
1043 | << "_query:content_";
|
---|
1044 |
|
---|
1045 | int count = 1;
|
---|
1046 |
|
---|
1047 | // output results
|
---|
1048 | while (res_here != res_end) {
|
---|
1049 | if (count < firstdoc) {count ++; res_here ++; continue;}
|
---|
1050 | if (count > thislast) break;
|
---|
1051 | formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
|
---|
1052 | browserptr = colinfomap[(*res_here).collection].browserptr;
|
---|
1053 | thisdoc = (*res_here).doc;
|
---|
1054 | use_table = is_table_content (formatlistptr);
|
---|
1055 | browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0,
|
---|
1056 | formatlistptr, use_table, metadata, getParents,
|
---|
1057 | collectproto, disp, outconvert, textout, logout);
|
---|
1058 | // textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
|
---|
1059 | res_here ++;
|
---|
1060 | count ++;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | textout << outconvert << disp << "_query:footer_";
|
---|
1064 |
|
---|
1065 | // clean up the format_t pointers
|
---|
1066 | map<text_t, colinfo_t, lttext_t>::iterator here = colinfomap.begin();
|
---|
1067 | map<text_t, colinfo_t, lttext_t>::iterator end = colinfomap.end();
|
---|
1068 | while (here != end) {
|
---|
1069 | delete ((*here).second.formatlistptr);
|
---|
1070 | here ++;
|
---|
1071 | }
|
---|
1072 | return true;
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | bool queryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
|
---|
1076 | recptprotolistclass *protos, browsermapclass *browsers,
|
---|
1077 | displayclass &disp, outconvertclass &outconvert,
|
---|
1078 | ostream &textout, ostream &logout) {
|
---|
1079 |
|
---|
1080 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
1081 | if (collectproto == NULL) {
|
---|
1082 | logout << outconvert << "queryaction::search_single_collection: " << collection
|
---|
1083 | << " collection has a NULL collectproto\n";
|
---|
1084 | return false;
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | // queryaction uses "VList" browser to display results,
|
---|
1088 | // a queries clasification is "Search"
|
---|
1089 | text_t browsertype = "VList";
|
---|
1090 | text_t classification = "Search";
|
---|
1091 |
|
---|
1092 | comerror_t err;
|
---|
1093 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
1094 |
|
---|
1095 | if (cinfo == NULL) {
|
---|
1096 | logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
|
---|
1097 | return false;
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | browserclass *bptr = browsers->getbrowser (browsertype);
|
---|
1101 |
|
---|
1102 | // get the formatstring if there is one
|
---|
1103 | text_t formatstring;
|
---|
1104 | if (!get_formatstring (classification, browsertype,
|
---|
1105 | cinfo->format, formatstring))
|
---|
1106 | formatstring = bptr->get_default_formatstring();
|
---|
1107 |
|
---|
1108 | FilterRequest_t request;
|
---|
1109 | FilterResponse_t response;
|
---|
1110 | bptr->set_filter_options (request, args);
|
---|
1111 | bptr->load_metadata_defaults (request.fields);
|
---|
1112 |
|
---|
1113 | format_t *formatlistptr = new format_t();
|
---|
1114 | parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
|
---|
1115 |
|
---|
1116 | // do the query
|
---|
1117 | request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
|
---|
1118 | text_t formattedstring = args["q"];
|
---|
1119 | if (!combine_query (args["z"], formattedstring, gsdlhome)) {
|
---|
1120 | args["q"]=formattedstring;
|
---|
1121 | }
|
---|
1122 | format_querystring (formattedstring, args.getintarg("b"));
|
---|
1123 | set_queryfilter_options (request, formattedstring, args);
|
---|
1124 | collectproto->filter (collection, request, response, err, logout);
|
---|
1125 | if (err != noError) {
|
---|
1126 | outconvertclass text_t2ascii;
|
---|
1127 | logout << text_t2ascii
|
---|
1128 | << "queryaction::search_single_collections: call to QueryFilter failed "
|
---|
1129 | << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
|
---|
1130 | return false;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 |
|
---|
1134 | define_query_macros (args, disp, response);
|
---|
1135 |
|
---|
1136 | // save the query if appropriate
|
---|
1137 | if (!save_search_history(args, response))
|
---|
1138 | logout << "save failed";
|
---|
1139 |
|
---|
1140 | define_history_macros (disp, args, protos, logout);
|
---|
1141 |
|
---|
1142 | textout << outconvert << disp << "_query:header_\n"
|
---|
1143 | << "_query:content_";
|
---|
1144 |
|
---|
1145 | // output the results
|
---|
1146 | bool use_table = is_table_content (formatlistptr);
|
---|
1147 | bptr->output_section_group (response, args, collection, 0, formatlistptr,
|
---|
1148 | use_table, request.fields, request.getParents,
|
---|
1149 | collectproto, disp, outconvert, textout, logout);
|
---|
1150 |
|
---|
1151 |
|
---|
1152 | textout << outconvert << disp << "_query:footer_";
|
---|
1153 |
|
---|
1154 | delete (formatlistptr);
|
---|
1155 |
|
---|
1156 | return true;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | // define_query_macros sets the macros that couldn't be set until the
|
---|
1160 | // query had been done. Those macros are _freqmsg_, _quotedquery_,
|
---|
1161 | // _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
|
---|
1162 | // _thisfirst_, and _thislast_
|
---|
1163 | void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
|
---|
1164 | const FilterResponse_t &response) {
|
---|
1165 |
|
---|
1166 | // set up _freqmsg_ and _quotedquery_ macros
|
---|
1167 | text_t freqmsg = "_textfreqmsg1_";
|
---|
1168 | TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
|
---|
1169 | TermInfo_tarray::const_iterator end_term = response.termInfo.end();
|
---|
1170 | while (this_term != end_term) {
|
---|
1171 | freqmsg += (*this_term).term + ": " + (*this_term).freq;
|
---|
1172 | if ((this_term + 1) != end_term)
|
---|
1173 | freqmsg += ", ";
|
---|
1174 | this_term ++;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | disp.setmacro ("freqmsg", "query", freqmsg);
|
---|
1178 |
|
---|
1179 |
|
---|
1180 | // set up _resultline_ macro
|
---|
1181 | text_t resline;
|
---|
1182 | int maxdocs = args.getintarg("m");
|
---|
1183 | int numdocs = response.numDocs;
|
---|
1184 | if (maxdocs == -1) maxdocs = response.numDocs;
|
---|
1185 | isapprox isApprox = response.isApprox;
|
---|
1186 |
|
---|
1187 | // if there were phrases (post-processing) we're not going to include
|
---|
1188 | // those documents that didn't match
|
---|
1189 | if (num_phrases > 0) isApprox = Exact;
|
---|
1190 |
|
---|
1191 | if (isApprox == Approximate) resline = "_textapprox_";
|
---|
1192 | else if (isApprox == MoreThan) resline = "_textmorethan_";
|
---|
1193 |
|
---|
1194 | if (numdocs == 0) resline = "_textnodocs_";
|
---|
1195 | else if (numdocs == 1) resline += "_text1doc_";
|
---|
1196 | else resline += text_t(numdocs) + " _textlotsdocs_";
|
---|
1197 |
|
---|
1198 | disp.setmacro("resultline", "query", resline);
|
---|
1199 |
|
---|
1200 | int firstdoc = args.getintarg("r");
|
---|
1201 | int hitsperpage = args.getintarg("o");
|
---|
1202 | if (hitsperpage == -1) hitsperpage = numdocs;
|
---|
1203 |
|
---|
1204 | // set up _thisfirst_ and _thislast_ macros
|
---|
1205 | disp.setmacro ("thisfirst", "query", firstdoc);
|
---|
1206 | int thislast = firstdoc + (hitsperpage - 1);
|
---|
1207 | if (thislast > numdocs) thislast = numdocs;
|
---|
1208 | disp.setmacro ("thislast", "query", thislast);
|
---|
1209 |
|
---|
1210 | // set up _prevfirst_ and _prevlast_ macros
|
---|
1211 | if (firstdoc > 1) {
|
---|
1212 | disp.setmacro ("prevlast", "query", firstdoc - 1);
|
---|
1213 | int prevfirst = firstdoc - hitsperpage;
|
---|
1214 | if (prevfirst < 1) prevfirst = 1;
|
---|
1215 | disp.setmacro ("prevfirst", "query", prevfirst);
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | // set up _nextfirst_ and _nextlast_ macros
|
---|
1219 | if (thislast < numdocs) {
|
---|
1220 | disp.setmacro ("nextfirst", "query", thislast + 1);
|
---|
1221 | int nextlast = thislast + hitsperpage;
|
---|
1222 | if (nextlast > numdocs) nextlast = numdocs;
|
---|
1223 | disp.setmacro ("nextlast", "query", nextlast);
|
---|
1224 | }
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | bool queryaction::save_search_history (cgiargsclass &args, const FilterResponse_t &response)
|
---|
1228 | {
|
---|
1229 | if (args["q"]=="") return true; // null query, dont save
|
---|
1230 | if (args["hs"]=="0") return true; // only save when submit query
|
---|
1231 |
|
---|
1232 | // get userid
|
---|
1233 | text_t userid = args["z"];
|
---|
1234 |
|
---|
1235 | // the number of docs goes on the front of the query string
|
---|
1236 | int numdocs= response.numDocs;
|
---|
1237 | text_t query = text_t(numdocs);
|
---|
1238 | if (response.isApprox==MoreThan) { // there were more docs found
|
---|
1239 | query.push_back('+');
|
---|
1240 | }
|
---|
1241 | query += "a=q";
|
---|
1242 | query += "&c="+args["c"];
|
---|
1243 | query += "&h="+args["h"];
|
---|
1244 | query += "&t="+args["t"];
|
---|
1245 | query += "&b="+args["b"];
|
---|
1246 | query += "&j="+args["j"];
|
---|
1247 | query += "&n="+args["n"];
|
---|
1248 | query += "&s="+args["s"];
|
---|
1249 | query += "&k="+args["k"];
|
---|
1250 |
|
---|
1251 | text_t qstring = args["q"];
|
---|
1252 | text_t formattedquery =cgi_safe(qstring);
|
---|
1253 | query += "&q="+formattedquery;
|
---|
1254 |
|
---|
1255 | if (set_history_info(userid, query, gsdlhome)) return true;
|
---|
1256 | else return false;
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 |
|
---|
1262 |
|
---|
1263 |
|
---|
1264 |
|
---|