source: gsdl/trunk/runtime-src/src/recpt/queryaction.cpp@ 20593

Last change on this file since 20593 was 20481, checked in by kjdon, 15 years ago

added get_plain_query_terms method to querytools (only partially implemented so far), and use it in queryaction to clean up the q arg and save as _queryterms_ macro - used for PDF search parameter

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 61.5 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 // add a queryterms macro for plain version of search terms
814 if (!args["q"].empty()) {
815 disp.setmacro ("queryterms", displayclass::defaultpackage, get_plain_query_terms(args["q"]));
816 }
817 }
818} // define external macros
819
820void queryaction::set_sfselection_macro(text_t current_value,
821 const FilterOption_t &option,
822 displayclass &disp) {
823
824 // we need at least one option here to continue
825 if (option.validValues.size() < 1) {
826 return;
827 }
828
829 text_t macrovalue = "<select name=\"sf\">\n";
830
831 if (current_value.empty()) current_value = "";
832
833 // we give a rank option first
834 macrovalue += "<option value=\"\"";
835 if (current_value == "") {
836 macrovalue += " selected";
837 }
838 macrovalue += ">_query:textsortbyrank_\n";
839
840 text_tarray::const_iterator thisvalue = option.validValues.begin();
841 text_tarray::const_iterator endvalue = option.validValues.end();
842 int valid_count = 0;
843 while (thisvalue != endvalue) {
844 if (*thisvalue != "ZZ" && *thisvalue != "TX") {
845 ++valid_count;
846 macrovalue += "<option value=\"by" + *thisvalue + "\"";
847 if (current_value == "by"+*thisvalue)
848 macrovalue += " selected";
849 macrovalue += ">_" + *thisvalue + "_\n";
850 }
851 ++thisvalue;
852 }
853 macrovalue += "</select>";
854 if (valid_count > 0) {
855 disp.setmacro ("sfselection", displayclass::defaultpackage, macrovalue);
856 }
857
858}
859
860// sets the selection box macro _gformselection_.
861// the default for _gformselection_ is _gselection_
862void queryaction::set_gformselection_macro (text_t current_value,
863 const FilterOption_t &option,
864 displayclass &disp) {
865
866 if (option.validValues.size() <= 1) {
867 return;
868 }
869 // we need to check to see if there is paragraph present
870 text_tarray::const_iterator thisvalue = option.validValues.begin();
871 text_tarray::const_iterator endvalue = option.validValues.end();
872
873 bool has_paras = false;
874 while (thisvalue != endvalue) {
875 if (*thisvalue == "Para") {
876 has_paras = true;
877 break;
878 }
879 ++thisvalue;
880 }
881 if (!has_paras) return; // there is no difference between the form selection and the normal one
882
883 if (option.validValues.size() == 2) {
884 // we will only have one value, but we will still put it in as a text string
885 int opt = 0;
886 if (option.validValues[0] == "Para") {
887 opt = 1;
888 }
889 disp.setmacro ("gformselection", displayclass::defaultpackage, "_"+option.validValues[opt]+"_");
890 return;
891 }
892
893 // there will be a select box
894 text_t macrovalue = "<select name=\"g\">\n";
895
896 if (current_value.empty()) current_value = option.defaultValue;
897
898 thisvalue = option.validValues.begin();
899
900 while (thisvalue != endvalue) {
901 if (*thisvalue != "Para") {
902 macrovalue += "<option value=\"" + *thisvalue + "\"";
903 if (*thisvalue == current_value)
904 macrovalue += " selected";
905 macrovalue += ">_" + *thisvalue + "_\n";
906 }
907 ++thisvalue;
908 }
909 macrovalue += "</select>\n";
910 disp.setmacro ("gformselection", displayclass::defaultpackage, macrovalue);
911}
912void queryaction::define_form_macros (displayclass &disp, cgiargsclass &args,
913 recptprotolistclass *protos, ostream &logout) {
914
915 // defines the following macros
916 // _regformlist_
917 // _advformlist_
918
919 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
920 return; // dont need these macros
921
922 text_t form = "";
923 int argfqn = args.getintarg("fqn");
924
925 if (args["b"] == "1") { // advanced form
926 form += "_firstadvformelement_\n";
927 for (int i=1; i<argfqn; ++i) {
928 form += "_advformelement_\n";
929 }
930 disp.setmacro("advformlist", "query", form);
931 }
932 else { // simple form
933 for (int i=0; i<argfqn; ++i) {
934 form += "_regformelement_\n";
935 }
936 disp.setmacro("regformlist", "query", form);
937 }
938
939}
940
941void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,
942 recptprotolistclass *protos, ostream &logout) {
943
944 // defines the following macros
945 // _searchhistorylist_
946
947 text_t historylist;
948 int arghd = args.getintarg("hd");
949 if (arghd == 0) {
950 historylist="";
951 }
952 else {
953 historylist = "<!-- Search History List -->\n";
954
955 text_t userid = args["z"];
956 text_tarray entries;
957 if (get_history_info (userid, entries, dbhome, logout)) {
958 int count = 1;
959 text_tarray::iterator here = entries.begin();
960 text_tarray::iterator end = entries.end();
961 int numrecords=(int)entries.size();
962 if (numrecords>arghd) { // only display some of them
963 numrecords = arghd;
964 }
965 historylist += "<form action=\"_gwcgi_\" name=\"HistoryForm\"><table width=\"537\">\n";
966
967 for (int i=0; i<numrecords;++i) {
968 text_t query;
969 text_t numdocs;
970 text_t cgiargs;
971 text_t userinfo;
972 text_t escquery;
973 split_saved_query(entries[i],numdocs,cgiargs);
974 parse_saved_args(cgiargs, "q", query); // get query string out
975 decode_cgi_arg(query); // un cgisafe it
976 escquery = escape_quotes(query); // escape the quotes and newlines
977 text_t histvalue = "histvalue";
978 histvalue += i;
979 disp.setmacro(histvalue, "query", escquery);
980 format_user_info(cgiargs, userinfo, args, protos, logout);
981
982 historylist += "<tr><td align=\"right\">_imagehistbutton_(";
983 historylist += i;
984 historylist += ")</td>\n";
985 historylist += "<td><table border=\"1\" cellspacing=\"0\" ";
986 historylist += "cellpadding=\"0\"><tr><td width=\"365\" align=\"left\">"
987 + query
988 + "</td></tr></table></td><td width=\"110\" align=\"center\"><small>"
989 + numdocs;
990 if (numdocs == 1) historylist += " _texthresult_";
991 else historylist += " _texthresults_";
992 if (!userinfo.empty()) {
993 historylist += "<br>( "+userinfo+" )";
994 }
995 historylist += "</small></td>\n";
996 }
997 historylist+="</table></form>\n\n";
998
999 } // if get history info
1000 else {
1001 historylist += "_textnohistory_";
1002 }
1003 historylist += "<! ---- end of history list ----->\n";
1004 } // else display list
1005 disp.setmacro("searchhistorylist", "query", historylist);
1006
1007} // define history macros
1008
1009void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos,
1010 displayclass &disp, outconvertclass &outconvert,
1011 ostream &textout, ostream &logout) {
1012
1013 ColInfoResponse_t *cinfo = NULL;
1014 comerror_t err;
1015 InfoFilterOptionsResponse_t fresponse;
1016 InfoFilterOptionsRequest_t frequest;
1017 frequest.filterName = "QueryFilter";
1018
1019 text_t &index = args["h"];
1020 text_t &subcollection = args["j"];
1021 text_t &language = args["n"];
1022
1023 text_tset collections;
1024 text_t arg_cc = args["cc"];
1025 decode_cgi_arg (arg_cc);
1026 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
1027
1028 textout << outconvert << disp << "_query:header_\n"
1029 << "<center>_navigationbar_</center><br>\n"
1030 << "<form name=\"QueryForm\" method=\"get\" action=\"_gwcgi_\">\n"
1031 << "<input type=\"hidden\" name=\"a\" value=\"q\">\n"
1032 << "<input type=\"hidden\" name=\"site\" value=\"_cgiargsite_\"\n"
1033 << "<input type=\"hidden\" name=\"e\" value=\"_compressedoptions_\">\n"
1034 << "<input type=\"hidden\" name=\"ccp\" value=\"1\">\n"
1035 << "<center><table width=\"_pagewidth_\"><tr valign=\"top\">\n"
1036 << "<td>Select collections to search for \"" << args["q"]
1037 << "\" <i>(index=" << index << " subcollection=" << subcollection
1038 << " language=" << language << ")</i></td>\n"
1039 << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n"
1040 << "</tr></table></center>\n"
1041 << "<center><table width=\"_pagewidth_\">\n"
1042 << "<tr><td>\n";
1043
1044 recptprotolistclass::iterator rprotolist_here = protos->begin();
1045 recptprotolistclass::iterator rprotolist_end = protos->end();
1046 while (rprotolist_here != rprotolist_end) {
1047 if ((*rprotolist_here).p != NULL) {
1048
1049 text_tarray collist;
1050 (*rprotolist_here).p->get_collection_list (collist, err, logout);
1051 if (err == noError) {
1052 text_tarray::iterator collist_here = collist.begin();
1053 text_tarray::iterator collist_end = collist.end();
1054 while (collist_here != collist_end) {
1055
1056 cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
1057 // if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) {
1058 if (cinfo != NULL && (cinfo->buildDate > 0)) {
1059
1060 (*rprotolist_here).p->get_filteroptions (*collist_here, frequest, fresponse, err, logout);
1061 if (err == noError) {
1062
1063 FilterOption_tmap::const_iterator it;
1064 FilterOption_tmap::const_iterator end = fresponse.filterOptions.end();
1065 if (!index.empty()) {
1066 it = fresponse.filterOptions.find ("Index");
1067 if (it == end) {++collist_here; continue;}
1068 text_tarray::const_iterator there = (*it).second.validValues.begin();
1069 text_tarray::const_iterator tend = (*it).second.validValues.end();
1070 while (there != tend) {
1071 if (*there == index) break;
1072 ++there;
1073 }
1074 if (there == tend) {++collist_here; continue;}
1075 }
1076 if (!subcollection.empty()) {
1077 it = fresponse.filterOptions.find ("Subcollection");
1078 if (it == end) {++collist_here; continue;}
1079 text_tarray::const_iterator there = (*it).second.validValues.begin();
1080 text_tarray::const_iterator tend = (*it).second.validValues.end();
1081 while (there != tend) {
1082 if (*there == subcollection) break;
1083 ++there;
1084 }
1085 if (there == tend) {++collist_here; continue;}
1086 }
1087 if (!language.empty()) {
1088 it = fresponse.filterOptions.find ("Language");
1089 if (it == end) {++collist_here; continue;}
1090 text_tarray::const_iterator there = (*it).second.validValues.begin();
1091 text_tarray::const_iterator tend = (*it).second.validValues.end();
1092 while (there != tend) {
1093 if (*there == language) break;
1094 ++there;
1095 }
1096 if (there == tend) {++collist_here; continue;}
1097 }
1098
1099 // we've got a matching collection
1100 textout << outconvert << "<input type=\"checkbox\"";
1101
1102 text_tset::const_iterator t = collections.find (*collist_here);
1103 if (t != collections.end()) textout << outconvert << " checked";
1104
1105 text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
1106 if (collectionname.empty()) {
1107 collectionname = *collist_here;
1108 }
1109 textout << outconvert << disp
1110 << " name=\"cc\" value=\"" << *collist_here << "\">"
1111 << collectionname << "<br>\n";
1112
1113
1114 }
1115 }
1116 ++collist_here;
1117 }
1118 }
1119 }
1120 ++rprotolist_here;
1121 }
1122 textout << outconvert << disp
1123 << "</td></tr></table></center>\n"
1124 << "</form>\n"
1125 << "_query:footer_\n";
1126
1127}
1128
1129bool queryaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
1130 browsermapclass *browsers, displayclass &disp,
1131 outconvertclass &outconvert, ostream &textout,
1132 ostream &logout) {
1133
1134 if (recpt == NULL) {
1135 logout << "ERROR (queryaction::do_action): This action does not contain information\n"
1136 << " about any receptionists. The method set_receptionist was probably\n"
1137 << " not called from the module which instantiated this action.\n";
1138 return true;
1139 }
1140
1141
1142
1143 if (args["ccs"] == "1") {
1144 if (!args["cc"].empty()) {
1145 // query the selected collections
1146 text_t::const_iterator b = args["cc"].begin();
1147 text_t::const_iterator e = args["cc"].end();
1148 if (findchar (b, e, ',') != e) {
1149 if (!search_multiple_collections (args, protos, browsers, disp, outconvert,
1150 textout, logout)) return false;
1151 return true;
1152 } else {
1153 if (!search_single_collection (args, args["cc"], protos, browsers, disp,
1154 outconvert, textout, logout)) return false;
1155 return true;
1156 }
1157 }
1158 }
1159
1160 // simply query the current collection
1161 if (!search_single_collection (args, args["c"], protos, browsers, disp,
1162 outconvert, textout, logout)) return false;
1163 return true;
1164}
1165
1166bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos,
1167 browsermapclass *browsers, displayclass &disp,
1168 outconvertclass &outconvert, ostream &textout,
1169 ostream &logout) {
1170
1171 text_tarray collections;
1172
1173 text_t arg_cc = args["cc"];
1174 decode_cgi_arg (arg_cc);
1175 splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
1176
1177 if (collections.empty()) {
1178 logout << "queryaction::search_multiple_collections: No collections "
1179 << "set for doing multiple query - will search current collection\n";
1180 textout << outconvert << disp << "_query:textwarningnocollections_\n";
1181 return search_single_collection (args, args["c"], protos, browsers, disp,
1182 outconvert, textout, logout);
1183 }
1184
1185 // queryaction uses "VList" browser to display results,
1186 // a queries clasification is "Search"
1187 text_t browsertype = "VList";
1188 text_t classification = "Search";
1189
1190 QueryResult_tset results;
1191 map<text_t, colinfo_t, lttext_t> colinfomap;
1192
1193 ColInfoResponse_t *cinfo = NULL;
1194 recptproto *collectproto = NULL;
1195 comerror_t err;
1196 FilterRequest_t request;
1197 FilterResponse_t response;
1198 request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking;
1199 text_t freqmsg = "_textfreqmsg1_";
1200 int numdocs = 0;
1201 isapprox isApprox = Exact;
1202
1203 // what to do about segmentation for multiple colls??
1204 bool segment = false;
1205 text_t formattedstring = "";
1206 get_formatted_query_string(formattedstring, segment, args, disp, logout);
1207
1208 if (formattedstring.empty()) {
1209 // dont bother doing a query if no query string
1210 define_history_macros (disp, args, protos, logout);
1211 textout << outconvert << disp << "_query:header_\n"
1212 << "_query:content_";
1213 textout << outconvert << disp << "_query:footer_";
1214
1215 return true;
1216 }
1217 bool syntax_error = false;
1218
1219 set_queryfilter_options (request, formattedstring, args);
1220
1221 // need to retrieve maxdocs matches for each collection
1222 // (will eventually want to tidy this up, do so caching etc.)
1223 OptionValue_t option;
1224 option.name = "StartResults";
1225 option.value = "1";
1226 request.filterOptions.push_back (option);
1227
1228 option.name = "EndResults";
1229 option.value = args["m"];
1230 request.filterOptions.push_back (option);
1231
1232 text_tarray::iterator col_here = collections.begin();
1233 text_tarray::iterator col_end = collections.end();
1234
1235 map<text_t, int, lttext_t> termfreqs;
1236
1237 // just check the main col for formatting info - use individual format statements, or the main one?
1238
1239 browserclass *bptr = browsers->getbrowser (browsertype);
1240
1241 text_t main_col = args["c"];
1242 cinfo = recpt->get_collectinfo_ptr (collectproto, main_col, logout);
1243 if (cinfo == NULL) {
1244 logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL for '"<<main_col<<"'\n";
1245 return false;
1246 }
1247
1248 bool use_main_col_format = false;
1249 if (cinfo->ccsOptions & CCSUniformSearchResultsFormatting) {
1250 use_main_col_format = true;
1251 }
1252
1253 request.fields.erase (request.fields.begin(), request.fields.end());
1254 request.getParents = false;
1255 bptr->load_metadata_defaults (request.fields);
1256
1257 text_t formatstring;
1258 format_t *formatlistptr = new format_t();
1259 if (use_main_col_format) {
1260 // just get one format for main coll and use it for each subcol
1261 if (!get_formatstring (classification, browsertype,
1262 cinfo->format, formatstring)) {
1263 formatstring = bptr->get_default_formatstring();
1264 }
1265
1266 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1267 }
1268
1269 while (col_here != col_end) {
1270
1271 collectproto = protos->getrecptproto (*col_here, logout);
1272 if (collectproto == NULL) {
1273 logout << outconvert << "queryaction::search_multiple_collections: " << *col_here
1274 << " collection has a NULL collectproto, ignoring\n";
1275 ++col_here;
1276 continue;
1277 }
1278 cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
1279 if (cinfo == NULL) {
1280 logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL\n";
1281 ++col_here;
1282 continue;
1283 }
1284
1285 if (!use_main_col_format) {
1286 request.fields.erase (request.fields.begin(), request.fields.end());
1287 request.getParents = false;
1288 bptr->load_metadata_defaults (request.fields);
1289
1290 //browserclass *bptr = browsers->getbrowser (browsertype);
1291
1292 // get the formatstring if there is one
1293 if (!get_formatstring (classification, browsertype,
1294 cinfo->format, formatstring)) {
1295 formatstring = bptr->get_default_formatstring();
1296 }
1297
1298 formatlistptr = new format_t();
1299 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1300 }
1301
1302 colinfo_t thiscolinfo;
1303 thiscolinfo.formatlistptr = formatlistptr;
1304 thiscolinfo.browserptr = bptr;
1305 colinfomap[*col_here] = thiscolinfo;
1306
1307 // do the query
1308 collectproto->filter (*col_here, request, response, err, logout);
1309 if (err != noError && err != syntaxError) {
1310 outconvertclass text_t2ascii;
1311 logout << text_t2ascii
1312 << "queryaction::search_multiple_collections: call to QueryFilter failed "
1313 << "for " << *col_here << " collection (" << get_comerror_string (err) << ")\n";
1314 return false;
1315 }
1316
1317 if (err == syntaxError) {
1318 syntax_error = true;
1319 freqmsg = "_textinvalidquery_";
1320 // assume the syntax will be invalid for all colls
1321 break;
1322 }
1323 if (response.error_message == "TOO_MANY_CLAUSES") {
1324 freqmsg = "_textlucenetoomanyclauses_";
1325 break;
1326 }
1327 if (isApprox == Exact)
1328 isApprox = response.isApprox;
1329 else if (isApprox == MoreThan)
1330 if (response.isApprox == Approximate)
1331 isApprox = response.isApprox;
1332
1333 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
1334 TermInfo_tarray::const_iterator end_term = response.termInfo.end();
1335 while (this_term != end_term) {
1336 termfreqs[(*this_term).term] += (*this_term).freq;
1337 if ((col_here+1) == col_end) {
1338 freqmsg += (*this_term).term + ": " + termfreqs[(*this_term).term];
1339 if ((this_term+1) != end_term) freqmsg += ", ";
1340 }
1341 ++this_term;
1342 }
1343
1344 if (response.numDocs > 0) {
1345 numdocs += response.numDocs;
1346
1347 QueryResult_t thisresult;
1348 thisresult.collection = *col_here;
1349 ResultDocInfo_tarray::iterator doc_here = response.docInfo.begin();
1350 ResultDocInfo_tarray::iterator doc_end = response.docInfo.end();
1351 while (doc_here != doc_end) {
1352 thisresult.doc = *doc_here;
1353 results.insert (thisresult);
1354 ++doc_here;
1355 }
1356 }
1357 ++col_here;
1358 } // for each coll
1359
1360 text_t numdocs_t = numdocs;
1361 args["nmd"] = numdocs_t;
1362
1363 disp.setmacro ("freqmsg", "query", freqmsg);
1364
1365 define_query_macros( args, disp, numdocs, isApprox);
1366 // save the query if appropriate
1367 save_search_history(args, numdocs, isApprox);
1368 define_history_macros (disp, args, protos, logout);
1369
1370 textout << outconvert << disp << "_query:header_\n"
1371 << "_query:content_";
1372
1373 if (!syntax_error) {
1374
1375 // now go through each result and output it
1376 QueryResult_tset::iterator res_here = results.begin();
1377 QueryResult_tset::iterator res_end = results.end();
1378 text_tset metadata; // empty !!
1379 bool getParents = false; // don't care !!
1380 bool use_table;
1381 ResultDocInfo_t thisdoc;
1382 format_t *formatlistptr = NULL;
1383 browserclass *browserptr = NULL;
1384
1385 int count = 1;
1386 int firstdoc = args.getintarg("r");
1387 int hitsperpage = args.getintarg("o");
1388 int thislast = firstdoc + (hitsperpage - 1);
1389
1390 // output results
1391 while (res_here != res_end) {
1392 if (count < firstdoc) {++count; ++res_here; continue;}
1393 if (count > thislast) break;
1394
1395 formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
1396 browserptr = colinfomap[(*res_here).collection].browserptr;
1397 thisdoc = (*res_here).doc;
1398 use_table = is_table_content (formatlistptr);
1399
1400 collectproto = protos->getrecptproto ((*res_here).collection, logout);
1401 if (collectproto == NULL) {
1402 logout << outconvert << "queryaction::search_multiple_collections: " << (*res_here).collection
1403 << " collection has a NULL collectproto, ignoring results\n";
1404 ++res_here;
1405 continue;
1406 }
1407
1408 browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0,
1409 formatlistptr, use_table, metadata, getParents,
1410 collectproto, disp, outconvert, textout, logout);
1411 // textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
1412 ++res_here;
1413 ++count;
1414 }
1415 }
1416 textout << outconvert << disp << "_query:footer_";
1417
1418 // clean up the format_t pointers
1419 map<text_t, colinfo_t, lttext_t>::iterator here = colinfomap.begin();
1420 map<text_t, colinfo_t, lttext_t>::iterator end = colinfomap.end();
1421 while (here != end) {
1422 delete ((*here).second.formatlistptr);
1423 ++here;
1424 }
1425 return true;
1426}
1427
1428bool queryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
1429 recptprotolistclass *protos, browsermapclass *browsers,
1430 displayclass &disp, outconvertclass &outconvert,
1431 ostream &textout, ostream &logout) {
1432
1433 recptproto *collectproto = protos->getrecptproto (collection, logout);
1434 if (collectproto == NULL) {
1435 logout << outconvert << "queryaction::search_single_collection: " << collection
1436 << " collection has a NULL collectproto\n";
1437
1438 // Display the "this collection is not installed on this system" page
1439 disp.setmacro("cvariable", displayclass::defaultpackage, collection);
1440 disp.setmacro("content", "query", "<p>_textbadcollection_<p>");
1441
1442 textout << outconvert << disp << "_query:header_\n"
1443 << "_query:content_\n" << "_query:footer_\n";
1444 return true;
1445 }
1446
1447 // queryaction uses "VList" browser to display results,
1448 // a queries clasification is "Search"
1449 text_t browsertype = "VList";
1450 text_t classification = "Search";
1451
1452 comerror_t err;
1453 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
1454
1455 if (cinfo == NULL) {
1456 logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
1457 return false;
1458 }
1459
1460 bool segment = cinfo->isSegmented;
1461 browserclass *bptr = browsers->getbrowser (browsertype);
1462
1463 // get the formatstring if there is one
1464 text_t formatstring;
1465 if (!get_formatstring (classification, browsertype,
1466 cinfo->format, formatstring)) {
1467 formatstring = bptr->get_default_formatstring();
1468 }
1469 FilterRequest_t request;
1470 FilterResponse_t response;
1471
1472 text_t hits_per_page_old = args["o"];
1473 text_t start_results_from_old = args["r"];
1474
1475 // if the "ifl" argument is set to 1, we only want to get one document
1476 // this may be the first search result (from "I feel lucky") or maybe a
1477 // specified search result (from next/prev search result link)
1478 if (args["ifl"] == "1") {
1479 args["r"] = args["ifln"]; // the document number we want
1480 args["o"] = "1";
1481 }
1482
1483 bptr->set_filter_options (request, args);
1484 bptr->load_metadata_defaults (request.fields);
1485
1486 format_t *formatlistptr = new format_t();
1487 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1488
1489 // do the query
1490 request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
1491 text_t formattedstring = "";
1492 get_formatted_query_string(formattedstring, segment, args, disp, logout);
1493
1494
1495 if (!formattedstring.empty()) { // do the query
1496 // note! formattedstring is in unicode! mg and mgpp must convert!
1497 set_queryfilter_options (request, formattedstring, args);
1498
1499 collectproto->filter (collection, request, response, err, logout);
1500
1501 if (err != noError) {
1502 outconvertclass text_t2ascii;
1503 logout << text_t2ascii
1504 << "queryaction::search_single_collections: call to QueryFilter failed "
1505 << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
1506
1507 }
1508
1509 // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
1510 if (err == noError && !args["ifl"].empty()) {
1511 //Restore the "r" and "o" arg
1512 args["r"] = start_results_from_old;
1513 args["o"] = hits_per_page_old;
1514
1515 //Find whether DocumentSearchResultLinks is enabled
1516 bool show_links = false;
1517 text_tmap::const_iterator format_here = cinfo->format.begin();
1518 text_tmap::const_iterator format_end = cinfo->format.end();
1519
1520 while (format_here != format_end) {
1521 if (((*format_here).first == "DocumentSearchResultLinks") &&
1522 ((*format_here).second == "true")){
1523 show_links = true;
1524 break;
1525 }
1526 ++format_here;
1527 }
1528
1529 if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1)) {
1530
1531 // The first search result is the one we want
1532 if (response.docInfo.begin() != response.docInfo.end()) {
1533
1534 ResultDocInfo_tarray::iterator section = response.docInfo.begin();
1535
1536 // We still need to set "srn" and "srp" values (next and prev search result numbers) if we are showing them
1537 int srn = 0;
1538 int srp = 0;
1539 if (show_links) {
1540 int ifln = args["ifln"].getint();
1541 srn = ifln + 1;
1542 if (srn > response.numDocs) {
1543 srn = 0;
1544 }
1545 srp = ifln - 1;
1546 if (srp < 0) {
1547 srp = 0;
1548 }
1549 }
1550
1551 textout << outconvert << disp
1552 << "Location: _gwcgi_?e=_compressedoptions_&a=d&c="
1553 << collection << "&cl=search&d=" << (*section).OID
1554 << "&srn=" << srn << "&srp=" << srp << "\n\n";
1555 textout << flush;
1556
1557 return true;
1558 }
1559 }
1560
1561 // There weren't enough (or any) matching documents
1562 // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
1563 // done the right thing (because ifl was set), so we need to make sure the output is html
1564 textout << "Content-type: text/html\n\n";
1565
1566 }
1567
1568 if (err != noError) {
1569 disp.setmacro("resultline", "query", "_textnodocs_");
1570 if (err == syntaxError) {
1571 disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
1572 } else {
1573 disp.setmacro ("freqmsg", "query", "");
1574 }
1575 } else {
1576
1577 define_query_macros (args, disp, response.numDocs, response.isApprox);
1578 define_single_query_macros(args, disp, response);
1579 // save the query if appropriate
1580 save_search_history(args, response.numDocs, response.isApprox);
1581 }
1582
1583 // If Lucene threw a TooManyClauses exception, tell the user about it
1584 if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
1585 disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
1586 }
1587 }
1588
1589 //Restore the "r" and "o" arg in case they have been changed and we still get here
1590 args["r"] = start_results_from_old;
1591 args["o"] = hits_per_page_old;
1592
1593 define_history_macros (disp, args, protos, logout);
1594
1595 textout << outconvert << disp << "_query:header_\n"
1596 << "_query:content_";
1597
1598 if (err == noError) {
1599 // output the results
1600 text_t numdocs_t = response.numDocs;
1601 args["nmd"] = numdocs_t;
1602 bool use_table = is_table_content (formatlistptr);
1603 bptr->output_section_group (response, args, collection, 0, formatlistptr,
1604 use_table, request.fields, request.getParents,
1605 collectproto, disp, outconvert, textout, logout);
1606 }
1607
1608 textout << outconvert << disp << "_query:footer_";
1609
1610 delete (formatlistptr);
1611
1612 return true;
1613}
1614
1615// does the formatting of the query string - either uses q for a text search
1616// or the form values for an form search
1617// also adds dates if appropriate in text search
1618void queryaction::get_formatted_query_string (text_t &formattedstring,
1619 bool segment,
1620 cgiargsclass &args,
1621 displayclass &disp,
1622 ostream &logout) {
1623 if (args["qt"]=="0" && args["qto"] != "2") { // normal text search
1624 formattedstring = args["q"];
1625 // remove & | ! for simple search,do segmentation if necessary
1626 format_querystring (formattedstring, args.getintarg("b"), segment);
1627 if (args["ct"]!=0) { // mgpp and lucene - need to add in tag info if appropriate
1628 format_field_info(formattedstring, args["fqf"], args.getintarg("ct"),
1629 args.getintarg("t"), args.getintarg("b"));
1630 }
1631
1632 add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
1633 args.getintarg("dsbc"), args.getintarg("debc"),
1634 args.getintarg("ct"));
1635 args["q"] = formattedstring;
1636
1637 }
1638 else if (args["qt"]=="1" || args["qto"]=="2"){ // form search
1639
1640 if (args["b"]=="1" && args["fqa"]=="1") { // explicit query
1641 formattedstring = args["q"];
1642 }
1643 else { // form search
1644 if (args["b"]=="0") { // regular form
1645 parse_reg_query_form(formattedstring, args, segment);
1646 }
1647 else { // advanced form
1648 parse_adv_query_form(formattedstring, args, segment);
1649 }
1650 args["q"] = formattedstring;
1651
1652 // reset the cgiargfqv macro - need to escape any quotes in it
1653 disp.setmacro("cgiargfqv", "query", escape_quotes(args["fqv"]));
1654
1655 // also reset the _cgiargq_ macro as it has changed now
1656 disp.setmacro("cgiargq", displayclass::defaultpackage, html_safe(args["q"]));
1657
1658 // reset the compressed options to include the q arg
1659 text_t compressedoptions = recpt->get_compressed_arg(args, logout);
1660 if (!compressedoptions.empty()) {
1661 disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
1662 // need a decoded version of compressedoptions for use within forms
1663 // as browsers encode values from forms before sending to server
1664 // (e.g. %25 becomes %2525)
1665 decode_cgi_arg (compressedoptions);
1666 if (args["w"] == "utf-8") { // if the encoding was utf-8, then compressed options was utf-8, and we need unicode.
1667 // if encoding wasn't utf-8, then compressed opotions may be screwed up, but seems to work for 8 bit encodings?
1668 compressedoptions = to_uni(compressedoptions);
1669 }
1670
1671 disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
1672 }
1673 } // form search
1674 } // args["qt"]=1
1675 else {
1676 logout << "ERROR (query_action::get_formatted_query_string): querytype not defined\n";
1677 }
1678}
1679
1680
1681// define_query_macros sets the macros that couldn't be set until the
1682// query had been done. Those macros are
1683// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
1684// _thisfirst_, and _thislast_ and _quotedquery_
1685// this has been simplified so it can be used with both search_single_coll
1686// and search_multiple_coll
1687void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
1688 int numdocs, isapprox isApprox) {
1689
1690 // set up _resultline_ macro
1691 text_t resline;
1692 int maxdocs = args.getintarg("m");
1693 if (num_phrases > 0) isApprox = Exact;
1694 if (maxdocs == -1) maxdocs = numdocs;
1695 else if (numdocs > maxdocs) {
1696 numdocs = maxdocs;
1697 isApprox = MoreThan;
1698 }
1699
1700 if (isApprox == Approximate) resline = "_textapprox_";
1701 else if (isApprox == MoreThan) resline = "_textmorethan_";
1702
1703 if (numdocs == 0) resline = "_textnodocs_";
1704 else if (numdocs == 1) resline += "_text1doc_";
1705 else resline += text_t(numdocs) + " _textlotsdocs_";
1706
1707 disp.setmacro("resultline", "query", resline);
1708
1709 int firstdoc = args.getintarg("r");
1710 int hitsperpage = args.getintarg("o");
1711 if (hitsperpage == -1) hitsperpage = numdocs;
1712
1713 // set up _thisfirst_ and _thislast_ macros
1714 disp.setmacro ("thisfirst", "query", firstdoc);
1715 int thislast = firstdoc + (hitsperpage - 1);
1716 if (thislast > numdocs) thislast = numdocs;
1717 disp.setmacro ("thislast", "query", thislast);
1718
1719 // set up _prevfirst_ and _prevlast_ macros
1720 if (firstdoc > 1) {
1721 disp.setmacro ("prevlast", "query", firstdoc - 1);
1722 int prevfirst = firstdoc - hitsperpage;
1723 if (prevfirst < 1) prevfirst = 1;
1724 disp.setmacro ("prevfirst", "query", prevfirst);
1725 }
1726
1727 // set up _nextfirst_ and _nextlast_ macros
1728 if (thislast < numdocs) {
1729 disp.setmacro ("nextfirst", "query", thislast + 1);
1730 int nextlast = thislast + hitsperpage;
1731 if (nextlast > numdocs) nextlast = numdocs;
1732 disp.setmacro ("nextlast", "query", nextlast);
1733 }
1734
1735 // do quoted query here cos we may have added quotes during query pre-processing
1736 if (args["ct"]==0) { // mg queries only, not mgpp
1737 // get the quoted bits of the query string and set _quotedquery_
1738 text_tarray phrases;
1739 get_phrases (args["q"], phrases);
1740 num_phrases = phrases.size();
1741 text_tarray::const_iterator phere = phrases.begin();
1742 text_tarray::const_iterator pend = phrases.end();
1743 bool first = true;
1744 text_t quotedquery;
1745 while (phere != pend) {
1746 if (!first)
1747 if ((phere +1) == pend) quotedquery += " and ";
1748 else quotedquery += ", ";
1749
1750 quotedquery += "\"" + *phere + "\"";
1751 first = false;
1752 ++phere;
1753 }
1754 if (args.getintarg("s") && !quotedquery.empty()) quotedquery += "_textstemon_";
1755 disp.setmacro ("quotedquery", "query", quotedquery);
1756 }
1757
1758}
1759
1760// define_single_query_macros sets the extra macros for search_single_coll
1761// that couldn't be set until the query had been done. Those macros are
1762// _freqmsg_ and _stopwordsmsg_
1763void queryaction::define_single_query_macros (cgiargsclass &args,
1764 displayclass &disp,
1765 const FilterResponse_t &response) {
1766 // set up _freqmsg_ and _stopwordsmsg_ macros
1767
1768 text_t freqmsg = "";
1769 freqmsg = "_textfreqmsg1_";
1770 TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
1771 TermInfo_tarray::const_iterator end_term = response.termInfo.end();
1772 while (this_term != end_term) {
1773 freqmsg += (*this_term).term + ": " + (*this_term).freq;
1774 if ((this_term + 1) != end_term)
1775 freqmsg += ", ";
1776 ++this_term;
1777 }
1778 disp.setmacro ("freqmsg", "query", freqmsg);
1779
1780 text_tset::const_iterator this_stopword = response.stopwords.begin();
1781 text_tset::const_iterator end_stopword = response.stopwords.end();
1782 if (this_stopword != end_stopword) {
1783 text_t stopwordsmsg = "_textstopwordsmsg_ ";
1784 while (this_stopword != end_stopword) {
1785 if (stopwordsmsg != "_textstopwordsmsg_ ") {
1786 stopwordsmsg += ", ";
1787 }
1788 stopwordsmsg += (*this_stopword);
1789 ++this_stopword;
1790 }
1791 disp.setmacro("stopwordsmsg", "query", stopwordsmsg);
1792 }
1793}
1794
1795// should this change for cross coll search??
1796bool queryaction::save_search_history (cgiargsclass &args, int numdocs,
1797 isapprox isApprox) {
1798 if (args["q"]=="") return true; // null query, dont save
1799 if (args["hs"]=="0") return true; // only save when submit query pressed
1800
1801 // get userid
1802 text_t userid = args["z"];
1803
1804 // the number of docs goes on the front of the query string
1805 text_t query = text_t(numdocs);
1806 if (isApprox==MoreThan) { // there were more docs found
1807 query.push_back('+');
1808 }
1809 query += "c="+args["c"];
1810 query += ";h="+args["h"];
1811 query += ";t="+args["t"];
1812 query += ";b="+args["b"];
1813 query += ";j="+args["j"];
1814 query += ";n="+args["n"];
1815 query += ";s="+args["s"];
1816 query += ";k="+args["k"];
1817 query += ";g="+args["g"];
1818
1819 text_t qstring = args["q"];
1820 //text_t formattedquery =cgi_safe(qstring);
1821 //query += "&amp;q="+formattedquery;
1822 query += ";q="+qstring;
1823 bool display=false;
1824 int hd = args.getintarg("hd");
1825 if (hd > 0) display=true;
1826 if (set_history_info(userid, query, dbhome, display)) return true;
1827 else return false;
1828
1829
1830}
1831
Note: See TracBrowser for help on using the repository browser.