source: trunk/gsdl/src/recpt/queryaction.cpp@ 2934

Last change on this file since 2934 was 2934, checked in by sjboddie, 22 years ago

Fixed a minor bug causing "post-processed to find (ignoring word endings)"
to be printed whenever a non-phrase search was done with stemming turned
on.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 48.4 KB
RevLine 
[174]1/**********************************************************************
2 *
3 * queryaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
[533]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.
[174]9 *
[533]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 *
[174]24 *********************************************************************/
25
26#include "queryaction.h"
[275]27#include "querytools.h"
[347]28#include "formattools.h"
[757]29#include "cgiutils.h"
[772]30#include "OIDtools.h"
[928]31//#include "infodbclass.h"
32#include "fileutil.h"
33#include "text_t.h"
34#include "historydb.h"
[1915]35#include "htmlutils.h" // for html_safe in do_action
36#include "gsdltools.h"
[174]37
[757]38void colinfo_t::clear () {
39 formatlistptr = NULL;
40 browserptr = NULL;
41}
42
43void QueryResult_t::clear() {
44 doc.clear();
45 collection.clear();
46}
47
[174]48queryaction::queryaction () {
[403]49
[1270]50 recpt = NULL;
[403]51 num_phrases = 0;
52
[174]53 // this action uses cgi variable "a"
54 cgiarginfo arg_ainfo;
55 arg_ainfo.shortname = "a";
56 arg_ainfo.longname = "action";
57 arg_ainfo.multiplechar = true;
58 arg_ainfo.defaultstatus = cgiarginfo::weak;
59 arg_ainfo.argdefault = "q";
60 arg_ainfo.savedarginfo = cgiarginfo::must;
61 argsinfo.addarginfo (NULL, arg_ainfo);
62
[1915]63 // "ct" - 0 = mg, 1 = mgpp
64 arg_ainfo.shortname = "ct";
65 arg_ainfo.longname = "collection type";
66 arg_ainfo.multiplechar = false;
67 arg_ainfo.defaultstatus = cgiarginfo::weak;
68 arg_ainfo.argdefault = "0";
69 arg_ainfo.savedarginfo = cgiarginfo::must;
70 argsinfo.addarginfo (NULL, arg_ainfo);
71
[470]72 // "b" - 0 = simple, 1 = advanced
73 arg_ainfo.shortname = "b";
74 arg_ainfo.longname = "query mode";
75 arg_ainfo.multiplechar = false;
76 arg_ainfo.defaultstatus = cgiarginfo::weak;
77 arg_ainfo.argdefault = "0";
78 arg_ainfo.savedarginfo = cgiarginfo::must;
79 argsinfo.addarginfo (NULL, arg_ainfo);
80
[174]81 // "h"
82 arg_ainfo.shortname = "h";
83 arg_ainfo.longname = "main index";
84 arg_ainfo.multiplechar = true;
85 arg_ainfo.defaultstatus = cgiarginfo::weak;
86 arg_ainfo.argdefault = "";
[295]87 arg_ainfo.savedarginfo = cgiarginfo::must;
[174]88 argsinfo.addarginfo (NULL, arg_ainfo);
89
[349]90 // "h2"
91 arg_ainfo.shortname = "h2";
92 arg_ainfo.longname = "main index for second query";
93 arg_ainfo.multiplechar = true;
94 arg_ainfo.defaultstatus = cgiarginfo::weak;
95 arg_ainfo.argdefault = "";
96 arg_ainfo.savedarginfo = cgiarginfo::must;
97 argsinfo.addarginfo (NULL, arg_ainfo);
98
[174]99 // "j"
100 arg_ainfo.shortname = "j";
101 arg_ainfo.longname = "sub collection index";
102 arg_ainfo.multiplechar = true;
103 arg_ainfo.defaultstatus = cgiarginfo::weak;
104 arg_ainfo.argdefault = "";
[295]105 arg_ainfo.savedarginfo = cgiarginfo::must;
[174]106 argsinfo.addarginfo (NULL, arg_ainfo);
107
[349]108 // "j2"
109 arg_ainfo.shortname = "j2";
110 arg_ainfo.longname = "sub collection index for second query";
111 arg_ainfo.multiplechar = true;
112 arg_ainfo.defaultstatus = cgiarginfo::weak;
113 arg_ainfo.argdefault = "";
114 arg_ainfo.savedarginfo = cgiarginfo::must;
115 argsinfo.addarginfo (NULL, arg_ainfo);
116
[174]117 // "n"
118 arg_ainfo.shortname = "n";
119 arg_ainfo.longname = "language index";
120 arg_ainfo.multiplechar = true;
121 arg_ainfo.defaultstatus = cgiarginfo::weak;
122 arg_ainfo.argdefault = "";
[295]123 arg_ainfo.savedarginfo = cgiarginfo::must;
[174]124 argsinfo.addarginfo (NULL, arg_ainfo);
125
[349]126 // "n2"
127 arg_ainfo.shortname = "n2";
128 arg_ainfo.longname = "language index for second query";
129 arg_ainfo.multiplechar = true;
130 arg_ainfo.defaultstatus = cgiarginfo::weak;
131 arg_ainfo.argdefault = "";
132 arg_ainfo.savedarginfo = cgiarginfo::must;
133 argsinfo.addarginfo (NULL, arg_ainfo);
134
[1915]135
[174]136 // "q"
137 arg_ainfo.shortname = "q";
138 arg_ainfo.longname = "query string";
139 arg_ainfo.multiplechar = true;
140 arg_ainfo.defaultstatus = cgiarginfo::weak;
141 arg_ainfo.argdefault = "";
142 arg_ainfo.savedarginfo = cgiarginfo::must;
143 argsinfo.addarginfo (NULL, arg_ainfo);
144
[349]145 // "q2"
146 arg_ainfo.shortname = "q2";
147 arg_ainfo.longname = "query string for second query";
148 arg_ainfo.multiplechar = true;
149 arg_ainfo.defaultstatus = cgiarginfo::weak;
150 arg_ainfo.argdefault = "";
151 arg_ainfo.savedarginfo = cgiarginfo::must;
152 argsinfo.addarginfo (NULL, arg_ainfo);
153
[356]154 // "cq2" ""=don't combine, "and", "or", "not"
[349]155 arg_ainfo.shortname = "cq2";
156 arg_ainfo.longname = "combine queries";
157 arg_ainfo.multiplechar = true;
158 arg_ainfo.defaultstatus = cgiarginfo::weak;
159 arg_ainfo.argdefault = "";
160 arg_ainfo.savedarginfo = cgiarginfo::must;
161 argsinfo.addarginfo (NULL, arg_ainfo);
162
[284]163 // "t" - 1 = ranked 0 = boolean
[174]164 arg_ainfo.shortname = "t";
165 arg_ainfo.longname = "search type";
166 arg_ainfo.multiplechar = false;
167 arg_ainfo.defaultstatus = cgiarginfo::weak;
[284]168 arg_ainfo.argdefault = "1";
[174]169 arg_ainfo.savedarginfo = cgiarginfo::must;
170 argsinfo.addarginfo (NULL, arg_ainfo);
171
172 // "k"
173 arg_ainfo.shortname = "k";
174 arg_ainfo.longname = "casefolding";
175 arg_ainfo.multiplechar = false;
176 arg_ainfo.defaultstatus = cgiarginfo::weak;
177 arg_ainfo.argdefault = "1";
178 arg_ainfo.savedarginfo = cgiarginfo::must;
179 argsinfo.addarginfo (NULL, arg_ainfo);
180
181 // "s"
182 arg_ainfo.shortname = "s";
183 arg_ainfo.longname = "stemming";
184 arg_ainfo.multiplechar = false;
185 arg_ainfo.defaultstatus = cgiarginfo::weak;
186 arg_ainfo.argdefault ="0";
187 arg_ainfo.savedarginfo = cgiarginfo::must;
188 argsinfo.addarginfo (NULL, arg_ainfo);
189
190 // "m"
191 arg_ainfo.shortname = "m";
192 arg_ainfo.longname = "maximum number of documents";
193 arg_ainfo.multiplechar = true;
194 arg_ainfo.defaultstatus = cgiarginfo::weak;
195 arg_ainfo.argdefault = "50";
196 arg_ainfo.savedarginfo = cgiarginfo::must;
197 argsinfo.addarginfo (NULL, arg_ainfo);
198
199 // "o"
200 arg_ainfo.shortname = "o";
201 arg_ainfo.longname = "hits per page";
202 arg_ainfo.multiplechar = true;
203 arg_ainfo.defaultstatus = cgiarginfo::weak;
204 arg_ainfo.argdefault = "20";
205 arg_ainfo.savedarginfo = cgiarginfo::must;
206 argsinfo.addarginfo (NULL, arg_ainfo);
207
208 // "r"
209 arg_ainfo.shortname = "r";
210 arg_ainfo.longname = "start results from";
211 arg_ainfo.multiplechar = true;
212 arg_ainfo.defaultstatus = cgiarginfo::weak;
213 arg_ainfo.argdefault = "1";
214 arg_ainfo.savedarginfo = cgiarginfo::must;
215 argsinfo.addarginfo (NULL, arg_ainfo);
[757]216
217 // "ccs"
218 arg_ainfo.shortname = "ccs";
219 arg_ainfo.longname = "cross collection searching";
220 arg_ainfo.multiplechar = false;
221 arg_ainfo.defaultstatus = cgiarginfo::weak;
222 arg_ainfo.argdefault = "0";
223 arg_ainfo.savedarginfo = cgiarginfo::must;
224 argsinfo.addarginfo (NULL, arg_ainfo);
225
226 // "ccp"
227 arg_ainfo.shortname = "ccp";
228 arg_ainfo.longname = "cross collection page";
229 arg_ainfo.multiplechar = false;
230 arg_ainfo.defaultstatus = cgiarginfo::weak;
231 arg_ainfo.argdefault = "0";
232 arg_ainfo.savedarginfo = cgiarginfo::must;
233 argsinfo.addarginfo (NULL, arg_ainfo);
234
235 // "cc"
236 arg_ainfo.shortname = "cc";
237 arg_ainfo.longname = "collections to search";
238 arg_ainfo.multiplechar = true;
[776]239 arg_ainfo.multiplevalue = true;
[757]240 arg_ainfo.defaultstatus = cgiarginfo::weak;
241 arg_ainfo.argdefault = "";
242 arg_ainfo.savedarginfo = cgiarginfo::must;
243 argsinfo.addarginfo (NULL, arg_ainfo);
244
[928]245 // "hd" history display - search history only displayed when
[1915]246 // this var set to something other than 0
247 // this number of records is displayed
[928]248 arg_ainfo.shortname = "hd";
249 arg_ainfo.longname = "history display";
[1915]250 arg_ainfo.multiplechar = true;
[936]251 arg_ainfo.multiplevalue = false;
[928]252 arg_ainfo.defaultstatus = cgiarginfo::weak;
253 arg_ainfo.argdefault = "0";
254 arg_ainfo.savedarginfo = cgiarginfo::must;
255 argsinfo.addarginfo (NULL, arg_ainfo);
256
[1915]257 // "hs" save - set to 1 in query form, so only save when submit
[928]258 // query
259 // 0 = no save 1 = save
260 arg_ainfo.shortname = "hs";
261 arg_ainfo.longname = "history save";
262 arg_ainfo.multiplechar = false;
263 arg_ainfo.defaultstatus = cgiarginfo::weak;
264 arg_ainfo.argdefault = "0";
265 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
266 argsinfo.addarginfo (NULL, arg_ainfo);
267
[2745]268 // "g" - new arg for granularity, for mgpp collections
[1328]269 arg_ainfo.shortname = "g";
270 arg_ainfo.longname = "granularity";
271 arg_ainfo.multiplechar = true;
272 arg_ainfo.defaultstatus = cgiarginfo::weak;
273 arg_ainfo.argdefault = "Document";
274 arg_ainfo.savedarginfo = cgiarginfo::must;
275 argsinfo.addarginfo (NULL, arg_ainfo);
[928]276
[1915]277 // "ds" - start date
[1373]278 arg_ainfo.shortname = "ds";
279 arg_ainfo.longname = "start date";
280 arg_ainfo.multiplechar = true;
281 arg_ainfo.defaultstatus = cgiarginfo::weak;
282 arg_ainfo.argdefault = "";
283 arg_ainfo.savedarginfo = cgiarginfo::must;
284 argsinfo.addarginfo (NULL, arg_ainfo);
[1328]285
[1373]286 // "de" - end date
287 arg_ainfo.shortname = "de";
288 arg_ainfo.longname = "end date";
289 arg_ainfo.multiplechar = true;
290 arg_ainfo.defaultstatus = cgiarginfo::weak;
291 arg_ainfo.argdefault = "";
292 arg_ainfo.savedarginfo = cgiarginfo::must;
293 argsinfo.addarginfo (NULL, arg_ainfo);
[1328]294
[1373]295 // "dsbc" - whether or not start date is prechristian
296 arg_ainfo.shortname = "dsbc";
297 arg_ainfo.longname = "start date bc";
298 arg_ainfo.multiplechar = false;
299 arg_ainfo.defaultstatus = cgiarginfo::weak;
300 arg_ainfo.argdefault = "0";
301 arg_ainfo.savedarginfo = cgiarginfo::must;
302 argsinfo.addarginfo (NULL, arg_ainfo);
303
304 // "debc" - whether or not end date is prechristian
305 arg_ainfo.shortname = "debc";
306 arg_ainfo.longname = "end date bc";
307 arg_ainfo.multiplechar = false;
308 arg_ainfo.defaultstatus = cgiarginfo::weak;
309 arg_ainfo.argdefault = "0";
310 arg_ainfo.savedarginfo = cgiarginfo::must;
311 argsinfo.addarginfo (NULL, arg_ainfo);
312
[1915]313 // "qt" - 0 = text, 1 = form
314 arg_ainfo.shortname = "qt";
315 arg_ainfo.longname = "query type";
316 arg_ainfo.multiplechar = false;
317 arg_ainfo.defaultstatus = cgiarginfo::weak;
318 arg_ainfo.argdefault = "0";
319 arg_ainfo.savedarginfo = cgiarginfo::must;
320 argsinfo.addarginfo (NULL, arg_ainfo);
321
322 // "qb" - 0 = regular, 1 = large
323 arg_ainfo.shortname = "qb";
324 arg_ainfo.longname = "query box type";
325 arg_ainfo.multiplechar = false;
326 arg_ainfo.defaultstatus = cgiarginfo::weak;
327 arg_ainfo.argdefault = "0";
328 arg_ainfo.savedarginfo = cgiarginfo::must;
329 argsinfo.addarginfo (NULL, arg_ainfo);
330
331 // "fqn" - number of fields in the query form
332 arg_ainfo.shortname = "fqn";
333 arg_ainfo.longname = "form query num fields";
334 arg_ainfo.multiplechar = true;
335 arg_ainfo.defaultstatus = cgiarginfo::weak;
336 arg_ainfo.argdefault = "4";
337 arg_ainfo.savedarginfo = cgiarginfo::must;
338 argsinfo.addarginfo (NULL, arg_ainfo);
339
340 // "fqf" - the list of field names in the form query
341 // - a comma separated list
342 arg_ainfo.shortname = "fqf";
343 arg_ainfo.longname = "form query fields";
344 arg_ainfo.multiplechar = true;
345 //arg_ainfo.multiplevalue = true;
346 arg_ainfo.defaultstatus = cgiarginfo::weak;
347 arg_ainfo.argdefault = "";
348 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
349 argsinfo.addarginfo (NULL, arg_ainfo);
350
351 // "fqv" - the list of values in the form query
352 // - a comma separated list
353 arg_ainfo.shortname = "fqv";
354 arg_ainfo.longname = "form query values";
355 arg_ainfo.multiplechar = true;
356 //arg_ainfo.multiplevalue = true;
357 arg_ainfo.defaultstatus = cgiarginfo::weak;
358 arg_ainfo.argdefault = "";
359 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
360 argsinfo.addarginfo (NULL, arg_ainfo);
361
362
363 // "fqs" - the list of stemming options in the form query
364 // - a comma separated list
365 arg_ainfo.shortname = "fqs";
366 arg_ainfo.longname = "form query stems";
367 arg_ainfo.multiplechar = true;
368 //arg_ainfo.multiplevalue = true;
369 arg_ainfo.defaultstatus = cgiarginfo::weak;
370 arg_ainfo.argdefault = "";
371 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
372 argsinfo.addarginfo (NULL, arg_ainfo);
373
374
375 // "fqk" - the list of casefolding options in the form query
376 // - a comma separated list
377 arg_ainfo.shortname = "fqk";
378 arg_ainfo.longname = "form query casefolds";
379 arg_ainfo.multiplechar = true;
380 //arg_ainfo.multiplevalue = true;
381 arg_ainfo.defaultstatus = cgiarginfo::weak;
382 arg_ainfo.argdefault = "";
383 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
384 argsinfo.addarginfo (NULL, arg_ainfo);
385
386 // "fqc" - the list of boolean operators in the form query
387 // - a comma separated list
388 arg_ainfo.shortname = "fqc";
389 arg_ainfo.longname = "form query combines";
390 arg_ainfo.multiplechar = true;
391 //arg_ainfo.multiplevalue = true;
392 arg_ainfo.defaultstatus = cgiarginfo::weak;
393 arg_ainfo.argdefault = "";
394 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
395 argsinfo.addarginfo (NULL, arg_ainfo);
396
397 // "fqa" - form query advanced - for "run query"
398 arg_ainfo.shortname = "fqa";
399 arg_ainfo.longname = "form query advanced query";
400 arg_ainfo.multiplechar = false;
401 arg_ainfo.defaultstatus = cgiarginfo::weak;
402 arg_ainfo.argdefault = "0";
403 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
404 argsinfo.addarginfo (NULL, arg_ainfo);
405
[174]406}
407
408void queryaction::configure (const text_t &key, const text_tarray &cfgline) {
409 action::configure (key, cfgline);
410}
411
412bool queryaction::init (ostream &logout) {
413 return action::init (logout);
414}
415
[275]416bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
417 ostream &logout) {
418
[174]419 // check t argument
[275]420 int arg_t = args.getintarg("t");
421 if (arg_t != 0 && arg_t != 1) {
422 logout << "Warning: \"t\" argument out of range (" << arg_t << ")\n";
[284]423 cgiarginfo *tinfo = argsinfo.getarginfo ("t");
424 if (tinfo != NULL) args["t"] = tinfo->argdefault;
[275]425 }
[174]426
427 // check k argument
[275]428 int arg_k = args.getintarg("k");
429 if (arg_k != 0 && arg_k != 1) {
430 logout << "Warning: \"k\" argument out of range (" << arg_k << ")\n";
[284]431 cgiarginfo *kinfo = argsinfo.getarginfo ("k");
432 if (kinfo != NULL) args["k"] = kinfo->argdefault;
[275]433 }
[174]434
435 // check s argument
[275]436 int arg_s = args.getintarg("s");
437 if (arg_s != 0 && arg_s != 1) {
438 logout << "Warning: \"s\" argument out of range (" << arg_s << ")\n";
[284]439 cgiarginfo *sinfo = argsinfo.getarginfo ("s");
440 if (sinfo != NULL) args["s"] = sinfo->argdefault;
[275]441 }
[174]442
443 // check m argument
[275]444 int arg_m = args.getintarg("m");
[608]445 if (arg_m < -1) {
446 logout << "Warning: \"m\" argument less than -1 (" << arg_m << ")\n";
[284]447 cgiarginfo *minfo = argsinfo.getarginfo ("m");
448 if (minfo != NULL) args["m"] = minfo->argdefault;
[275]449 }
[174]450
451 // check o argument
[275]452 int arg_o = args.getintarg("o");
[622]453 if (arg_o < -1) {
454 logout << "Warning: \"o\" argument less than -1 (" << arg_o << ")\n";
[284]455 cgiarginfo *oinfo = argsinfo.getarginfo ("o");
456 if (oinfo != NULL) args["o"] = oinfo->argdefault;
[275]457 }
[174]458
459 // check r argument
[275]460 int arg_r = args.getintarg("r");
461 if (arg_r < 1) {
462 logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";
[284]463 cgiarginfo *rinfo = argsinfo.getarginfo ("r");
464 if (rinfo != NULL) args["r"] = rinfo->argdefault;
[275]465 }
[928]466 //check hd argument
[1915]467 int arg_hd = args.getintarg("hd");
468 if (arg_hd <0 ) {
469 logout << "Warning: \"hd\" argument less than 0 (" << arg_hd << ")\n";
470 cgiarginfo *hdinfo = argsinfo.getarginfo ("hd");
471 if (hdinfo != NULL) args["hd"] = hdinfo->argdefault;
472 }
473
[928]474 //check hs argument
475 int arg_hs = args.getintarg("hs");
476 if (arg_hs !=0 && arg_hs !=1) {
477 logout << "Warning: \"hs\" argument out of range (" << arg_hs << ")\n";
478 cgiarginfo *hsinfo = argsinfo.getarginfo ("hs");
479 if (hsinfo != NULL) args["hs"] = hsinfo->argdefault;
480 }
[174]481
[1915]482 // check ct argument
483 int arg_ct = args.getintarg("ct");
484 if (arg_ct !=0 && arg_ct !=1) {
485 logout << "Warning: \"ct\" argument out of range (" << arg_ct << ")\n";
486 cgiarginfo *ctinfo = argsinfo.getarginfo ("ct");
487 if (ctinfo != NULL) args["ct"] = ctinfo->argdefault;
[928]488 }
489
[1915]490 // check qt argument
491 int arg_qt = args.getintarg("qt");
492 if (arg_qt !=0 && arg_qt !=1) {
493 logout << "Warning: \"qt\" argument out of range (" << arg_qt << ")\n";
494 cgiarginfo *qtinfo = argsinfo.getarginfo ("qt");
495 if (qtinfo != NULL) args["qt"] = qtinfo->argdefault;
496 }
497
498 // check qb argument
499 int arg_qb = args.getintarg("qb");
500 if (arg_qb !=0 && arg_qb !=1) {
501 logout << "Warning: \"qb\" argument out of range (" << arg_qb << ")\n";
502 cgiarginfo *qbinfo = argsinfo.getarginfo ("qb");
503 if (qbinfo != NULL) args["qb"] = qbinfo->argdefault;
504 }
505
506 // check fqa argument
507 int arg_fqa = args.getintarg("fqa");
508 if (arg_fqa !=0 && arg_fqa !=1) {
509 logout << "Warning: \"fqa\" argument out of range (" << arg_fqa << ")\n";
510 cgiarginfo *fqainfo = argsinfo.getarginfo ("fqa");
511 if (fqainfo != NULL) args["fqa"] = fqainfo->argdefault;
512 }
513
514 // check fqn argument
515 int arg_fqn = args.getintarg("fqn");
516 if (arg_fqn < -1) {
517 logout << "Warning: \"fqn\" argument less than -1 (" << arg_fqn << ")\n";
518 cgiarginfo *fqninfo = argsinfo.getarginfo ("fqn");
519 if (fqninfo != NULL) args["fqn"] = fqninfo->argdefault;
520 }
521
[174]522 return true;
523}
524
[757]525void queryaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
526 response_t &response, text_t &response_data,
527 ostream &/*logout*/) {
[174]528 response = content;
529 response_data = "text/html";
530}
531
[757]532void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
[1915]533 recptprotolistclass * protos,
534 ostream &logout) {
[275]535
[403]536 // define_internal_macros sets the following macros:
[275]537
[397]538 // _quotedquery_ the part of the query string that was quoted for post-processing
539
540
541
542 // The following macros are set later (in define_query_macros) as they can't be set until
543 // the query has been done.
544
[275]545 // _freqmsg_ the term frequency string
546
547 // _resultline_ the "x documents matched the query" string
548
549 // _prevfirst_ these are used when setting up the links to previous/next
550 // _prevlast_ pages of results (_thisfirst_ and _thislast_ are used to set
551 // _nextfirst_ the 'results x-x for query: xxxx' string in the title bar)
552 // _nextlast_
553 // _thisfirst_
554 // _thislast_
[397]555
556
557 // get the quoted bits of the query string and set _quotedquery_
[403]558 text_tarray phrases;
559 get_phrases (args["q"], phrases);
[800]560 num_phrases = phrases.size();
[403]561 text_tarray::const_iterator phere = phrases.begin();
562 text_tarray::const_iterator pend = phrases.end();
563 bool first = true;
564 text_t quotedquery;
565 while (phere != pend) {
566 if (!first)
567 if ((phere +1) == pend) quotedquery += " and ";
568 else quotedquery += ", ";
569
570 quotedquery += "\"" + *phere + "\"";
571 first = false;
572 phere ++;
573 }
[2934]574 if (args.getintarg("s") && !quotedquery.empty()) quotedquery += "_textstemon_";
[403]575 disp.setmacro ("quotedquery", "query", quotedquery);
[1915]576
577 define_form_macros(disp, args, protos, logout);
[2769]578
579
580 define_query_interface(disp, args, protos, logout);
581
582
583
584
585
586
[174]587}
588
[2769]589void queryaction::define_query_interface(displayclass &disp,
590 cgiargsclass &args,
591 recptprotolistclass * protos,
592 ostream &logout){
593 text_t collection = args["c"];
594
595 //check that the protocol is alive
596 recptproto* colproto = protos->getrecptproto (collection, logout);
597 if(colproto == NULL) {
598 logout << "ERROR: Null collection protocol trying to query"
599 << collection.getcstr() << "\n";
600 return;
601 }
602
603 //check the collection is responding/in place
604 ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(colproto, collection,
605 logout);
606 if(colinfo == NULL){
607 logout << "ERROR: Null returned for get_collectinfo_ptr on "
608 << collection.getcstr() << "in queryaction::define_query_interface\n";
609 return;
610 }
611
612
613 text_tmap::iterator check = colinfo->format.find("QueryInterface");
614 if(check != colinfo->format.end()){
615 if((*check).second=="DateSearch"){
616 text_t current = "_basicqueryform_ _datesearch_";
[2776]617
[2769]618 disp.setmacro("queryformcontent","query",current);
619 }
620 }
621}
622
623
[275]624// sets the selection box macros _hselection_, _jselection_, and _nselection_.
625void queryaction::set_option_macro (const text_t &macroname, text_t current_value,
626 const FilterOption_t &option, displayclass &disp) {
627
[634]628 if (option.validValues.empty()) return;
629 else if (option.validValues.size() == 1) {
630 disp.setmacro (macroname + "selection", "Global", "_" + option.defaultValue + "_");
631 return;
632 }
[275]633 if (option.validValues.size() < 2) return;
[634]634
[275]635 text_t macrovalue = "<select name=\"" + macroname + "\">\n";
[634]636
[275]637 if (current_value.empty()) current_value = option.defaultValue;
[634]638
[275]639 text_tarray::const_iterator thisvalue = option.validValues.begin();
640 text_tarray::const_iterator endvalue = option.validValues.end();
641
642 while (thisvalue != endvalue) {
643 macrovalue += "<option value=\"" + *thisvalue + "\"";
644 if (*thisvalue == current_value)
645 macrovalue += " selected";
[457]646 macrovalue += ">_" + *thisvalue + "_\n";
[275]647 thisvalue ++;
648 }
649 macrovalue += "</select>\n";
650 disp.setmacro (macroname + "selection", "Global", macrovalue);
[174]651}
652
[1915]653// sets the selection box macro _fqfselection_.
654void queryaction::set_fqfselection_macro (const FilterOption_t &option,
655 displayclass &disp) {
656
657 if (option.validValues.empty()) return;
658 text_t macrovalue = "";
659
[2745]660 if (option.validValues.size() == 1) {
661 macrovalue = "_ZZ_";
662 }
663 else {
664 macrovalue += "<select name=\"fqf\" onChange=\"updatefqf();\">\n";
665
666 text_tarray::const_iterator thisvalue = option.validValues.begin();
667 text_tarray::const_iterator endvalue = option.validValues.end();
668
669 while (thisvalue != endvalue) {
670 macrovalue += "<option value=\"" + *thisvalue + "\">_";
671 macrovalue += *thisvalue + "_\n";
672 thisvalue ++;
673 }
674 macrovalue += "</select>\n";
675 }
676 disp.setmacro ("fqfselection", "query", macrovalue);
677
678}
679// sets the selection box macros _gselection_.
680void queryaction::set_gselection_macro (text_t current_value,
681 const FilterOption_t &option,
682 displayclass &disp) {
[1915]683
[2745]684 if (option.validValues.size() <= 1) {
685 return;
686 }
687
688 text_t macrovalue = "<select name=\"g\">\n";
689
690 if (current_value.empty()) current_value = option.defaultValue;
691
[1915]692 text_tarray::const_iterator thisvalue = option.validValues.begin();
693 text_tarray::const_iterator endvalue = option.validValues.end();
694
695 while (thisvalue != endvalue) {
[2745]696 macrovalue += "<option value=\"" + *thisvalue + "\"";
697 if (*thisvalue == current_value)
698 macrovalue += " selected";
699 macrovalue += ">_" + *thisvalue + "_\n";
[1915]700 thisvalue ++;
701 }
702 macrovalue += "</select>\n";
[2745]703 disp.setmacro ("gselection", "Global", macrovalue);
[1915]704}
705
[757]706void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args,
707 recptprotolistclass *protos, ostream &logout) {
[275]708
709 // define_external_macros sets the following macros:
710
711 // some or all of these may not be required to be set
[356]712 // _hselection_, _h2selection_ the selection box for the main part of the index
713 // _jselection_, _j2selection_ the selection box for the subcollection part of the index
714 // _nselection_, _n2selection_ the selection box for the language part of the index
715 // _cq2selection the selection box for combining two queries
[275]716
[928]717
[275]718 // can't do anything if collectproto is null (i.e. no collection was specified)
[757]719 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
[275]720 if (collectproto == NULL) return;
721
722 comerror_t err;
723 InfoFilterOptionsResponse_t response;
724 InfoFilterOptionsRequest_t request;
725 request.filterName = "QueryFilter";
726
727 collectproto->get_filteroptions (args["c"], request, response, err, logout);
728 if (err == noError) {
[356]729
[275]730 FilterOption_tmap::const_iterator it;
731 FilterOption_tmap::const_iterator end = response.filterOptions.end();
[356]732
733 // _hselection_ and _h2selection_ (Index)
[275]734 it = response.filterOptions.find ("Index");
[356]735 if (it != end) set_option_macro ("h", args["h"], (*it).second, disp);
736 if (it != end) set_option_macro ("h2", args["h2"], (*it).second, disp);
737
738 // _jselection_ and _j2selection_ (Subcollection)
[275]739 it = response.filterOptions.find ("Subcollection");
[356]740 if (it != end) set_option_macro ("j", args["j"], (*it).second, disp);
741 if (it != end) set_option_macro ("j2", args["j2"], (*it).second, disp);
742
743 // _nselection_ and _n2selection_ (Language)
744 it = response.filterOptions.find ("Language");
745 if (it != end) set_option_macro ("n", args["n"], (*it).second, disp);
746 if (it != end) set_option_macro ("n2", args["n2"], (*it).second, disp);
[275]747
[356]748 // _cq2selection_ (CombineQuery)
749 it = response.filterOptions.find ("CombineQuery");
750 if (it != end) set_option_macro ("cq2", args["cq2"], (*it).second, disp);
[928]751
[1328]752 // _gselection_ (Level) // for mgpp collections
753 it = response.filterOptions.find("Level");
[2745]754 if (it!=end) set_gselection_macro(args["g"], (*it).second, disp);
[1328]755
[1915]756 // should probably go into define_internal_macros
757 // _fqfselection_
758 it = response.filterOptions.find("IndexField");
759 if (it!=end) {
760 set_fqfselection_macro((*it).second, disp);
761 }
[275]762 }
[928]763} // define external macros
764
[1915]765void queryaction::define_form_macros (displayclass &disp, cgiargsclass &args,
766 recptprotolistclass *protos, ostream &logout) {
767
768 // defines the following macros
769 // _regformlist_
770 // _advformlist_
771
772 if (args["ct"]!="1" || args["qt"]!="1")
773 return; // dont need these macros
774
775 // mgpp & form query only needs the macros defined
776 text_t form = "";
777 int argfqn = args.getintarg("fqn");
778
779 if (args["b"] == "1") { // advanced form
780 form += "<tr>_firstadvformelement_</tr>\n";
781 for (int i=1; i<argfqn; i++) {
782 form += "<tr>_advformelement_</tr>\n";
783 }
784 disp.setmacro("advformlist", "query", form);
785 }
786 else { // simple form
787 for (int i=0; i<argfqn; i++) {
788 form += "<tr>_regformelement_</tr>\n";
789 }
790 disp.setmacro("regformlist", "query", form);
791 }
792
793}
794
[936]795void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,
796 recptprotolistclass *protos, ostream &logout) {
[928]797
798 // defines the following macros
799
800 // _searchhistorylist_
801
802 text_t historylist;
803 int arghd = args.getintarg("hd");
[1915]804 if (arghd == 0) {
[928]805 historylist="";
806 }
807 else {
808 historylist = "<!-- Search History List -->\n";
809
810 text_t userid = args["z"];
811 text_tarray entries;
[2212]812 if (get_history_info (userid, entries, gdbmhome, logout)) {
[928]813 int count = 1;
814 text_tarray::iterator here = entries.begin();
815 text_tarray::iterator end = entries.end();
[1915]816 int numrecords=(int)entries.size();
817 if (numrecords>arghd) { // only display some of them
818 numrecords = arghd;
[928]819 }
[1915]820 historylist += "<form name=\"HistoryForm\"><table width=537>\n";
[928]821
[1915]822 for (int i=0; i<numrecords;i++) {
[928]823 text_t query;
824 text_t numdocs;
825 text_t cgiargs;
[1915]826 text_t userinfo;
827 text_t escquery;
828 split_saved_query(entries[i],numdocs,cgiargs);
[936]829 parse_saved_args(cgiargs, "q", query); // get query string out
[928]830 decode_cgi_arg(query); // un cgisafe it
[2745]831 escquery = escape_quotes(query); // escape the quotes and newlines
[1915]832 text_t histvalue = "histvalue";
833 histvalue += i;
834 disp.setmacro(histvalue, "query", escquery);
835 format_user_info(cgiargs, userinfo, args, protos, logout);
[928]836
[1915]837 historylist += "<tr><td align=right>_imagehistbutton_(";
838 historylist += i;
839 historylist += ")</td>\n";
840 historylist += "<td><nobr><table border=1 cellspacing=0 ";
841 historylist += "cellpadding=0><tr><td width=365 align=left>"
842 + query
843 + "</td></tr></table></td><td width=110 align=center><small>"
844 + numdocs;
845 if (numdocs == 1) historylist += " _texthresult_";
846 else historylist += " _texthresults_";
847 if (!userinfo.empty()) {
848 historylist += "<br>( "+userinfo+" )</small></td>\n";
849 }
[928]850 }
[1915]851 historylist+="</table></form>\n\n";
[928]852
[1915]853 } // if get history info
[928]854 else {
[936]855 historylist += "_textnohistory_";
[928]856 }
857 historylist += "<p><! ---- end of history list ----->\n";
858 } // else display list
859 disp.setmacro("searchhistorylist", "query", historylist);
860
861} // define history macros
862
863void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos,
864 displayclass &disp, outconvertclass &outconvert,
865 ostream &textout, ostream &logout) {
866
[1270]867 ColInfoResponse_t *cinfo = NULL;
[928]868 comerror_t err;
869 InfoFilterOptionsResponse_t fresponse;
870 InfoFilterOptionsRequest_t frequest;
871 frequest.filterName = "QueryFilter";
872
873 text_t &index = args["h"];
874 text_t &subcollection = args["j"];
875 text_t &language = args["n"];
876
877 text_tset collections;
878 text_t arg_cc = args["cc"];
879 decode_cgi_arg (arg_cc);
880 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
881
882 textout << outconvert << disp << "_query:header_\n"
883 << "<center>_navigationbar_</center><br>\n"
884 << "<form name=QueryForm method=get action=\"_gwcgi_\">\n"
885 << "<input type=hidden name=a value=\"q\">\n"
[1860]886 << "<input type=hidden name=site value=\"_cgiargsite_\"\n"
[928]887 << "<input type=hidden name=e value=\"_compressedoptions_\">\n"
888 << "<input type=hidden name=ccp value=\"1\">\n"
889 << "<center><table width=_pagewidth_><tr valign=top>\n"
890 << "<td>Select collections to search for \"" << args["q"]
891 << "\" <i>(index=" << index << " subcollection=" << subcollection
892 << " language=" << language << ")</i></td>\n"
893 << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n"
894 << "</tr></table></center>\n"
895 << "<center><table width=_pagewidth_>\n"
896 << "<tr><td>\n";
897
898 recptprotolistclass::iterator rprotolist_here = protos->begin();
899 recptprotolistclass::iterator rprotolist_end = protos->end();
900 while (rprotolist_here != rprotolist_end) {
901 if ((*rprotolist_here).p != NULL) {
902
903 text_tarray collist;
904 (*rprotolist_here).p->get_collection_list (collist, err, logout);
905 if (err == noError) {
906 text_tarray::iterator collist_here = collist.begin();
907 text_tarray::iterator collist_end = collist.end();
908 while (collist_here != collist_end) {
909
[1270]910 cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
[928]911 // if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) {
[1270]912 if (cinfo != NULL && (cinfo->buildDate > 0)) {
[928]913
914 (*rprotolist_here).p->get_filteroptions (*collist_here, frequest, fresponse, err, logout);
915 if (err == noError) {
916
917 FilterOption_tmap::const_iterator it;
918 FilterOption_tmap::const_iterator end = fresponse.filterOptions.end();
919 if (!index.empty()) {
920 it = fresponse.filterOptions.find ("Index");
921 if (it == end) {collist_here ++; continue;}
922 text_tarray::const_iterator there = (*it).second.validValues.begin();
923 text_tarray::const_iterator tend = (*it).second.validValues.end();
924 while (there != tend) {
925 if (*there == index) break;
926 there ++;
927 }
928 if (there == tend) {collist_here++; continue;}
929 }
930 if (!subcollection.empty()) {
931 it = fresponse.filterOptions.find ("Subcollection");
932 if (it == end) {collist_here++; continue;}
933 text_tarray::const_iterator there = (*it).second.validValues.begin();
934 text_tarray::const_iterator tend = (*it).second.validValues.end();
935 while (there != tend) {
936 if (*there == subcollection) break;
937 there ++;
938 }
939 if (there == tend) {collist_here++; continue;}
940 }
941 if (!language.empty()) {
942 it = fresponse.filterOptions.find ("Language");
943 if (it == end) {collist_here++; continue;}
944 text_tarray::const_iterator there = (*it).second.validValues.begin();
945 text_tarray::const_iterator tend = (*it).second.validValues.end();
946 while (there != tend) {
947 if (*there == language) break;
948 there ++;
949 }
950 if (there == tend) {collist_here++; continue;}
951 }
952
953 // we've got a matching collection
954 textout << "<input type=checkbox";
955
956 text_tset::const_iterator t = collections.find (*collist_here);
957 if (t != collections.end()) textout << " checked";
958
959 textout << outconvert
960 << " name=cc value=\"" << *collist_here << "\">";
961
[1270]962 if (!cinfo->collectionmeta["collectionname"].empty())
963 textout << outconvert << disp << cinfo->collectionmeta["collectionname"];
[928]964 else
965 textout << outconvert << *collist_here;
966
967 textout << "<br>\n";
968
969 }
970 }
971 collist_here ++;
972 }
973 }
974 }
975 rprotolist_here ++;
976 }
977 textout << outconvert << disp
978 << "</td></tr></table></center>\n"
979 << "</form>\n"
980 << "_query:footer_\n";
981
[174]982}
[275]983
[757]984bool queryaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
985 browsermapclass *browsers, displayclass &disp,
[421]986 outconvertclass &outconvert, ostream &textout,
987 ostream &logout) {
[757]988
[1270]989 if (recpt == NULL) {
990 logout << "ERROR (queryaction::do_action): This action does not contain information\n"
991 << " about any receptionists. The method set_receptionist was probably\n"
992 << " not called from the module which instantiated this action.\n";
993 return true;
994 }
995
996
[865]997 if (args["ccs"] == "1") {
998 if (!args["cc"].empty()) {
[757]999 // query the selected collections
[865]1000 text_t::const_iterator b = args["cc"].begin();
1001 text_t::const_iterator e = args["cc"].end();
1002 if (findchar (b, e, ',') != e) {
1003 if (!search_multiple_collections (args, protos, browsers, disp, outconvert,
1004 textout, logout)) return false;
1005 return true;
1006 } else {
1007 if (!search_single_collection (args, args["cc"], protos, browsers, disp,
1008 outconvert, textout, logout)) return false;
1009 return true;
1010 }
1011 }
[337]1012 }
[421]1013
[800]1014 // simply query the current collection
[865]1015 if (!search_single_collection (args, args["c"], protos, browsers, disp,
1016 outconvert, textout, logout)) return false;
[757]1017 return true;
1018}
1019
1020bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos,
1021 browsermapclass *browsers, displayclass &disp,
1022 outconvertclass &outconvert, ostream &textout,
1023 ostream &logout) {
1024
1025 text_tarray collections;
1026
1027 text_t arg_cc = args["cc"];
1028 decode_cgi_arg (arg_cc);
1029 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
1030
1031 if (collections.empty()) {
1032 logout << "queryaction::search_multiple_collections: No collections "
1033 << "set for doing multiple query - will search current collection\n";
1034 textout << outconvert << disp << "_query:textwarningnocollections_\n";
[865]1035 return search_single_collection (args, args["c"], protos, browsers, disp,
[757]1036 outconvert, textout, logout);
[447]1037 }
1038
[757]1039 // queryaction uses "VList" browser to display results,
1040 // a queries clasification is "Search"
1041 text_t browsertype = "VList";
1042 text_t classification = "Search";
[337]1043
[757]1044 QueryResult_tset results;
1045 map<text_t, colinfo_t, lttext_t> colinfomap;
[275]1046
[1270]1047 ColInfoResponse_t *cinfo = NULL;
[1695]1048 recptproto *collectproto = NULL;
[757]1049 comerror_t err;
1050 FilterRequest_t request;
1051 FilterResponse_t response;
1052 request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking;
1053 text_t formattedstring = args["q"];
1054 text_t freqmsg = "_textfreqmsg1_";
1055 int numdocs = 0;
[800]1056 isapprox isApprox = Exact;
[772]1057
[757]1058 format_querystring (formattedstring, args.getintarg("b"));
1059 set_queryfilter_options (request, formattedstring, args);
1060
1061 // need to retrieve maxdocs matches for each collection
1062 // (will eventually want to tidy this up, do so caching etc.)
1063 OptionValue_t option;
1064 option.name = "StartResults";
1065 option.value = "1";
1066 request.filterOptions.push_back (option);
1067
1068 option.name = "EndResults";
1069 option.value = args["m"];
1070 request.filterOptions.push_back (option);
1071
1072 text_tarray::iterator col_here = collections.begin();
1073 text_tarray::iterator col_end = collections.end();
1074
[865]1075 map<text_t, int, lttext_t> termfreqs;
[757]1076 while (col_here != col_end) {
1077
1078 request.fields.erase (request.fields.begin(), request.fields.end());
1079 request.getParents = false;
1080
[1695]1081 collectproto = protos->getrecptproto (*col_here, logout);
[757]1082 if (collectproto == NULL) {
1083 logout << outconvert << "queryaction::search_multiple_collections: " << *col_here
1084 << " collection has a NULL collectproto, ignoring\n";
1085 col_here ++;
1086 continue;
1087 }
[1270]1088 cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
1089 if (cinfo == NULL) {
1090 logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL\n";
1091 col_here ++;
1092 continue;
1093 }
[757]1094
1095 browserclass *bptr = browsers->getbrowser (browsertype);
1096
1097 // get the formatstring if there is one
1098 text_t formatstring;
1099 if (!get_formatstring (classification, browsertype,
[1270]1100 cinfo->format, formatstring))
[757]1101 formatstring = bptr->get_default_formatstring();
1102
1103 bptr->load_metadata_defaults (request.fields);
1104
[347]1105 format_t *formatlistptr = new format_t();
1106 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1107
[757]1108 colinfo_t thiscolinfo;
1109 thiscolinfo.formatlistptr = formatlistptr;
1110 thiscolinfo.browserptr = bptr;
1111 colinfomap[*col_here] = thiscolinfo;
1112
[275]1113 // do the query
[757]1114 collectproto->filter (*col_here, request, response, err, logout);
1115 if (err != noError) {
1116 outconvertclass text_t2ascii;
1117 logout << text_t2ascii
1118 << "queryaction::search_multiple_collections: call to QueryFilter failed "
1119 << "for " << *col_here << " collection (" << get_comerror_string (err) << ")\n";
[275]1120 return false;
[757]1121 }
1122
[800]1123 if (isApprox == Exact)
1124 isApprox = response.isApprox;
1125 else if (isApprox == MoreThan)
1126 if (response.isApprox == Approximate)
1127 isApprox = response.isApprox;
1128
[757]1129 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
1130 TermInfo_tarray::const_iterator end_term = response.termInfo.end();
1131 while (this_term != end_term) {
[865]1132 termfreqs[(*this_term).term] += (*this_term).freq;
1133 if ((col_here+1) == col_end) {
1134 freqmsg += (*this_term).term + ": " + termfreqs[(*this_term).term];
1135 if ((this_term+1) != end_term) freqmsg += ", ";
1136 }
[757]1137 this_term ++;
1138 }
[275]1139
[757]1140 if (response.numDocs > 0) {
1141 numdocs += response.numDocs;
[275]1142
[757]1143 QueryResult_t thisresult;
1144 thisresult.collection = *col_here;
1145 ResultDocInfo_tarray::iterator doc_here = response.docInfo.begin();
1146 ResultDocInfo_tarray::iterator doc_end = response.docInfo.end();
1147 while (doc_here != doc_end) {
1148 thisresult.doc = *doc_here;
1149 results.insert (thisresult);
1150 doc_here ++;
[447]1151 }
[347]1152 }
[757]1153 col_here ++;
1154 }
[347]1155
[800]1156 disp.setmacro ("freqmsg", "query", freqmsg);
[349]1157
[1690]1158 int maxdocs = args.getintarg("m");
1159 int firstdoc = args.getintarg("r");
1160 int hitsperpage = args.getintarg("o");
1161 if (num_phrases > 0) isApprox = Exact;
1162 if (maxdocs == -1) maxdocs = numdocs;
1163 else if (numdocs > maxdocs) {
1164 numdocs = maxdocs;
1165 isApprox = MoreThan;
1166 }
1167 if (hitsperpage == -1) hitsperpage = numdocs;
1168
[800]1169 text_t resline;
1170 if (isApprox == Approximate) resline = "_textapprox_";
1171 else if (isApprox == MoreThan) resline = "_textmorethan_";
1172
1173 if (numdocs == 0) resline = "_textnodocs_";
1174 else if (numdocs == 1) resline += "_text1doc_";
1175 else resline += text_t(numdocs) + " _textlotsdocs_";
1176 disp.setmacro("resultline", "query", resline);
[757]1177
1178 QueryResult_tset::iterator res_here = results.begin();
1179 QueryResult_tset::iterator res_end = results.end();
1180 text_tset metadata; // empty !!
1181 bool getParents = false; // don't care !!
1182 bool use_table;
1183 ResultDocInfo_t thisdoc;
1184 format_t *formatlistptr = NULL;
1185 browserclass *browserptr = NULL;
1186
1187 // set up _thisfirst_ and _thislast_ macros
1188 disp.setmacro ("thisfirst", "query", firstdoc);
1189 int thislast = firstdoc + (hitsperpage - 1);
1190 if (thislast > numdocs) thislast = numdocs;
1191 disp.setmacro ("thislast", "query", thislast);
1192
1193 // set up _prevfirst_ and _prevlast_ macros
1194 if (firstdoc > 1) {
1195 disp.setmacro ("prevlast", "query", firstdoc - 1);
1196 int prevfirst = firstdoc - hitsperpage;
1197 if (prevfirst < 1) prevfirst = 1;
1198 disp.setmacro ("prevfirst", "query", prevfirst);
[275]1199 }
[757]1200
1201 // set up _nextfirst_ and _nextlast_ macros
1202 if (thislast < numdocs) {
1203 disp.setmacro ("nextfirst", "query", thislast + 1);
1204 int nextlast = thislast + hitsperpage;
1205 if (nextlast > numdocs) nextlast = numdocs;
1206 disp.setmacro ("nextlast", "query", nextlast);
1207 }
1208
1209 textout << outconvert << disp << "_query:header_\n"
1210 << "_query:content_";
1211
1212 int count = 1;
1213
1214 // output results
1215 while (res_here != res_end) {
1216 if (count < firstdoc) {count ++; res_here ++; continue;}
1217 if (count > thislast) break;
1218 formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
1219 browserptr = colinfomap[(*res_here).collection].browserptr;
1220 thisdoc = (*res_here).doc;
1221 use_table = is_table_content (formatlistptr);
[1695]1222
1223 collectproto = protos->getrecptproto ((*res_here).collection, logout);
1224 if (collectproto == NULL) {
1225 logout << outconvert << "queryaction::search_multiple_collections: " << (*res_here).collection
1226 << " collection has a NULL collectproto, ignoring results\n";
1227 res_here ++;
1228 continue;
1229 }
1230
[757]1231 browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0,
1232 formatlistptr, use_table, metadata, getParents,
1233 collectproto, disp, outconvert, textout, logout);
1234 // textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
1235 res_here ++;
1236 count ++;
1237 }
1238
1239 textout << outconvert << disp << "_query:footer_";
[349]1240
[757]1241 // clean up the format_t pointers
1242 map<text_t, colinfo_t, lttext_t>::iterator here = colinfomap.begin();
1243 map<text_t, colinfo_t, lttext_t>::iterator end = colinfomap.end();
1244 while (here != end) {
1245 delete ((*here).second.formatlistptr);
1246 here ++;
1247 }
[275]1248 return true;
1249}
[757]1250
[865]1251bool queryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
1252 recptprotolistclass *protos, browsermapclass *browsers,
1253 displayclass &disp, outconvertclass &outconvert,
1254 ostream &textout, ostream &logout) {
[757]1255
[865]1256 recptproto *collectproto = protos->getrecptproto (collection, logout);
[757]1257 if (collectproto == NULL) {
[865]1258 logout << outconvert << "queryaction::search_single_collection: " << collection
[757]1259 << " collection has a NULL collectproto\n";
1260 return false;
1261 }
1262
1263 // queryaction uses "VList" browser to display results,
1264 // a queries clasification is "Search"
1265 text_t browsertype = "VList";
1266 text_t classification = "Search";
1267
1268 comerror_t err;
[1270]1269 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
1270
1271 if (cinfo == NULL) {
1272 logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
1273 return false;
1274 }
[757]1275
1276 browserclass *bptr = browsers->getbrowser (browsertype);
1277
1278 // get the formatstring if there is one
1279 text_t formatstring;
1280 if (!get_formatstring (classification, browsertype,
[1270]1281 cinfo->format, formatstring))
[757]1282 formatstring = bptr->get_default_formatstring();
1283
1284 FilterRequest_t request;
1285 FilterResponse_t response;
1286 bptr->set_filter_options (request, args);
1287 bptr->load_metadata_defaults (request.fields);
1288
1289 format_t *formatlistptr = new format_t();
1290 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1291
1292 // do the query
1293 request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
[1915]1294 text_t formattedstring = "";
1295
1296 if (args["qt"]=="0") { // normal text search
1297 formattedstring = args["q"];
1298 format_querystring (formattedstring, args.getintarg("b"));
1299 add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
1300 args.getintarg("dsbc"), args.getintarg("debc"));
[928]1301 }
[1915]1302 else if (args["qt"]=="1" ){ // form search
[1347]1303
[1915]1304 if (args["b"]=="1" && args["fqa"]=="1") { // explicit query
1305 formattedstring = args["q"];
1306 }
1307 else { // form search
1308 if (args["b"]=="0") { // regular form
1309 parse_reg_query_form(formattedstring, args);
1310 }
1311 else { // advanced form
1312 parse_adv_query_form(formattedstring, args);
1313 }
1314 args["q"] = formattedstring;
1315
1316 // also reset the _cgiargq_ macro as it has changed now
1317 disp.setmacro("cgiargq", "Global", html_safe(args["q"]));
1318
1319 // reset the compressed options to include the q arg
1320 text_t compressedoptions = recpt->get_compressed_arg(args, logout);
1321 if (!compressedoptions.empty()) {
1322 disp.setmacro ("compressedoptions", "Global", dm_safe(compressedoptions));
1323 // need a decoded version of compressedoptions for use within forms
1324 // as browsers encode values from forms before sending to server
1325 // (e.g. %25 becomes %2525)
1326 decode_cgi_arg (compressedoptions);
1327 disp.setmacro ("decodedcompressedoptions", "Global", dm_safe(compressedoptions));
1328 }
1329 } // form search
1330 } // args["qt"]=1
1331 else {
1332 logout << "ERROR (query_action::search_single_collection): querytype not defined\n";
[757]1333 return false;
1334 }
[928]1335
[1915]1336 if (!formattedstring.empty()) { // do the query
1337 set_queryfilter_options (request, formattedstring, args);
1338 collectproto->filter (collection, request, response, err, logout);
1339 if (err != noError) {
1340 outconvertclass text_t2ascii;
1341 logout << text_t2ascii
1342 << "queryaction::search_single_collections: call to QueryFilter failed "
1343 << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
1344 return false;
1345 }
1346
1347 define_query_macros (args, disp, response);
[757]1348
[1915]1349 // save the query if appropriate
1350 if (!save_search_history(args, response))
1351 logout << "save failed";
1352 }
[928]1353
[936]1354 define_history_macros (disp, args, protos, logout);
[1915]1355
[757]1356 textout << outconvert << disp << "_query:header_\n"
1357 << "_query:content_";
1358
1359 // output the results
1360 bool use_table = is_table_content (formatlistptr);
[865]1361 bptr->output_section_group (response, args, collection, 0, formatlistptr,
[757]1362 use_table, request.fields, request.getParents,
1363 collectproto, disp, outconvert, textout, logout);
1364
1365
1366 textout << outconvert << disp << "_query:footer_";
1367
1368 delete (formatlistptr);
1369
1370 return true;
1371}
1372
[298]1373// define_query_macros sets the macros that couldn't be set until the
[275]1374// query had been done. Those macros are _freqmsg_, _quotedquery_,
1375// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
1376// _thisfirst_, and _thislast_
1377void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
[397]1378 const FilterResponse_t &response) {
[275]1379 // set up _freqmsg_ and _quotedquery_ macros
1380 text_t freqmsg = "_textfreqmsg1_";
1381 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
1382 TermInfo_tarray::const_iterator end_term = response.termInfo.end();
1383 while (this_term != end_term) {
[1373]1384 char *term = (*this_term).term.getcstr();
[2848]1385 if(term[0]<'0' || term[0] >'9'){
1386 freqmsg += (*this_term).term + ": " + (*this_term).freq;
1387 if ((this_term + 1) != end_term)
1388 freqmsg += ", ";
1389 }
[1373]1390 delete term;
[275]1391 this_term ++;
1392 }
[2848]1393 disp.setmacro ("freqmsg", "query", freqmsg);
[275]1394
1395 // set up _resultline_ macro
1396 text_t resline;
[398]1397 int maxdocs = args.getintarg("m");
[400]1398 int numdocs = response.numDocs;
[403]1399 isapprox isApprox = response.isApprox;
[800]1400 if (num_phrases > 0) isApprox = Exact;
[1717]1401 if (maxdocs == -1) maxdocs = numdocs;
1402 else if (numdocs > maxdocs) {
1403 numdocs = maxdocs;
1404 isApprox = MoreThan;
1405 }
[403]1406
1407 if (isApprox == Approximate) resline = "_textapprox_";
1408 else if (isApprox == MoreThan) resline = "_textmorethan_";
[400]1409
[275]1410 if (numdocs == 0) resline = "_textnodocs_";
1411 else if (numdocs == 1) resline += "_text1doc_";
[400]1412 else resline += text_t(numdocs) + " _textlotsdocs_";
[398]1413
[275]1414 disp.setmacro("resultline", "query", resline);
1415
1416 int firstdoc = args.getintarg("r");
1417 int hitsperpage = args.getintarg("o");
[622]1418 if (hitsperpage == -1) hitsperpage = numdocs;
[275]1419
1420 // set up _thisfirst_ and _thislast_ macros
1421 disp.setmacro ("thisfirst", "query", firstdoc);
1422 int thislast = firstdoc + (hitsperpage - 1);
1423 if (thislast > numdocs) thislast = numdocs;
1424 disp.setmacro ("thislast", "query", thislast);
1425
1426 // set up _prevfirst_ and _prevlast_ macros
1427 if (firstdoc > 1) {
1428 disp.setmacro ("prevlast", "query", firstdoc - 1);
1429 int prevfirst = firstdoc - hitsperpage;
1430 if (prevfirst < 1) prevfirst = 1;
1431 disp.setmacro ("prevfirst", "query", prevfirst);
1432 }
1433
1434 // set up _nextfirst_ and _nextlast_ macros
1435 if (thislast < numdocs) {
1436 disp.setmacro ("nextfirst", "query", thislast + 1);
1437 int nextlast = thislast + hitsperpage;
1438 if (nextlast > numdocs) nextlast = numdocs;
1439 disp.setmacro ("nextlast", "query", nextlast);
1440 }
1441}
1442
[928]1443bool queryaction::save_search_history (cgiargsclass &args, const FilterResponse_t &response)
1444{
1445 if (args["q"]=="") return true; // null query, dont save
1446 if (args["hs"]=="0") return true; // only save when submit query
[1915]1447 // displayed
[928]1448 // get userid
1449 text_t userid = args["z"];
[275]1450
[928]1451 // the number of docs goes on the front of the query string
1452 int numdocs= response.numDocs;
1453 text_t query = text_t(numdocs);
1454 if (response.isApprox==MoreThan) { // there were more docs found
1455 query.push_back('+');
1456 }
[1915]1457 query += "c="+args["c"];
[928]1458 query += "&h="+args["h"];
1459 query += "&t="+args["t"];
1460 query += "&b="+args["b"];
1461 query += "&j="+args["j"];
1462 query += "&n="+args["n"];
1463 query += "&s="+args["s"];
1464 query += "&k="+args["k"];
[1915]1465 query += "&g="+args["g"];
1466
[928]1467 text_t qstring = args["q"];
1468 text_t formattedquery =cgi_safe(qstring);
1469 query += "&q="+formattedquery;
1470
[1915]1471 bool display=false;
1472 int hd = args.getintarg("hd");
1473 if (hd > 0) display=true;
[2212]1474 if (set_history_info(userid, query, gdbmhome, display)) return true;
[928]1475 else return false;
1476
1477
1478}
[1373]1479
1480
1481
Note: See TracBrowser for help on using the repository browser.