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

Last change on this file since 15433 was 15433, checked in by mdewsnip, 13 years ago

(Adding new DB support) Removed unnecessary inclusions of "infodbclass.h".

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 61.2 KB
Line 
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 *********************************************************************/
25
26#include "queryaction.h"
27#include "querytools.h"
28#include "formattools.h"
29#include "cgiutils.h"
30#include "OIDtools.h"
31#include "fileutil.h"
32#include "text_t.h"
33#include "historydb.h"
34#include "htmlutils.h" // for html_safe in do_action
35#include "gsdltools.h"
36#include "phrases.h" // for get_phrases
37#include <stdlib.h> // for strtol
38#include <assert.h>
39
40void colinfo_t::clear () {
41 formatlistptr = NULL;
42 browserptr = NULL;
43}
44
45void QueryResult_t::clear() {
46 doc.clear();
47 collection.clear();
48}
49
50queryaction::queryaction () {
51
52 recpt = NULL;
53 num_phrases = 0;
54
55 // this action uses cgi variable "a"
56 cgiarginfo arg_ainfo;
57 arg_ainfo.shortname = "a";
58 arg_ainfo.longname = "action";
59 arg_ainfo.multiplechar = true;
60 arg_ainfo.defaultstatus = cgiarginfo::weak;
61 arg_ainfo.argdefault = "q";
62 arg_ainfo.savedarginfo = cgiarginfo::must;
63 argsinfo.addarginfo (NULL, arg_ainfo);
64
65 // "ct" - 0 = mg, 1 = mgpp, 2=lucene
66 arg_ainfo.shortname = "ct";
67 arg_ainfo.longname = "collection type";
68 arg_ainfo.multiplechar = true; // can be empty or single char
69 arg_ainfo.defaultstatus = cgiarginfo::weak;
70 arg_ainfo.argdefault = g_EmptyText;
71 arg_ainfo.savedarginfo = cgiarginfo::must;
72 argsinfo.addarginfo (NULL, arg_ainfo);
73
74 // "b" - 0 = simple, 1 = advanced
75 arg_ainfo.shortname = "b";
76 arg_ainfo.longname = "query mode";
77 arg_ainfo.multiplechar = false;
78 arg_ainfo.defaultstatus = cgiarginfo::weak;
79 arg_ainfo.argdefault = "0";
80 arg_ainfo.savedarginfo = cgiarginfo::must;
81 argsinfo.addarginfo (NULL, arg_ainfo);
82
83 // "h"
84 arg_ainfo.shortname = "h";
85 arg_ainfo.longname = "main index";
86 arg_ainfo.multiplechar = true;
87 arg_ainfo.defaultstatus = cgiarginfo::weak;
88 arg_ainfo.argdefault = g_EmptyText;
89 arg_ainfo.savedarginfo = cgiarginfo::must;
90 argsinfo.addarginfo (NULL, arg_ainfo);
91
92 // "h2"
93 arg_ainfo.shortname = "h2";
94 arg_ainfo.longname = "main index for second query";
95 arg_ainfo.multiplechar = true;
96 arg_ainfo.defaultstatus = cgiarginfo::weak;
97 arg_ainfo.argdefault = g_EmptyText;
98 arg_ainfo.savedarginfo = cgiarginfo::must;
99 argsinfo.addarginfo (NULL, arg_ainfo);
100
101 // "j"
102 arg_ainfo.shortname = "j";
103 arg_ainfo.longname = "sub collection index";
104 arg_ainfo.multiplechar = true;
105 arg_ainfo.defaultstatus = cgiarginfo::weak;
106 arg_ainfo.argdefault = g_EmptyText;
107 arg_ainfo.savedarginfo = cgiarginfo::must;
108 argsinfo.addarginfo (NULL, arg_ainfo);
109
110 // "j2"
111 arg_ainfo.shortname = "j2";
112 arg_ainfo.longname = "sub collection index for second query";
113 arg_ainfo.multiplechar = true;
114 arg_ainfo.defaultstatus = cgiarginfo::weak;
115 arg_ainfo.argdefault = g_EmptyText;
116 arg_ainfo.savedarginfo = cgiarginfo::must;
117 argsinfo.addarginfo (NULL, arg_ainfo);
118
119 // "n"
120 arg_ainfo.shortname = "n";
121 arg_ainfo.longname = "language index";
122 arg_ainfo.multiplechar = true;
123 arg_ainfo.defaultstatus = cgiarginfo::weak;
124 arg_ainfo.argdefault = g_EmptyText;
125 arg_ainfo.savedarginfo = cgiarginfo::must;
126 argsinfo.addarginfo (NULL, arg_ainfo);
127
128 // "n2"
129 arg_ainfo.shortname = "n2";
130 arg_ainfo.longname = "language index for second query";
131 arg_ainfo.multiplechar = true;
132 arg_ainfo.defaultstatus = cgiarginfo::weak;
133 arg_ainfo.argdefault = g_EmptyText;
134 arg_ainfo.savedarginfo = cgiarginfo::must;
135 argsinfo.addarginfo (NULL, arg_ainfo);
136
137
138 // "q"
139 arg_ainfo.shortname = "q";
140 arg_ainfo.longname = "query string";
141 arg_ainfo.multiplechar = true;
142 arg_ainfo.defaultstatus = cgiarginfo::weak;
143 arg_ainfo.argdefault = g_EmptyText;
144 arg_ainfo.savedarginfo = cgiarginfo::must;
145 argsinfo.addarginfo (NULL, arg_ainfo);
146
147 // "q2"
148 arg_ainfo.shortname = "q2";
149 arg_ainfo.longname = "query string for second query";
150 arg_ainfo.multiplechar = true;
151 arg_ainfo.defaultstatus = cgiarginfo::weak;
152 arg_ainfo.argdefault = g_EmptyText;
153 arg_ainfo.savedarginfo = cgiarginfo::must;
154 argsinfo.addarginfo (NULL, arg_ainfo);
155
156 // "cq2" ""=don't combine, "and", "or", "not"
157 arg_ainfo.shortname = "cq2";
158 arg_ainfo.longname = "combine queries";
159 arg_ainfo.multiplechar = true;
160 arg_ainfo.defaultstatus = cgiarginfo::weak;
161 arg_ainfo.argdefault = g_EmptyText;
162 arg_ainfo.savedarginfo = cgiarginfo::must;
163 argsinfo.addarginfo (NULL, arg_ainfo);
164
165 // "t" - 1 = ranked 0 = boolean
166 arg_ainfo.shortname = "t";
167 arg_ainfo.longname = "search type";
168 arg_ainfo.multiplechar = false;
169 arg_ainfo.defaultstatus = cgiarginfo::weak;
170 arg_ainfo.argdefault = "1";
171 arg_ainfo.savedarginfo = cgiarginfo::must;
172 argsinfo.addarginfo (NULL, arg_ainfo);
173
174 // "k"
175 arg_ainfo.shortname = "k";
176 arg_ainfo.longname = "casefolding";
177 arg_ainfo.multiplechar = false;
178 arg_ainfo.defaultstatus = cgiarginfo::weak;
179 arg_ainfo.argdefault = "1";
180 arg_ainfo.savedarginfo = cgiarginfo::must;
181 argsinfo.addarginfo (NULL, arg_ainfo);
182
183 // "ks"
184 arg_ainfo.shortname = "ks";
185 arg_ainfo.longname = "casefolding support";
186 arg_ainfo.multiplechar = false;
187 arg_ainfo.defaultstatus = cgiarginfo::weak;
188 arg_ainfo.argdefault = "0";
189 arg_ainfo.savedarginfo = cgiarginfo::must;
190 argsinfo.addarginfo (NULL, arg_ainfo);
191
192 // "s"
193 arg_ainfo.shortname = "s";
194 arg_ainfo.longname = "stemming";
195 arg_ainfo.multiplechar = false;
196 arg_ainfo.defaultstatus = cgiarginfo::weak;
197 arg_ainfo.argdefault = "0";
198 arg_ainfo.savedarginfo = cgiarginfo::must;
199 argsinfo.addarginfo (NULL, arg_ainfo);
200
201 // "ss"
202 arg_ainfo.shortname = "ss";
203 arg_ainfo.longname = "stemming support";
204 arg_ainfo.multiplechar = false;
205 arg_ainfo.defaultstatus = cgiarginfo::weak;
206 arg_ainfo.argdefault = "0";
207 arg_ainfo.savedarginfo = cgiarginfo::must;
208 argsinfo.addarginfo (NULL, arg_ainfo);
209
210 // "af"
211 arg_ainfo.shortname = "af";
212 arg_ainfo.longname = "accentfolding";
213 arg_ainfo.multiplechar = false;
214 arg_ainfo.defaultstatus = cgiarginfo::weak;
215 arg_ainfo.argdefault = "0";
216 arg_ainfo.savedarginfo = cgiarginfo::must;
217 argsinfo.addarginfo (NULL, arg_ainfo);
218
219 // "afs"
220 arg_ainfo.shortname = "afs";
221 arg_ainfo.longname = "accentfolding support";
222 arg_ainfo.multiplechar = false;
223 arg_ainfo.defaultstatus = cgiarginfo::weak;
224 arg_ainfo.argdefault = "0";
225 arg_ainfo.savedarginfo = cgiarginfo::must;
226 argsinfo.addarginfo (NULL, arg_ainfo);
227
228 // "m"
229 arg_ainfo.shortname = "m";
230 arg_ainfo.longname = "maximum number of documents";
231 arg_ainfo.multiplechar = true;
232 arg_ainfo.defaultstatus = cgiarginfo::weak;
233 arg_ainfo.argdefault = "50";
234 arg_ainfo.savedarginfo = cgiarginfo::must;
235 argsinfo.addarginfo (NULL, arg_ainfo);
236
237 // "o"
238 arg_ainfo.shortname = "o";
239 arg_ainfo.longname = "hits per page";
240 arg_ainfo.multiplechar = true;
241 arg_ainfo.defaultstatus = cgiarginfo::weak;
242 arg_ainfo.argdefault = "20";
243 arg_ainfo.savedarginfo = cgiarginfo::must;
244 argsinfo.addarginfo (NULL, arg_ainfo);
245
246 // "r"
247 arg_ainfo.shortname = "r";
248 arg_ainfo.longname = "start results from";
249 arg_ainfo.multiplechar = true;
250 arg_ainfo.defaultstatus = cgiarginfo::weak;
251 arg_ainfo.argdefault = "1";
252 arg_ainfo.savedarginfo = cgiarginfo::must;
253 argsinfo.addarginfo (NULL, arg_ainfo);
254
255 // "ccs"
256 arg_ainfo.shortname = "ccs";
257 arg_ainfo.longname = "cross collection searching";
258 arg_ainfo.multiplechar = false;
259 arg_ainfo.defaultstatus = cgiarginfo::weak;
260 arg_ainfo.argdefault = "0";
261 arg_ainfo.savedarginfo = cgiarginfo::must;
262 argsinfo.addarginfo (NULL, arg_ainfo);
263
264 // "ccp"
265 arg_ainfo.shortname = "ccp";
266 arg_ainfo.longname = "cross collection page";
267 arg_ainfo.multiplechar = false;
268 arg_ainfo.defaultstatus = cgiarginfo::weak;
269 arg_ainfo.argdefault = "0";
270 arg_ainfo.savedarginfo = cgiarginfo::must;
271 argsinfo.addarginfo (NULL, arg_ainfo);
272
273 // "cc"
274 arg_ainfo.shortname = "cc";
275 arg_ainfo.longname = "collections to search";
276 arg_ainfo.multiplechar = true;
277 arg_ainfo.multiplevalue = true;
278 arg_ainfo.defaultstatus = cgiarginfo::weak;
279 arg_ainfo.argdefault = g_EmptyText;
280 arg_ainfo.savedarginfo = cgiarginfo::must;
281 argsinfo.addarginfo (NULL, arg_ainfo);
282
283 // "hd" history display - search history only displayed when
284 // this var set to something other than 0
285 // this number of records is displayed
286 arg_ainfo.shortname = "hd";
287 arg_ainfo.longname = "history display";
288 arg_ainfo.multiplechar = true;
289 arg_ainfo.multiplevalue = false;
290 arg_ainfo.defaultstatus = cgiarginfo::weak;
291 arg_ainfo.argdefault = "0";
292 arg_ainfo.savedarginfo = cgiarginfo::must;
293 argsinfo.addarginfo (NULL, arg_ainfo);
294
295 // "hs" save - set to 1 in query form, so only save when submit
296 // query
297 // 0 = no save 1 = save
298 arg_ainfo.shortname = "hs";
299 arg_ainfo.longname = "history save";
300 arg_ainfo.multiplechar = false;
301 arg_ainfo.defaultstatus = cgiarginfo::weak;
302 arg_ainfo.argdefault = "0";
303 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
304 argsinfo.addarginfo (NULL, arg_ainfo);
305
306 // "g" - new arg for granularity, for mgpp collections
307 arg_ainfo.shortname = "g";
308 arg_ainfo.longname = "granularity";
309 arg_ainfo.multiplechar = true;
310 arg_ainfo.defaultstatus = cgiarginfo::weak;
311 arg_ainfo.argdefault = g_EmptyText;
312 arg_ainfo.savedarginfo = cgiarginfo::must;
313 argsinfo.addarginfo (NULL, arg_ainfo);
314
315 // "ds" - start date
316 arg_ainfo.shortname = "ds";
317 arg_ainfo.longname = "start date";
318 arg_ainfo.multiplechar = true;
319 arg_ainfo.defaultstatus = cgiarginfo::weak;
320 arg_ainfo.argdefault = g_EmptyText;
321 arg_ainfo.savedarginfo = cgiarginfo::must;
322 argsinfo.addarginfo (NULL, arg_ainfo);
323
324 // "de" - end date
325 arg_ainfo.shortname = "de";
326 arg_ainfo.longname = "end date";
327 arg_ainfo.multiplechar = true;
328 arg_ainfo.defaultstatus = cgiarginfo::weak;
329 arg_ainfo.argdefault = g_EmptyText;
330 arg_ainfo.savedarginfo = cgiarginfo::must;
331 argsinfo.addarginfo (NULL, arg_ainfo);
332
333 // "dsbc" - whether or not start date is prechristian
334 arg_ainfo.shortname = "dsbc";
335 arg_ainfo.longname = "start date bc";
336 arg_ainfo.multiplechar = false;
337 arg_ainfo.defaultstatus = cgiarginfo::weak;
338 arg_ainfo.argdefault = "0";
339 arg_ainfo.savedarginfo = cgiarginfo::must;
340 argsinfo.addarginfo (NULL, arg_ainfo);
341
342 // "debc" - whether or not end date is prechristian
343 arg_ainfo.shortname = "debc";
344 arg_ainfo.longname = "end date bc";
345 arg_ainfo.multiplechar = false;
346 arg_ainfo.defaultstatus = cgiarginfo::weak;
347 arg_ainfo.argdefault = "0";
348 arg_ainfo.savedarginfo = cgiarginfo::must;
349 argsinfo.addarginfo (NULL, arg_ainfo);
350
351 // "qt" - 0 = text, 1 = form
352 arg_ainfo.shortname = "qt";
353 arg_ainfo.longname = "query type";
354 arg_ainfo.multiplechar = true; // can be empty or single char
355 arg_ainfo.defaultstatus = cgiarginfo::weak;
356 arg_ainfo.argdefault = g_EmptyText;
357 arg_ainfo.savedarginfo = cgiarginfo::must;
358 argsinfo.addarginfo (NULL, arg_ainfo);
359
360 // "qto" - 1 = text only, 2 = form only, 3 = text and form
361 arg_ainfo.shortname = "qto";
362 arg_ainfo.longname = "query type options";
363 arg_ainfo.multiplechar = true; // can be empty or single char
364 arg_ainfo.defaultstatus = cgiarginfo::weak;
365 arg_ainfo.argdefault = g_EmptyText;
366 arg_ainfo.savedarginfo = cgiarginfo::must;
367 argsinfo.addarginfo (NULL, arg_ainfo);
368
369 // "qb" - 0 = regular, 1 = large
370 arg_ainfo.shortname = "qb";
371 arg_ainfo.longname = "query box type";
372 arg_ainfo.multiplechar = false;
373 arg_ainfo.defaultstatus = cgiarginfo::weak;
374 arg_ainfo.argdefault = "0";
375 arg_ainfo.savedarginfo = cgiarginfo::must;
376 argsinfo.addarginfo (NULL, arg_ainfo);
377
378 // "fqn" - number of fields in the query form
379 arg_ainfo.shortname = "fqn";
380 arg_ainfo.longname = "form query num fields";
381 arg_ainfo.multiplechar = true;
382 arg_ainfo.defaultstatus = cgiarginfo::weak;
383 arg_ainfo.argdefault = "4";
384 arg_ainfo.savedarginfo = cgiarginfo::must;
385 argsinfo.addarginfo (NULL, arg_ainfo);
386
387 // "fqf" - the list of field names in the form query
388 // - a comma separated list
389 arg_ainfo.shortname = "fqf";
390 arg_ainfo.longname = "form query fields";
391 arg_ainfo.multiplechar = true;
392 arg_ainfo.defaultstatus = cgiarginfo::weak;
393 arg_ainfo.argdefault = g_EmptyText;
394 arg_ainfo.savedarginfo = cgiarginfo::must;
395 argsinfo.addarginfo (NULL, arg_ainfo);
396
397 // "fqv" - the list of values in the form query
398 // - a comma separated list
399 arg_ainfo.shortname = "fqv";
400 arg_ainfo.longname = "form query values";
401 arg_ainfo.multiplechar = true;
402 arg_ainfo.defaultstatus = cgiarginfo::weak;
403 arg_ainfo.argdefault = g_EmptyText;
404 arg_ainfo.savedarginfo = cgiarginfo::must;
405 argsinfo.addarginfo (NULL, arg_ainfo);
406
407
408 // "fqs" - the list of stemming options in the form query
409 // - a comma separated list
410 arg_ainfo.shortname = "fqs";
411 arg_ainfo.longname = "form query stems";
412 arg_ainfo.multiplechar = true;
413 arg_ainfo.defaultstatus = cgiarginfo::weak;
414 arg_ainfo.argdefault = g_EmptyText;
415 arg_ainfo.savedarginfo = cgiarginfo::must;
416 argsinfo.addarginfo (NULL, arg_ainfo);
417
418
419 // "fqk" - the list of casefolding options in the form query
420 // - a comma separated list
421 arg_ainfo.shortname = "fqk";
422 arg_ainfo.longname = "form query casefolds";
423 arg_ainfo.multiplechar = true;
424 arg_ainfo.defaultstatus = cgiarginfo::weak;
425 arg_ainfo.argdefault = g_EmptyText;
426 arg_ainfo.savedarginfo = cgiarginfo::must;
427 argsinfo.addarginfo (NULL, arg_ainfo);
428
429 // "fqc" - the list of boolean operators in the form query
430 // - a comma separated list
431 arg_ainfo.shortname = "fqc";
432 arg_ainfo.longname = "form query combines";
433 arg_ainfo.multiplechar = true;
434 arg_ainfo.defaultstatus = cgiarginfo::weak;
435 arg_ainfo.argdefault = g_EmptyText;
436 arg_ainfo.savedarginfo = cgiarginfo::must;
437 argsinfo.addarginfo (NULL, arg_ainfo);
438
439 // "fqa" - form query advanced - for "run query"
440 arg_ainfo.shortname = "fqa";
441 arg_ainfo.longname = "form query advanced query";
442 arg_ainfo.multiplechar = false;
443 arg_ainfo.defaultstatus = cgiarginfo::weak;
444 arg_ainfo.argdefault = "0";
445 arg_ainfo.savedarginfo = cgiarginfo::must;
446 argsinfo.addarginfo (NULL, arg_ainfo);
447
448 // "ifl" - I'm feeling lucky! (Go directly to a matching document)
449 arg_ainfo.shortname = "ifl";
450 arg_ainfo.longname = "i'm feeling lucky";
451 arg_ainfo.multiplechar = false;
452 arg_ainfo.defaultstatus = cgiarginfo::weak;
453 arg_ainfo.argdefault = g_EmptyText;
454 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
455 argsinfo.addarginfo (NULL, arg_ainfo);
456
457 // "ifln" - I'm feeling lucky number (Go directly to the nth matching document)
458 arg_ainfo.shortname = "ifln";
459 arg_ainfo.longname = "i'm feeling lucky number";
460 arg_ainfo.multiplechar = true;
461 arg_ainfo.defaultstatus = cgiarginfo::weak;
462 arg_ainfo.argdefault = "1";
463 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
464 argsinfo.addarginfo (NULL, arg_ainfo);
465
466 // "srn" - the next search result
467 arg_ainfo.shortname = "srn";
468 arg_ainfo.longname = "the next search result number";
469 arg_ainfo.multiplechar = true;
470 arg_ainfo.defaultstatus = cgiarginfo::weak;
471 arg_ainfo.argdefault = "0";
472 arg_ainfo.savedarginfo = cgiarginfo::must;
473 argsinfo.addarginfo (NULL, arg_ainfo);
474
475 // "srp" - the previous search result
476 arg_ainfo.shortname = "srp";
477 arg_ainfo.longname = "the previous search result number";
478 arg_ainfo.multiplechar = true;
479 arg_ainfo.defaultstatus = cgiarginfo::weak;
480 arg_ainfo.argdefault = "0";
481 arg_ainfo.savedarginfo = cgiarginfo::must;
482 argsinfo.addarginfo (NULL, arg_ainfo);
483
484 // "sf" - Sort field. Set to field to be used for sorting search reult
485 // set (only implemented for lucene collections at present).
486 arg_ainfo.shortname = "sf";
487 arg_ainfo.longname = "sort field";
488 arg_ainfo.multiplechar = true;
489 arg_ainfo.defaultstatus = cgiarginfo::weak;
490 arg_ainfo.argdefault = g_EmptyText;
491 arg_ainfo.savedarginfo = cgiarginfo::must;
492 argsinfo.addarginfo (NULL, arg_ainfo);
493
494 // "fuzziness" controls how closely the search terms must match
495 // 100 = exact match, 0 = very inexact match (only implemented for Lucene)
496 arg_ainfo.shortname = "fuzziness";
497 arg_ainfo.longname = "Lucene fuzziness value";
498 arg_ainfo.multiplechar = true;
499 arg_ainfo.defaultstatus = cgiarginfo::weak;
500 arg_ainfo.argdefault = g_EmptyText;
501 arg_ainfo.savedarginfo = cgiarginfo::must;
502 argsinfo.addarginfo (NULL, arg_ainfo);
503}
504
505void queryaction::configure (const text_t &key, const text_tarray &cfgline) {
506 action::configure (key, cfgline);
507}
508
509bool queryaction::init (ostream &logout) {
510 return action::init (logout);
511}
512
513bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
514 recptprotolistclass * /*protos*/, ostream &logout) {
515
516 // check t argument
517 int arg_t = args.getintarg("t");
518 if (arg_t != 0 && arg_t != 1) {
519 logout << "Warning: \"t\" argument out of range (" << arg_t << ")\n";
520 cgiarginfo *tinfo = argsinfo.getarginfo ("t");
521 if (tinfo != NULL) args["t"] = tinfo->argdefault;
522 }
523
524 // check k argument
525 int arg_k = args.getintarg("k");
526 if (arg_k != 0 && arg_k != 1) {
527 logout << "Warning: \"k\" argument out of range (" << arg_k << ")\n";
528 cgiarginfo *kinfo = argsinfo.getarginfo ("k");
529 if (kinfo != NULL) args["k"] = kinfo->argdefault;
530 }
531
532 // check s argument
533 int arg_s = args.getintarg("s");
534 if (arg_s != 0 && arg_s != 1) {
535 logout << "Warning: \"s\" argument out of range (" << arg_s << ")\n";
536 cgiarginfo *sinfo = argsinfo.getarginfo ("s");
537 if (sinfo != NULL) args["s"] = sinfo->argdefault;
538 }
539
540 // check m argument
541 int arg_m = args.getintarg("m");
542 if (arg_m < -1) {
543 logout << "Warning: \"m\" argument less than -1 (" << arg_m << ")\n";
544 cgiarginfo *minfo = argsinfo.getarginfo ("m");
545 if (minfo != NULL) args["m"] = minfo->argdefault;
546 }
547
548 // check o argument
549 int arg_o = args.getintarg("o");
550 if (arg_o < -1) {
551 logout << "Warning: \"o\" argument less than -1 (" << arg_o << ")\n";
552 cgiarginfo *oinfo = argsinfo.getarginfo ("o");
553 if (oinfo != NULL) args["o"] = oinfo->argdefault;
554 }
555
556 // check r argument
557 int arg_r = args.getintarg("r");
558 if (arg_r < 1) {
559 logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";
560 cgiarginfo *rinfo = argsinfo.getarginfo ("r");
561 if (rinfo != NULL) args["r"] = rinfo->argdefault;
562 }
563 //check hd argument
564 int arg_hd = args.getintarg("hd");
565 if (arg_hd <0 ) {
566 logout << "Warning: \"hd\" argument less than 0 (" << arg_hd << ")\n";
567 cgiarginfo *hdinfo = argsinfo.getarginfo ("hd");
568 if (hdinfo != NULL) args["hd"] = hdinfo->argdefault;
569 }
570
571 //check hs argument
572 int arg_hs = args.getintarg("hs");
573 if (arg_hs !=0 && arg_hs !=1) {
574 logout << "Warning: \"hs\" argument out of range (" << arg_hs << ")\n";
575 cgiarginfo *hsinfo = argsinfo.getarginfo ("hs");
576 if (hsinfo != NULL) args["hs"] = hsinfo->argdefault;
577 }
578
579 // check ct argument
580 int arg_ct = args.getintarg("ct");
581 if (arg_ct < 0 || arg_ct > 2) {
582 logout << "Warning: \"ct\" argument out of range (" << arg_ct << ")\n";
583 cgiarginfo *ctinfo = argsinfo.getarginfo ("ct");
584 if (ctinfo != NULL) args["ct"] = ctinfo->argdefault;
585 }
586
587 // check qt argument
588 int arg_qt = args.getintarg("qt");
589 if (arg_qt !=0 && arg_qt !=1) {
590 logout << "Warning: \"qt\" argument out of range (" << arg_qt << ")\n";
591 cgiarginfo *qtinfo = argsinfo.getarginfo ("qt");
592 if (qtinfo != NULL) args["qt"] = qtinfo->argdefault;
593 }
594
595 // check qb argument
596 int arg_qb = args.getintarg("qb");
597 if (arg_qb !=0 && arg_qb !=1) {
598 logout << "Warning: \"qb\" argument out of range (" << arg_qb << ")\n";
599 cgiarginfo *qbinfo = argsinfo.getarginfo ("qb");
600 if (qbinfo != NULL) args["qb"] = qbinfo->argdefault;
601 }
602
603 // check fqa argument
604 int arg_fqa = args.getintarg("fqa");
605 if (arg_fqa !=0 && arg_fqa !=1) {
606 logout << "Warning: \"fqa\" argument out of range (" << arg_fqa << ")\n";
607 cgiarginfo *fqainfo = argsinfo.getarginfo ("fqa");
608 if (fqainfo != NULL) args["fqa"] = fqainfo->argdefault;
609 }
610
611 // check fqn argument
612 int arg_fqn = args.getintarg("fqn");
613 if (arg_fqn < -1) {
614 logout << "Warning: \"fqn\" argument less than -1 (" << arg_fqn << ")\n";
615 cgiarginfo *fqninfo = argsinfo.getarginfo ("fqn");
616 if (fqninfo != NULL) args["fqn"] = fqninfo->argdefault;
617 }
618
619 return true;
620}
621
622void queryaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
623 response_t &response, text_t &response_data,
624 ostream &/*logout*/) {
625 // If this is an "I'm feeling lucky" request, we don't know the target location until later
626 if (!args["ifl"].empty()) {
627 response = undecided_location;
628 return;
629 }
630
631 response = content;
632 response_data = "text/html";
633}
634
635void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
636 recptprotolistclass * protos,
637 ostream &logout) {
638
639 // define_internal_macros sets the following macros:
640
641 // The following macros are set later (in define_query_macros) as they can't be set until
642 // the query has been done.
643 // _quotedquery_ the part of the query string that was quoted for post-processing
644 // _freqmsg_ the term frequency string
645
646 // _resultline_ the "x documents matched the query" string
647
648 // _prevfirst_ these are used when setting up the links to previous/next
649 // _prevlast_ pages of results (_thisfirst_ and _thislast_ are used to set
650 // _nextfirst_ the 'results x-x for query: xxxx' string in the title bar)
651 // _nextlast_
652 // _thisfirst_
653 // _thislast_
654
655
656 define_form_macros(disp, args, protos, logout);
657
658 define_query_interface(disp, args, protos, logout);
659
660
661}
662
663void queryaction::define_query_interface(displayclass &disp,
664 cgiargsclass &args,
665 recptprotolistclass * protos,
666 ostream &logout){
667 text_t collection = args["c"];
668
669 //check that the protocol is alive
670 recptproto* colproto = protos->getrecptproto (collection, logout);
671 if(colproto == NULL) {
672 logout << "ERROR: Null collection protocol trying to query"
673 << collection.getcstr() << "\n";
674 return;
675 }
676
677 //check the collection is responding/in place
678 ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(colproto, collection,
679 logout);
680 if(colinfo == NULL){
681 logout << "ERROR: Null returned for get_collectinfo_ptr on "
682 << collection.getcstr() << "in queryaction::define_query_interface\n";
683 return;
684 }
685
686 text_tmap::iterator check = colinfo->format.find("QueryInterface");
687 if(check != colinfo->format.end()){
688 if((*check).second=="DateSearch"){
689 text_t current = "_datesearch_";
690 disp.setmacro("optdatesearch","query",current);
691 }
692 }
693}
694
695
696// sets the selection box macros _hselection_, _jselection_, _nselection_ _gselection_, fqfselection_
697void queryaction::set_option_macro (const text_t &macroname,
698 text_t current_value,
699 bool display_single,
700 bool add_js_update,
701 const FilterOption_t &option,
702 displayclass &disp) {
703
704 if (option.validValues.empty()) return;
705 if (option.validValues.size() == 1) {
706 if (display_single) {
707 disp.setmacro (macroname + "selection", displayclass::defaultpackage, "_" + option.defaultValue + "_");
708 }
709 return;
710 }
711 if (option.validValues.size() < 2) return;
712
713 text_t macrovalue = "<select name=\"" + macroname + "\"";
714 if (add_js_update) {
715 macrovalue += " onChange=\"update"+macroname+"();\"";
716 }
717 macrovalue += ">\n";
718
719 if (current_value.empty()) current_value = option.defaultValue;
720
721 text_tarray::const_iterator thisvalue = option.validValues.begin();
722 text_tarray::const_iterator endvalue = option.validValues.end();
723
724 while (thisvalue != endvalue) {
725 macrovalue += "<option value=\"" + *thisvalue + "\"";
726 if (*thisvalue == current_value)
727 macrovalue += " selected";
728 macrovalue += ">_" + *thisvalue + "_\n";
729 ++thisvalue;
730 }
731 macrovalue += "</select>\n";
732 disp.setmacro (macroname + "selection", displayclass::defaultpackage, macrovalue);
733}
734
735
736void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args,
737 recptprotolistclass *protos, ostream &logout) {
738
739 // define_external_macros sets the following macros:
740
741 // some or all of these may not be required to be set
742 // _hselection_, _h2selection_ the selection box for the main part of the index
743 // _jselection_, _j2selection_ the selection box for the subcollection part of the index
744 // _nselection_, _n2selection_ the selection box for the language part of the index
745 // _cq2selection the selection box for combining two queries
746
747 // _gselection_, the selection box forlevels (mgpp)
748 // _fqfselection_, the selection box for index/fields (mgpp)
749 // can't do anything if collectproto is null (i.e. no collection was specified)
750 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
751 if (collectproto == NULL) return;
752
753 ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(collectproto,
754 args["c"],
755 logout);
756 set_query_type_args(colinfo, args);
757 set_stem_index_args(colinfo, args);
758
759 comerror_t err;
760 InfoFilterOptionsResponse_t response;
761 InfoFilterOptionsRequest_t request;
762 request.filterName = "QueryFilter";
763
764 collectproto->get_filteroptions (args["c"], request, response, err, logout);
765 if (err == noError) {
766
767 FilterOption_tmap::const_iterator it;
768 FilterOption_tmap::const_iterator end = response.filterOptions.end();
769
770 // _hselection_ and _h2selection_ (Index)
771 it = response.filterOptions.find ("Index");
772 if (it != end) set_option_macro ("h", args["h"], true, false, (*it).second, disp);
773 if (it != end) set_option_macro ("h2", args["h2"], true,false, (*it).second, disp);
774
775 // _jselection_ and _j2selection_ (Subcollection)
776 it = response.filterOptions.find ("Subcollection");
777 if (it != end) set_option_macro ("j", args["j"], true,false, (*it).second, disp);
778 if (it != end) set_option_macro ("j2", args["j2"], true,false, (*it).second, disp);
779
780 // _nselection_ and _n2selection_ (Language)
781 it = response.filterOptions.find ("Language");
782 if (it != end) set_option_macro ("n", args["n"], true,false, (*it).second, disp);
783 if (it != end) set_option_macro ("n2", args["n2"], true,false, (*it).second, disp);
784
785 // _cq2selection_ (CombineQuery)
786 it = response.filterOptions.find ("CombineQuery");
787 if (it != end) set_option_macro ("cq2", args["cq2"], true,false, (*it).second, disp);
788
789 if ((args["ct"] == "1") || (args["ct"] == "2")) { // mgpp/lucene collections
790 // _gselection_ (Level)
791 it = response.filterOptions.find("Level");
792 if (it!=end) {
793 set_option_macro("g", args["g"], false, false, (*it).second, disp);
794 if (args["qt"]=="1") { // form search
795 set_gformselection_macro(args["g"], (*it).second, disp);
796 }
797 }
798 // _fqfselection_ field list
799 it = response.filterOptions.find("IndexField");
800 if (it!=end) {
801 bool form_search = false;
802 if (args["qto"]=="2" || args["qt"]=="1") {
803 form_search = true;
804 }
805 set_option_macro ("fqf", args["fqf"], true, form_search, (*it).second, disp);
806 if (args["ct"] == "2") {// lucene
807 // set the sort field macro
808 set_sfselection_macro(args["sf"], (*it).second, disp);
809 }
810 }
811 }
812 }
813} // define external macros
814
815void queryaction::set_sfselection_macro(text_t current_value,
816 const FilterOption_t &option,
817 displayclass &disp) {
818
819 // we need at least one option here to continue
820 if (option.validValues.size() < 1) {
821 return;
822 }
823
824 text_t macrovalue = "<select name=\"sf\">\n";
825
826 if (current_value.empty()) current_value = "";
827
828 // we give a rank option first
829 macrovalue += "<option value=\"\"";
830 if (current_value == "") {
831 macrovalue += " selected";
832 }
833 macrovalue += ">_query:textsortbyrank_\n";
834
835 text_tarray::const_iterator thisvalue = option.validValues.begin();
836 text_tarray::const_iterator endvalue = option.validValues.end();
837 int valid_count = 0;
838 while (thisvalue != endvalue) {
839 if (*thisvalue != "ZZ" && *thisvalue != "TX") {
840 ++valid_count;
841 macrovalue += "<option value=\"by" + *thisvalue + "\"";
842 if (current_value == "by"+*thisvalue)
843 macrovalue += " selected";
844 macrovalue += ">_" + *thisvalue + "_\n";
845 }
846 ++thisvalue;
847 }
848 macrovalue += "</select>";
849 if (valid_count > 0) {
850 disp.setmacro ("sfselection", displayclass::defaultpackage, macrovalue);
851 }
852
853}
854
855// sets the selection box macro _gformselection_.
856// the default for _gformselection_ is _gselection_
857void queryaction::set_gformselection_macro (text_t current_value,
858 const FilterOption_t &option,
859 displayclass &disp) {
860
861 if (option.validValues.size() <= 1) {
862 return;
863 }
864 // we need to check to see if there is paragraph present
865 text_tarray::const_iterator thisvalue = option.validValues.begin();
866 text_tarray::const_iterator endvalue = option.validValues.end();
867
868 bool has_paras = false;
869 while (thisvalue != endvalue) {
870 if (*thisvalue == "Para") {
871 has_paras = true;
872 break;
873 }
874 ++thisvalue;
875 }
876 if (!has_paras) return; // there is no difference between the form selection and the normal one
877
878 if (option.validValues.size() == 2) {
879 // we will only have one value, but we will still put it in as a text string
880 int opt = 0;
881 if (option.validValues[0] == "Para") {
882 opt = 1;
883 }
884 disp.setmacro ("gformselection", displayclass::defaultpackage, "_"+option.validValues[opt]+"_");
885 return;
886 }
887
888 // there will be a select box
889 text_t macrovalue = "<select name=\"g\">\n";
890
891 if (current_value.empty()) current_value = option.defaultValue;
892
893 thisvalue = option.validValues.begin();
894
895 while (thisvalue != endvalue) {
896 if (*thisvalue != "Para") {
897 macrovalue += "<option value=\"" + *thisvalue + "\"";
898 if (*thisvalue == current_value)
899 macrovalue += " selected";
900 macrovalue += ">_" + *thisvalue + "_\n";
901 }
902 ++thisvalue;
903 }
904 macrovalue += "</select>\n";
905 disp.setmacro ("gformselection", displayclass::defaultpackage, macrovalue);
906}
907void queryaction::define_form_macros (displayclass &disp, cgiargsclass &args,
908 recptprotolistclass *protos, ostream &logout) {
909
910 // defines the following macros
911 // _regformlist_
912 // _advformlist_
913
914 if (args["ct"]=="0" || args["qto"]=="1" || (args["qto"]=="3" && args["qt"] == "0") ) // mg, or mgpp/lucene with plain only, or mgpp with both, but set to plain
915 return; // dont need these macros
916
917 text_t form = "";
918 int argfqn = args.getintarg("fqn");
919
920 if (args["b"] == "1") { // advanced form
921 form += "_firstadvformelement_\n";
922 for (int i=1; i<argfqn; ++i) {
923 form += "_advformelement_\n";
924 }
925 disp.setmacro("advformlist", "query", form);
926 }
927 else { // simple form
928 for (int i=0; i<argfqn; ++i) {
929 form += "_regformelement_\n";
930 }
931 disp.setmacro("regformlist", "query", form);
932 }
933
934}
935
936void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,
937 recptprotolistclass *protos, ostream &logout) {
938
939 // defines the following macros
940 // _searchhistorylist_
941
942 text_t historylist;
943 int arghd = args.getintarg("hd");
944 if (arghd == 0) {
945 historylist="";
946 }
947 else {
948 historylist = "<!-- Search History List -->\n";
949
950 text_t userid = args["z"];
951 text_tarray entries;
952 if (get_history_info (userid, entries, gdbmhome, logout)) {
953 int count = 1;
954 text_tarray::iterator here = entries.begin();
955 text_tarray::iterator end = entries.end();
956 int numrecords=(int)entries.size();
957 if (numrecords>arghd) { // only display some of them
958 numrecords = arghd;
959 }
960 historylist += "<form action=\"_gwcgi_\" name=\"HistoryForm\"><table width=\"537\">\n";
961
962 for (int i=0; i<numrecords;++i) {
963 text_t query;
964 text_t numdocs;
965 text_t cgiargs;
966 text_t userinfo;
967 text_t escquery;
968 split_saved_query(entries[i],numdocs,cgiargs);
969 parse_saved_args(cgiargs, "q", query); // get query string out
970 decode_cgi_arg(query); // un cgisafe it
971 escquery = escape_quotes(query); // escape the quotes and newlines
972 text_t histvalue = "histvalue";
973 histvalue += i;
974 disp.setmacro(histvalue, "query", escquery);
975 format_user_info(cgiargs, userinfo, args, protos, logout);
976
977 historylist += "<tr><td align=\"right\">_imagehistbutton_(";
978 historylist += i;
979 historylist += ")</td>\n";
980 historylist += "<td><table border=\"1\" cellspacing=\"0\" ";
981 historylist += "cellpadding=\"0\"><tr><td width=\"365\" align=\"left\">"
982 + query
983 + "</td></tr></table></td><td width=\"110\" align=\"center\"><small>"
984 + numdocs;
985 if (numdocs == 1) historylist += " _texthresult_";
986 else historylist += " _texthresults_";
987 if (!userinfo.empty()) {
988 historylist += "<br>( "+userinfo+" )";
989 }
990 historylist += "</small></td>\n";
991 }
992 historylist+="</table></form>\n\n";
993
994 } // if get history info
995 else {
996 historylist += "_textnohistory_";
997 }
998 historylist += "<! ---- end of history list ----->\n";
999 } // else display list
1000 disp.setmacro("searchhistorylist", "query", historylist);
1001
1002} // define history macros
1003
1004void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos,
1005 displayclass &disp, outconvertclass &outconvert,
1006 ostream &textout, ostream &logout) {
1007
1008 ColInfoResponse_t *cinfo = NULL;
1009 comerror_t err;
1010 InfoFilterOptionsResponse_t fresponse;
1011 InfoFilterOptionsRequest_t frequest;
1012 frequest.filterName = "QueryFilter";
1013
1014 text_t &index = args["h"];
1015 text_t &subcollection = args["j"];
1016 text_t &language = args["n"];
1017
1018 text_tset collections;
1019 text_t arg_cc = args["cc"];
1020 decode_cgi_arg (arg_cc);
1021 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
1022
1023 textout << outconvert << disp << "_query:header_\n"
1024 << "<center>_navigationbar_</center><br>\n"
1025 << "<form name=\"QueryForm\" method=\"get\" action=\"_gwcgi_\">\n"
1026 << "<input type=\"hidden\" name=\"a\" value=\"q\">\n"
1027 << "<input type=\"hidden\" name=\"site\" value=\"_cgiargsite_\"\n"
1028 << "<input type=\"hidden\" name=\"e\" value=\"_compressedoptions_\">\n"
1029 << "<input type=\"hidden\" name=\"ccp\" value=\"1\">\n"
1030 << "<center><table width=\"_pagewidth_\"><tr valign=\"top\">\n"
1031 << "<td>Select collections to search for \"" << args["q"]
1032 << "\" <i>(index=" << index << " subcollection=" << subcollection
1033 << " language=" << language << ")</i></td>\n"
1034 << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n"
1035 << "</tr></table></center>\n"
1036 << "<center><table width=\"_pagewidth_\">\n"
1037 << "<tr><td>\n";
1038
1039 recptprotolistclass::iterator rprotolist_here = protos->begin();
1040 recptprotolistclass::iterator rprotolist_end = protos->end();
1041 while (rprotolist_here != rprotolist_end) {
1042 if ((*rprotolist_here).p != NULL) {
1043
1044 text_tarray collist;
1045 (*rprotolist_here).p->get_collection_list (collist, err, logout);
1046 if (err == noError) {
1047 text_tarray::iterator collist_here = collist.begin();
1048 text_tarray::iterator collist_end = collist.end();
1049 while (collist_here != collist_end) {
1050
1051 cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
1052 // if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) {
1053 if (cinfo != NULL && (cinfo->buildDate > 0)) {
1054
1055 (*rprotolist_here).p->get_filteroptions (*collist_here, frequest, fresponse, err, logout);
1056 if (err == noError) {
1057
1058 FilterOption_tmap::const_iterator it;
1059 FilterOption_tmap::const_iterator end = fresponse.filterOptions.end();
1060 if (!index.empty()) {
1061 it = fresponse.filterOptions.find ("Index");
1062 if (it == end) {++collist_here; continue;}
1063 text_tarray::const_iterator there = (*it).second.validValues.begin();
1064 text_tarray::const_iterator tend = (*it).second.validValues.end();
1065 while (there != tend) {
1066 if (*there == index) break;
1067 ++there;
1068 }
1069 if (there == tend) {++collist_here; continue;}
1070 }
1071 if (!subcollection.empty()) {
1072 it = fresponse.filterOptions.find ("Subcollection");
1073 if (it == end) {++collist_here; continue;}
1074 text_tarray::const_iterator there = (*it).second.validValues.begin();
1075 text_tarray::const_iterator tend = (*it).second.validValues.end();
1076 while (there != tend) {
1077 if (*there == subcollection) break;
1078 ++there;
1079 }
1080 if (there == tend) {++collist_here; continue;}
1081 }
1082 if (!language.empty()) {
1083 it = fresponse.filterOptions.find ("Language");
1084 if (it == end) {++collist_here; continue;}
1085 text_tarray::const_iterator there = (*it).second.validValues.begin();
1086 text_tarray::const_iterator tend = (*it).second.validValues.end();
1087 while (there != tend) {
1088 if (*there == language) break;
1089 ++there;
1090 }
1091 if (there == tend) {++collist_here; continue;}
1092 }
1093
1094 // we've got a matching collection
1095 textout << outconvert << "<input type=\"checkbox\"";
1096
1097 text_tset::const_iterator t = collections.find (*collist_here);
1098 if (t != collections.end()) textout << outconvert << " checked";
1099
1100 text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
1101 if (collectionname.empty()) {
1102 collectionname = *collist_here;
1103 }
1104 textout << outconvert << disp
1105 << " name=\"cc\" value=\"" << *collist_here << "\">"
1106 << collectionname << "<br>\n";
1107
1108
1109 }
1110 }
1111 ++collist_here;
1112 }
1113 }
1114 }
1115 ++rprotolist_here;
1116 }
1117 textout << outconvert << disp
1118 << "</td></tr></table></center>\n"
1119 << "</form>\n"
1120 << "_query:footer_\n";
1121
1122}
1123
1124bool queryaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
1125 browsermapclass *browsers, displayclass &disp,
1126 outconvertclass &outconvert, ostream &textout,
1127 ostream &logout) {
1128
1129 if (recpt == NULL) {
1130 logout << "ERROR (queryaction::do_action): This action does not contain information\n"
1131 << " about any receptionists. The method set_receptionist was probably\n"
1132 << " not called from the module which instantiated this action.\n";
1133 return true;
1134 }
1135
1136
1137
1138 if (args["ccs"] == "1") {
1139 if (!args["cc"].empty()) {
1140 // query the selected collections
1141 text_t::const_iterator b = args["cc"].begin();
1142 text_t::const_iterator e = args["cc"].end();
1143 if (findchar (b, e, ',') != e) {
1144 if (!search_multiple_collections (args, protos, browsers, disp, outconvert,
1145 textout, logout)) return false;
1146 return true;
1147 } else {
1148 if (!search_single_collection (args, args["cc"], protos, browsers, disp,
1149 outconvert, textout, logout)) return false;
1150 return true;
1151 }
1152 }
1153 }
1154
1155 // simply query the current collection
1156 if (!search_single_collection (args, args["c"], protos, browsers, disp,
1157 outconvert, textout, logout)) return false;
1158 return true;
1159}
1160
1161bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos,
1162 browsermapclass *browsers, displayclass &disp,
1163 outconvertclass &outconvert, ostream &textout,
1164 ostream &logout) {
1165
1166 text_tarray collections;
1167
1168 text_t arg_cc = args["cc"];
1169 decode_cgi_arg (arg_cc);
1170 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
1171
1172 if (collections.empty()) {
1173 logout << "queryaction::search_multiple_collections: No collections "
1174 << "set for doing multiple query - will search current collection\n";
1175 textout << outconvert << disp << "_query:textwarningnocollections_\n";
1176 return search_single_collection (args, args["c"], protos, browsers, disp,
1177 outconvert, textout, logout);
1178 }
1179
1180 // queryaction uses "VList" browser to display results,
1181 // a queries clasification is "Search"
1182 text_t browsertype = "VList";
1183 text_t classification = "Search";
1184
1185 QueryResult_tset results;
1186 map<text_t, colinfo_t, lttext_t> colinfomap;
1187
1188 ColInfoResponse_t *cinfo = NULL;
1189 recptproto *collectproto = NULL;
1190 comerror_t err;
1191 FilterRequest_t request;
1192 FilterResponse_t response;
1193 request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking;
1194 text_t freqmsg = "_textfreqmsg1_";
1195 int numdocs = 0;
1196 isapprox isApprox = Exact;
1197
1198 // what to do about segmentation for multiple colls??
1199 bool segment = false;
1200 text_t formattedstring = "";
1201 get_formatted_query_string(formattedstring, segment, args, disp, logout);
1202
1203 if (formattedstring.empty()) {
1204 // dont bother doing a query if no query string
1205 define_history_macros (disp, args, protos, logout);
1206 textout << outconvert << disp << "_query:header_\n"
1207 << "_query:content_";
1208 textout << outconvert << disp << "_query:footer_";
1209
1210 return true;
1211 }
1212 bool syntax_error = false;
1213
1214 set_queryfilter_options (request, formattedstring, args);
1215
1216 // need to retrieve maxdocs matches for each collection
1217 // (will eventually want to tidy this up, do so caching etc.)
1218 OptionValue_t option;
1219 option.name = "StartResults";
1220 option.value = "1";
1221 request.filterOptions.push_back (option);
1222
1223 option.name = "EndResults";
1224 option.value = args["m"];
1225 request.filterOptions.push_back (option);
1226
1227 text_tarray::iterator col_here = collections.begin();
1228 text_tarray::iterator col_end = collections.end();
1229
1230 map<text_t, int, lttext_t> termfreqs;
1231
1232 // just check the main col for formatting info - use individual format statements, or the main one?
1233
1234 browserclass *bptr = browsers->getbrowser (browsertype);
1235
1236 text_t main_col = args["c"];
1237 cinfo = recpt->get_collectinfo_ptr (collectproto, main_col, logout);
1238 if (cinfo == NULL) {
1239 logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL for '"<<main_col<<"'\n";
1240 return false;
1241 }
1242
1243 bool use_main_col_format = false;
1244 if (cinfo->ccsOptions & CCSUniformSearchResultsFormatting) {
1245 use_main_col_format = true;
1246 }
1247
1248 request.fields.erase (request.fields.begin(), request.fields.end());
1249 request.getParents = false;
1250 bptr->load_metadata_defaults (request.fields);
1251
1252 text_t formatstring;
1253 format_t *formatlistptr = new format_t();
1254 if (use_main_col_format) {
1255 // just get one format for main coll and use it for each subcol
1256 if (!get_formatstring (classification, browsertype,
1257 cinfo->format, formatstring)) {
1258 formatstring = bptr->get_default_formatstring();
1259 }
1260
1261 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1262 }
1263
1264 while (col_here != col_end) {
1265
1266 collectproto = protos->getrecptproto (*col_here, logout);
1267 if (collectproto == NULL) {
1268 logout << outconvert << "queryaction::search_multiple_collections: " << *col_here
1269 << " collection has a NULL collectproto, ignoring\n";
1270 ++col_here;
1271 continue;
1272 }
1273 cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
1274 if (cinfo == NULL) {
1275 logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL\n";
1276 ++col_here;
1277 continue;
1278 }
1279
1280 if (!use_main_col_format) {
1281 request.fields.erase (request.fields.begin(), request.fields.end());
1282 request.getParents = false;
1283 bptr->load_metadata_defaults (request.fields);
1284
1285 //browserclass *bptr = browsers->getbrowser (browsertype);
1286
1287 // get the formatstring if there is one
1288 if (!get_formatstring (classification, browsertype,
1289 cinfo->format, formatstring)) {
1290 formatstring = bptr->get_default_formatstring();
1291 }
1292
1293 formatlistptr = new format_t();
1294 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1295 }
1296
1297 colinfo_t thiscolinfo;
1298 thiscolinfo.formatlistptr = formatlistptr;
1299 thiscolinfo.browserptr = bptr;
1300 colinfomap[*col_here] = thiscolinfo;
1301
1302 // do the query
1303 collectproto->filter (*col_here, request, response, err, logout);
1304 if (err != noError && err != syntaxError) {
1305 outconvertclass text_t2ascii;
1306 logout << text_t2ascii
1307 << "queryaction::search_multiple_collections: call to QueryFilter failed "
1308 << "for " << *col_here << " collection (" << get_comerror_string (err) << ")\n";
1309 return false;
1310 }
1311
1312 if (err == syntaxError) {
1313 syntax_error = true;
1314 freqmsg = "_textinvalidquery_";
1315 // assume the syntax will be invalid for all colls
1316 break;
1317 }
1318 if (response.error_message == "TOO_MANY_CLAUSES") {
1319 freqmsg = "_textlucenetoomanyclauses_";
1320 break;
1321 }
1322 if (isApprox == Exact)
1323 isApprox = response.isApprox;
1324 else if (isApprox == MoreThan)
1325 if (response.isApprox == Approximate)
1326 isApprox = response.isApprox;
1327
1328 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
1329 TermInfo_tarray::const_iterator end_term = response.termInfo.end();
1330 while (this_term != end_term) {
1331 termfreqs[(*this_term).term] += (*this_term).freq;
1332 if ((col_here+1) == col_end) {
1333 freqmsg += (*this_term).term + ": " + termfreqs[(*this_term).term];
1334 if ((this_term+1) != end_term) freqmsg += ", ";
1335 }
1336 ++this_term;
1337 }
1338
1339 if (response.numDocs > 0) {
1340 numdocs += response.numDocs;
1341
1342 QueryResult_t thisresult;
1343 thisresult.collection = *col_here;
1344 ResultDocInfo_tarray::iterator doc_here = response.docInfo.begin();
1345 ResultDocInfo_tarray::iterator doc_end = response.docInfo.end();
1346 while (doc_here != doc_end) {
1347 thisresult.doc = *doc_here;
1348 results.insert (thisresult);
1349 ++doc_here;
1350 }
1351 }
1352 ++col_here;
1353 } // for each coll
1354
1355 text_t numdocs_t = numdocs;
1356 args["nmd"] = numdocs_t;
1357
1358 disp.setmacro ("freqmsg", "query", freqmsg);
1359
1360 define_query_macros( args, disp, numdocs, isApprox);
1361 // save the query if appropriate
1362 save_search_history(args, numdocs, isApprox);
1363 define_history_macros (disp, args, protos, logout);
1364
1365 textout << outconvert << disp << "_query:header_\n"
1366 << "_query:content_";
1367
1368 if (!syntax_error) {
1369
1370 // now go through each result and output it
1371 QueryResult_tset::iterator res_here = results.begin();
1372 QueryResult_tset::iterator res_end = results.end();
1373 text_tset metadata; // empty !!
1374 bool getParents = false; // don't care !!
1375 bool use_table;
1376 ResultDocInfo_t thisdoc;
1377 format_t *formatlistptr = NULL;
1378 browserclass *browserptr = NULL;
1379
1380 int count = 1;
1381 int firstdoc = args.getintarg("r");
1382 int hitsperpage = args.getintarg("o");
1383 int thislast = firstdoc + (hitsperpage - 1);
1384
1385 // output results
1386 while (res_here != res_end) {
1387 if (count < firstdoc) {++count; ++res_here; continue;}
1388 if (count > thislast) break;
1389
1390 formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
1391 browserptr = colinfomap[(*res_here).collection].browserptr;
1392 thisdoc = (*res_here).doc;
1393 use_table = is_table_content (formatlistptr);
1394
1395 collectproto = protos->getrecptproto ((*res_here).collection, logout);
1396 if (collectproto == NULL) {
1397 logout << outconvert << "queryaction::search_multiple_collections: " << (*res_here).collection
1398 << " collection has a NULL collectproto, ignoring results\n";
1399 ++res_here;
1400 continue;
1401 }
1402
1403 browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0,
1404 formatlistptr, use_table, metadata, getParents,
1405 collectproto, disp, outconvert, textout, logout);
1406 // textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
1407 ++res_here;
1408 ++count;
1409 }
1410 }
1411 textout << outconvert << disp << "_query:footer_";
1412
1413 // clean up the format_t pointers
1414 map<text_t, colinfo_t, lttext_t>::iterator here = colinfomap.begin();
1415 map<text_t, colinfo_t, lttext_t>::iterator end = colinfomap.end();
1416 while (here != end) {
1417 delete ((*here).second.formatlistptr);
1418 ++here;
1419 }
1420 return true;
1421}
1422
1423bool queryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
1424 recptprotolistclass *protos, browsermapclass *browsers,
1425 displayclass &disp, outconvertclass &outconvert,
1426 ostream &textout, ostream &logout) {
1427
1428 recptproto *collectproto = protos->getrecptproto (collection, logout);
1429 if (collectproto == NULL) {
1430 logout << outconvert << "queryaction::search_single_collection: " << collection
1431 << " collection has a NULL collectproto\n";
1432
1433 // Display the "this collection is not installed on this system" page
1434 disp.setmacro("cvariable", displayclass::defaultpackage, collection);
1435 disp.setmacro("content", "query", "<p>_textbadcollection_<p>");
1436
1437 textout << outconvert << disp << "_query:header_\n"
1438 << "_query:content_\n" << "_query:footer_\n";
1439 return true;
1440 }
1441
1442 // queryaction uses "VList" browser to display results,
1443 // a queries clasification is "Search"
1444 text_t browsertype = "VList";
1445 text_t classification = "Search";
1446
1447 comerror_t err;
1448 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
1449
1450 if (cinfo == NULL) {
1451 logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
1452 return false;
1453 }
1454
1455 bool segment = cinfo->isSegmented;
1456 browserclass *bptr = browsers->getbrowser (browsertype);
1457
1458 // get the formatstring if there is one
1459 text_t formatstring;
1460 if (!get_formatstring (classification, browsertype,
1461 cinfo->format, formatstring)) {
1462 formatstring = bptr->get_default_formatstring();
1463 }
1464 FilterRequest_t request;
1465 FilterResponse_t response;
1466
1467 text_t maxDoc_old = args["o"];
1468 text_t starts_old = args["r"];
1469
1470 //if the "ifl" argument is set ignore the "r" and "o" arg
1471 if(!args["ifl"].empty()){
1472 args["r"] = 1;
1473 args["o"] = args["m"];
1474 }
1475
1476
1477 bptr->set_filter_options (request, args);
1478 bptr->load_metadata_defaults (request.fields);
1479
1480 format_t *formatlistptr = new format_t();
1481 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1482
1483 // do the query
1484 request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
1485 text_t formattedstring = "";
1486 get_formatted_query_string(formattedstring, segment, args, disp, logout);
1487
1488
1489 if (!formattedstring.empty()) { // do the query
1490 // note! formattedstring is in unicode! mg and mgpp must convert!
1491 set_queryfilter_options (request, formattedstring, args);
1492
1493 collectproto->filter (collection, request, response, err, logout);
1494
1495 if (err != noError) {
1496 outconvertclass text_t2ascii;
1497 logout << text_t2ascii
1498 << "queryaction::search_single_collections: call to QueryFilter failed "
1499 << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
1500
1501 }
1502
1503 // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
1504 if (err == noError && !args["ifl"].empty()) {
1505 //Restore the "r" and "o" arg
1506 args["r"] = starts_old;
1507 args["o"] = maxDoc_old ;
1508
1509 //Find whether DocumentSearchResultLinks is enabled
1510 bool show_links = false;
1511 text_tmap::const_iterator format_here = cinfo->format.begin();
1512 text_tmap::const_iterator format_end = cinfo->format.end();
1513
1514 while (format_here != format_end) {
1515 if (((*format_here).first == "DocumentSearchResultLinks") &&
1516 ((*format_here).second == "true")){
1517 show_links = true;
1518 break;
1519 }
1520 ++format_here;
1521 }
1522
1523 if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1))
1524 {
1525 // Find the search result specified by the ifln argument
1526 ResultDocInfo_tarray::iterator thissection = response.docInfo.begin();
1527 int section_number = 1;
1528 int ifln = args["ifln"].getint();
1529
1530 while (section_number != ifln && thissection != response.docInfo.end()) {
1531 thissection++;
1532 section_number++;
1533 }
1534 // If the search result exists, go directly to it
1535 if (section_number == ifln && thissection != response.docInfo.end()) {
1536 // Location response (this URL must have "&" and not "&amp;"!)
1537 int num_docs = response.numDocs;
1538 int srn = 0;
1539 int srp = 0;
1540 if (show_links && section_number < num_docs ) {
1541 srn = section_number + 1;
1542 }
1543 if (show_links && section_number > 1 ) {
1544 srp = section_number - 1;
1545 }
1546
1547 textout << outconvert << disp << "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" << collection << "&cl=search&d=" << (*thissection).OID <<"&srn="<<srn<<"&srp="<<srp<< "\n\n";
1548 textout << flush;
1549
1550 return true;
1551 }
1552 }
1553
1554 // There weren't enough (or any) matching documents
1555 // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
1556 // done the right thing (because ifl was set), so we need to make sure the output is html
1557 textout << "Content-type: text/html\n\n";
1558
1559 }
1560
1561 if (err != noError) {
1562 disp.setmacro("resultline", "query", "_textnodocs_");
1563 if (err == syntaxError) {
1564 disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
1565 } else {
1566 disp.setmacro ("freqmsg", "query", "");
1567 }
1568 } else {
1569
1570 define_query_macros (args, disp, response.numDocs, response.isApprox);
1571 define_single_query_macros(args, disp, response);
1572 // save the query if appropriate
1573 save_search_history(args, response.numDocs, response.isApprox);
1574 }
1575
1576 // If Lucene threw a TooManyClauses exception, tell the user about it
1577 if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
1578 disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
1579 }
1580 }
1581 define_history_macros (disp, args, protos, logout);
1582
1583 textout << outconvert << disp << "_query:header_\n"
1584 << "_query:content_";
1585
1586 if (err == noError) {
1587 // output the results
1588 text_t numdocs_t = response.numDocs;
1589 args["nmd"] = numdocs_t;
1590 bool use_table = is_table_content (formatlistptr);
1591 bptr->output_section_group (response, args, collection, 0, formatlistptr,
1592 use_table, request.fields, request.getParents,
1593 collectproto, disp, outconvert, textout, logout);
1594 }
1595
1596 textout << outconvert << disp << "_query:footer_";
1597
1598 delete (formatlistptr);
1599
1600 return true;
1601}
1602
1603// does the formatting of the query string - either uses q for a text search
1604// or the form values for an form search
1605// also adds dates if appropriate in text search
1606void queryaction::get_formatted_query_string (text_t &formattedstring,
1607 bool segment,
1608 cgiargsclass &args,
1609 displayclass &disp,
1610 ostream &logout) {
1611 if (args["qt"]=="0" && args["qto"] != "2") { // normal text search
1612 formattedstring = args["q"];
1613 // remove & | ! for simple search,do segmentation if necessary
1614 format_querystring (formattedstring, args.getintarg("b"), segment);
1615 if (args["ct"]!=0) { // mgpp and lucene - need to add in tag info if appropriate
1616 format_field_info(formattedstring, args["fqf"], args.getintarg("ct"),
1617 args.getintarg("t"), args.getintarg("b"));
1618 }
1619
1620 add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
1621 args.getintarg("dsbc"), args.getintarg("debc"),
1622 args.getintarg("ct"));
1623 args["q"] = formattedstring;
1624
1625 }
1626 else if (args["qt"]=="1" || args["qto"]=="2"){ // form search
1627
1628 if (args["b"]=="1" && args["fqa"]=="1") { // explicit query
1629 formattedstring = args["q"];
1630 }
1631 else { // form search
1632 if (args["b"]=="0") { // regular form
1633 parse_reg_query_form(formattedstring, args, segment);
1634 }
1635 else { // advanced form
1636 parse_adv_query_form(formattedstring, args, segment);
1637 }
1638 args["q"] = formattedstring;
1639
1640 // reset the cgiargfqv macro - need to escape any quotes in it
1641 disp.setmacro("cgiargfqv", "query", escape_quotes(args["fqv"]));
1642
1643 // also reset the _cgiargq_ macro as it has changed now
1644 disp.setmacro("cgiargq", displayclass::defaultpackage, html_safe(args["q"]));
1645
1646 // reset the compressed options to include the q arg
1647 text_t compressedoptions = recpt->get_compressed_arg(args, logout);
1648 if (!compressedoptions.empty()) {
1649 disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
1650 // need a decoded version of compressedoptions for use within forms
1651 // as browsers encode values from forms before sending to server
1652 // (e.g. %25 becomes %2525)
1653 decode_cgi_arg (compressedoptions);
1654 if (args["w"] == "utf-8") { // if the encoding was utf-8, then compressed options was utf-8, and we need unicode.
1655 // if encoding wasn't utf-8, then compressed opotions may be screwed up, but seems to work for 8 bit encodings?
1656 compressedoptions = to_uni(compressedoptions);
1657 }
1658
1659 disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
1660 }
1661 } // form search
1662 } // args["qt"]=1
1663 else {
1664 logout << "ERROR (query_action::get_formatted_query_string): querytype not defined\n";
1665 }
1666}
1667
1668
1669// define_query_macros sets the macros that couldn't be set until the
1670// query had been done. Those macros are
1671// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
1672// _thisfirst_, and _thislast_ and _quotedquery_
1673// this has been simplified so it can be used with both search_single_coll
1674// and search_multiple_coll
1675void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
1676 int numdocs, isapprox isApprox) {
1677
1678 // set up _resultline_ macro
1679 text_t resline;
1680 int maxdocs = args.getintarg("m");
1681 if (num_phrases > 0) isApprox = Exact;
1682 if (maxdocs == -1) maxdocs = numdocs;
1683 else if (numdocs > maxdocs) {
1684 numdocs = maxdocs;
1685 isApprox = MoreThan;
1686 }
1687
1688 if (isApprox == Approximate) resline = "_textapprox_";
1689 else if (isApprox == MoreThan) resline = "_textmorethan_";
1690
1691 if (numdocs == 0) resline = "_textnodocs_";
1692 else if (numdocs == 1) resline += "_text1doc_";
1693 else resline += text_t(numdocs) + " _textlotsdocs_";
1694
1695 disp.setmacro("resultline", "query", resline);
1696
1697 int firstdoc = args.getintarg("r");
1698 int hitsperpage = args.getintarg("o");
1699 if (hitsperpage == -1) hitsperpage = numdocs;
1700
1701 // set up _thisfirst_ and _thislast_ macros
1702 disp.setmacro ("thisfirst", "query", firstdoc);
1703 int thislast = firstdoc + (hitsperpage - 1);
1704 if (thislast > numdocs) thislast = numdocs;
1705 disp.setmacro ("thislast", "query", thislast);
1706
1707 // set up _prevfirst_ and _prevlast_ macros
1708 if (firstdoc > 1) {
1709 disp.setmacro ("prevlast", "query", firstdoc - 1);
1710 int prevfirst = firstdoc - hitsperpage;
1711 if (prevfirst < 1) prevfirst = 1;
1712 disp.setmacro ("prevfirst", "query", prevfirst);
1713 }
1714
1715 // set up _nextfirst_ and _nextlast_ macros
1716 if (thislast < numdocs) {
1717 disp.setmacro ("nextfirst", "query", thislast + 1);
1718 int nextlast = thislast + hitsperpage;
1719 if (nextlast > numdocs) nextlast = numdocs;
1720 disp.setmacro ("nextlast", "query", nextlast);
1721 }
1722
1723 // do quoted query here cos we may have added quotes during query pre-processing
1724 if (args["ct"]==0) { // mg queries only, not mgpp
1725 // get the quoted bits of the query string and set _quotedquery_
1726 text_tarray phrases;
1727 get_phrases (args["q"], phrases);
1728 num_phrases = phrases.size();
1729 text_tarray::const_iterator phere = phrases.begin();
1730 text_tarray::const_iterator pend = phrases.end();
1731 bool first = true;
1732 text_t quotedquery;
1733 while (phere != pend) {
1734 if (!first)
1735 if ((phere +1) == pend) quotedquery += " and ";
1736 else quotedquery += ", ";
1737
1738 quotedquery += "\"" + *phere + "\"";
1739 first = false;
1740 ++phere;
1741 }
1742 if (args.getintarg("s") && !quotedquery.empty()) quotedquery += "_textstemon_";
1743 disp.setmacro ("quotedquery", "query", quotedquery);
1744 }
1745
1746}
1747
1748// define_single_query_macros sets the extra macros for search_single_coll
1749// that couldn't be set until the query had been done. Those macros are
1750// _freqmsg_ and _stopwordsmsg_
1751void queryaction::define_single_query_macros (cgiargsclass &args,
1752 displayclass &disp,
1753 const FilterResponse_t &response) {
1754 // set up _freqmsg_ and _stopwordsmsg_ macros
1755
1756 text_t freqmsg = "";
1757 freqmsg = "_textfreqmsg1_";
1758 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
1759 TermInfo_tarray::const_iterator end_term = response.termInfo.end();
1760 while (this_term != end_term) {
1761 freqmsg += (*this_term).term + ": " + (*this_term).freq;
1762 if ((this_term + 1) != end_term)
1763 freqmsg += ", ";
1764 ++this_term;
1765 }
1766 disp.setmacro ("freqmsg", "query", freqmsg);
1767
1768 text_tset::const_iterator this_stopword = response.stopwords.begin();
1769 text_tset::const_iterator end_stopword = response.stopwords.end();
1770 if (this_stopword != end_stopword) {
1771 text_t stopwordsmsg = "_textstopwordsmsg_ ";
1772 while (this_stopword != end_stopword) {
1773 if (stopwordsmsg != "_textstopwordsmsg_ ") {
1774 stopwordsmsg += ", ";
1775 }
1776 stopwordsmsg += (*this_stopword);
1777 ++this_stopword;
1778 }
1779 disp.setmacro("stopwordsmsg", "query", stopwordsmsg);
1780 }
1781}
1782
1783// should this change for cross coll search??
1784bool queryaction::save_search_history (cgiargsclass &args, int numdocs,
1785 isapprox isApprox) {
1786 if (args["q"]=="") return true; // null query, dont save
1787 if (args["hs"]=="0") return true; // only save when submit query pressed
1788
1789 // get userid
1790 text_t userid = args["z"];
1791
1792 // the number of docs goes on the front of the query string
1793 text_t query = text_t(numdocs);
1794 if (isApprox==MoreThan) { // there were more docs found
1795 query.push_back('+');
1796 }
1797 query += "c="+args["c"];
1798 query += ";h="+args["h"];
1799 query += ";t="+args["t"];
1800 query += ";b="+args["b"];
1801 query += ";j="+args["j"];
1802 query += ";n="+args["n"];
1803 query += ";s="+args["s"];
1804 query += ";k="+args["k"];
1805 query += ";g="+args["g"];
1806
1807 text_t qstring = args["q"];
1808 //text_t formattedquery =cgi_safe(qstring);
1809 //query += "&amp;q="+formattedquery;
1810 query += ";q="+qstring;
1811 bool display=false;
1812 int hd = args.getintarg("hd");
1813 if (hd > 0) display=true;
1814 if (set_history_info(userid, query, gdbmhome, display)) return true;
1815 else return false;
1816
1817
1818}
1819
Note: See TracBrowser for help on using the repository browser.