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

Last change on this file since 15433 was 15433, checked in by mdewsnip, 16 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
RevLine 
[174]1/**********************************************************************
2 *
3 * queryaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
[533]6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
[174]9 *
[533]10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
[174]24 *********************************************************************/
25
26#include "queryaction.h"
[275]27#include "querytools.h"
[347]28#include "formattools.h"
[757]29#include "cgiutils.h"
[772]30#include "OIDtools.h"
[928]31#include "fileutil.h"
32#include "text_t.h"
33#include "historydb.h"
[1915]34#include "htmlutils.h" // for html_safe in do_action
35#include "gsdltools.h"
[11005]36#include "phrases.h" // for get_phrases
[3176]37#include <stdlib.h> // for strtol
[3204]38#include <assert.h>
[174]39
[757]40void colinfo_t::clear () {
41 formatlistptr = NULL;
42 browserptr = NULL;
43}
44
45void QueryResult_t::clear() {
46 doc.clear();
47 collection.clear();
48}
49
[174]50queryaction::queryaction () {
[403]51
[1270]52 recpt = NULL;
[403]53 num_phrases = 0;
54
[174]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);
[4755]64
[8029]65 // "ct" - 0 = mg, 1 = mgpp, 2=lucene
[1915]66 arg_ainfo.shortname = "ct";
67 arg_ainfo.longname = "collection type";
[12000]68 arg_ainfo.multiplechar = true; // can be empty or single char
[1915]69 arg_ainfo.defaultstatus = cgiarginfo::weak;
[11988]70 arg_ainfo.argdefault = g_EmptyText;
[1915]71 arg_ainfo.savedarginfo = cgiarginfo::must;
72 argsinfo.addarginfo (NULL, arg_ainfo);
73
[470]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
[174]83 // "h"
84 arg_ainfo.shortname = "h";
85 arg_ainfo.longname = "main index";
86 arg_ainfo.multiplechar = true;
87 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]88 arg_ainfo.argdefault = g_EmptyText;
[295]89 arg_ainfo.savedarginfo = cgiarginfo::must;
[174]90 argsinfo.addarginfo (NULL, arg_ainfo);
91
[349]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;
[7441]97 arg_ainfo.argdefault = g_EmptyText;
[349]98 arg_ainfo.savedarginfo = cgiarginfo::must;
99 argsinfo.addarginfo (NULL, arg_ainfo);
100
[174]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;
[7441]106 arg_ainfo.argdefault = g_EmptyText;
[295]107 arg_ainfo.savedarginfo = cgiarginfo::must;
[174]108 argsinfo.addarginfo (NULL, arg_ainfo);
109
[349]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;
[7441]115 arg_ainfo.argdefault = g_EmptyText;
[349]116 arg_ainfo.savedarginfo = cgiarginfo::must;
117 argsinfo.addarginfo (NULL, arg_ainfo);
118
[174]119 // "n"
120 arg_ainfo.shortname = "n";
121 arg_ainfo.longname = "language index";
122 arg_ainfo.multiplechar = true;
123 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]124 arg_ainfo.argdefault = g_EmptyText;
[295]125 arg_ainfo.savedarginfo = cgiarginfo::must;
[174]126 argsinfo.addarginfo (NULL, arg_ainfo);
127
[349]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;
[7441]133 arg_ainfo.argdefault = g_EmptyText;
[349]134 arg_ainfo.savedarginfo = cgiarginfo::must;
135 argsinfo.addarginfo (NULL, arg_ainfo);
136
[1915]137
[174]138 // "q"
139 arg_ainfo.shortname = "q";
140 arg_ainfo.longname = "query string";
141 arg_ainfo.multiplechar = true;
142 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]143 arg_ainfo.argdefault = g_EmptyText;
[174]144 arg_ainfo.savedarginfo = cgiarginfo::must;
145 argsinfo.addarginfo (NULL, arg_ainfo);
146
[349]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;
[7441]152 arg_ainfo.argdefault = g_EmptyText;
[349]153 arg_ainfo.savedarginfo = cgiarginfo::must;
154 argsinfo.addarginfo (NULL, arg_ainfo);
155
[356]156 // "cq2" ""=don't combine, "and", "or", "not"
[349]157 arg_ainfo.shortname = "cq2";
158 arg_ainfo.longname = "combine queries";
159 arg_ainfo.multiplechar = true;
160 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]161 arg_ainfo.argdefault = g_EmptyText;
[349]162 arg_ainfo.savedarginfo = cgiarginfo::must;
163 argsinfo.addarginfo (NULL, arg_ainfo);
164
[284]165 // "t" - 1 = ranked 0 = boolean
[174]166 arg_ainfo.shortname = "t";
167 arg_ainfo.longname = "search type";
168 arg_ainfo.multiplechar = false;
169 arg_ainfo.defaultstatus = cgiarginfo::weak;
[284]170 arg_ainfo.argdefault = "1";
[174]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
[12866]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
[174]192 // "s"
193 arg_ainfo.shortname = "s";
194 arg_ainfo.longname = "stemming";
195 arg_ainfo.multiplechar = false;
196 arg_ainfo.defaultstatus = cgiarginfo::weak;
[12866]197 arg_ainfo.argdefault = "0";
[174]198 arg_ainfo.savedarginfo = cgiarginfo::must;
199 argsinfo.addarginfo (NULL, arg_ainfo);
200
[12866]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
[174]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);
[757]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;
[776]277 arg_ainfo.multiplevalue = true;
[757]278 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]279 arg_ainfo.argdefault = g_EmptyText;
[757]280 arg_ainfo.savedarginfo = cgiarginfo::must;
281 argsinfo.addarginfo (NULL, arg_ainfo);
282
[928]283 // "hd" history display - search history only displayed when
[1915]284 // this var set to something other than 0
285 // this number of records is displayed
[928]286 arg_ainfo.shortname = "hd";
287 arg_ainfo.longname = "history display";
[1915]288 arg_ainfo.multiplechar = true;
[936]289 arg_ainfo.multiplevalue = false;
[928]290 arg_ainfo.defaultstatus = cgiarginfo::weak;
291 arg_ainfo.argdefault = "0";
292 arg_ainfo.savedarginfo = cgiarginfo::must;
293 argsinfo.addarginfo (NULL, arg_ainfo);
294
[1915]295 // "hs" save - set to 1 in query form, so only save when submit
[928]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
[2745]306 // "g" - new arg for granularity, for mgpp collections
[1328]307 arg_ainfo.shortname = "g";
308 arg_ainfo.longname = "granularity";
309 arg_ainfo.multiplechar = true;
310 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]311 arg_ainfo.argdefault = g_EmptyText;
[1328]312 arg_ainfo.savedarginfo = cgiarginfo::must;
313 argsinfo.addarginfo (NULL, arg_ainfo);
[928]314
[1915]315 // "ds" - start date
[1373]316 arg_ainfo.shortname = "ds";
317 arg_ainfo.longname = "start date";
318 arg_ainfo.multiplechar = true;
319 arg_ainfo.defaultstatus = cgiarginfo::weak;
[7441]320 arg_ainfo.argdefault = g_EmptyText;
[1373]321 arg_ainfo.savedarginfo = cgiarginfo::must;
322 argsinfo.addarginfo (NULL, arg_ainfo);
[1328]323
[1373]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;
[7441]329 arg_ainfo.argdefault = g_EmptyText;
[1373]330 arg_ainfo.savedarginfo = cgiarginfo::must;
331 argsinfo.addarginfo (NULL, arg_ainfo);
[1328]332
[1373]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
[1915]351 // "qt" - 0 = text, 1 = form
352 arg_ainfo.shortname = "qt";
353 arg_ainfo.longname = "query type";
[12000]354 arg_ainfo.multiplechar = true; // can be empty or single char
[1915]355 arg_ainfo.defaultstatus = cgiarginfo::weak;
[11988]356 arg_ainfo.argdefault = g_EmptyText;
[1915]357 arg_ainfo.savedarginfo = cgiarginfo::must;
358 argsinfo.addarginfo (NULL, arg_ainfo);
359
[5531]360 // "qto" - 1 = text only, 2 = form only, 3 = text and form
[4755]361 arg_ainfo.shortname = "qto";
362 arg_ainfo.longname = "query type options";
[12000]363 arg_ainfo.multiplechar = true; // can be empty or single char
[4755]364 arg_ainfo.defaultstatus = cgiarginfo::weak;
[11988]365 arg_ainfo.argdefault = g_EmptyText;
[4755]366 arg_ainfo.savedarginfo = cgiarginfo::must;
367 argsinfo.addarginfo (NULL, arg_ainfo);
[12768]368
[1915]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;
[7441]393 arg_ainfo.argdefault = g_EmptyText;
[3145]394 arg_ainfo.savedarginfo = cgiarginfo::must;
[1915]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;
[7441]403 arg_ainfo.argdefault = g_EmptyText;
[3145]404 arg_ainfo.savedarginfo = cgiarginfo::must;
[1915]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;
[7441]414 arg_ainfo.argdefault = g_EmptyText;
[3145]415 arg_ainfo.savedarginfo = cgiarginfo::must;
[1915]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;
[7441]425 arg_ainfo.argdefault = g_EmptyText;
[3145]426 arg_ainfo.savedarginfo = cgiarginfo::must;
[1915]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;
[7441]435 arg_ainfo.argdefault = g_EmptyText;
[3145]436 arg_ainfo.savedarginfo = cgiarginfo::must;
[1915]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";
[3145]445 arg_ainfo.savedarginfo = cgiarginfo::must;
[1915]446 argsinfo.addarginfo (NULL, arg_ainfo);
[7594]447
[13280]448 // "ifl" - I'm feeling lucky! (Go directly to a matching document)
[7594]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
[13280]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
[13526]466 // "srn" - the next search result
[13366]467 arg_ainfo.shortname = "srn";
[13526]468 arg_ainfo.longname = "the next search result number";
469 arg_ainfo.multiplechar = true;
[13366]470 arg_ainfo.defaultstatus = cgiarginfo::weak;
471 arg_ainfo.argdefault = "0";
472 arg_ainfo.savedarginfo = cgiarginfo::must;
473 argsinfo.addarginfo (NULL, arg_ainfo);
474
[13526]475 // "srp" - the previous search result
[13366]476 arg_ainfo.shortname = "srp";
[13526]477 arg_ainfo.longname = "the previous search result number";
[13530]478 arg_ainfo.multiplechar = true;
[13366]479 arg_ainfo.defaultstatus = cgiarginfo::weak;
480 arg_ainfo.argdefault = "0";
481 arg_ainfo.savedarginfo = cgiarginfo::must;
482 argsinfo.addarginfo (NULL, arg_ainfo);
483
[12276]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);
[12388]493
[12770]494 // "fuzziness" controls how closely the search terms must match
[12771]495 // 100 = exact match, 0 = very inexact match (only implemented for Lucene)
[12770]496 arg_ainfo.shortname = "fuzziness";
497 arg_ainfo.longname = "Lucene fuzziness value";
498 arg_ainfo.multiplechar = true;
[12388]499 arg_ainfo.defaultstatus = cgiarginfo::weak;
[12771]500 arg_ainfo.argdefault = g_EmptyText;
[12388]501 arg_ainfo.savedarginfo = cgiarginfo::must;
502 argsinfo.addarginfo (NULL, arg_ainfo);
[174]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
[275]513bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
[3546]514 recptprotolistclass * /*protos*/, ostream &logout) {
[275]515
[174]516 // check t argument
[275]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";
[284]520 cgiarginfo *tinfo = argsinfo.getarginfo ("t");
521 if (tinfo != NULL) args["t"] = tinfo->argdefault;
[275]522 }
[174]523
524 // check k argument
[275]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";
[284]528 cgiarginfo *kinfo = argsinfo.getarginfo ("k");
529 if (kinfo != NULL) args["k"] = kinfo->argdefault;
[275]530 }
[174]531
532 // check s argument
[275]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";
[284]536 cgiarginfo *sinfo = argsinfo.getarginfo ("s");
537 if (sinfo != NULL) args["s"] = sinfo->argdefault;
[275]538 }
[174]539
540 // check m argument
[275]541 int arg_m = args.getintarg("m");
[608]542 if (arg_m < -1) {
543 logout << "Warning: \"m\" argument less than -1 (" << arg_m << ")\n";
[284]544 cgiarginfo *minfo = argsinfo.getarginfo ("m");
545 if (minfo != NULL) args["m"] = minfo->argdefault;
[275]546 }
[174]547
548 // check o argument
[275]549 int arg_o = args.getintarg("o");
[622]550 if (arg_o < -1) {
551 logout << "Warning: \"o\" argument less than -1 (" << arg_o << ")\n";
[284]552 cgiarginfo *oinfo = argsinfo.getarginfo ("o");
553 if (oinfo != NULL) args["o"] = oinfo->argdefault;
[275]554 }
[174]555
556 // check r argument
[275]557 int arg_r = args.getintarg("r");
558 if (arg_r < 1) {
559 logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";
[284]560 cgiarginfo *rinfo = argsinfo.getarginfo ("r");
561 if (rinfo != NULL) args["r"] = rinfo->argdefault;
[275]562 }
[928]563 //check hd argument
[1915]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
[928]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 }
[174]578
[1915]579 // check ct argument
580 int arg_ct = args.getintarg("ct");
[10361]581 if (arg_ct < 0 || arg_ct > 2) {
[1915]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;
[928]585 }
586
[1915]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
[174]619 return true;
620}
621
[7594]622void queryaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
[757]623 response_t &response, text_t &response_data,
624 ostream &/*logout*/) {
[7594]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
[174]631 response = content;
632 response_data = "text/html";
633}
634
[757]635void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
[1915]636 recptprotolistclass * protos,
637 ostream &logout) {
[275]638
[403]639 // define_internal_macros sets the following macros:
[275]640
[397]641 // The following macros are set later (in define_query_macros) as they can't be set until
642 // the query has been done.
[7197]643 // _quotedquery_ the part of the query string that was quoted for post-processing
[275]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_
[397]654
[11988]655
[1915]656 define_form_macros(disp, args, protos, logout);
[2769]657
658 define_query_interface(disp, args, protos, logout);
659
[11988]660
[174]661}
662
[2769]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 }
[11988]685
[2769]686 text_tmap::iterator check = colinfo->format.find("QueryInterface");
687 if(check != colinfo->format.end()){
688 if((*check).second=="DateSearch"){
[5633]689 text_t current = "_datesearch_";
690 disp.setmacro("optdatesearch","query",current);
[2769]691 }
692 }
693}
694
695
[4755]696// sets the selection box macros _hselection_, _jselection_, _nselection_ _gselection_, fqfselection_
[6584]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) {
[275]703
[634]704 if (option.validValues.empty()) return;
[4755]705 if (option.validValues.size() == 1) {
706 if (display_single) {
[7433]707 disp.setmacro (macroname + "selection", displayclass::defaultpackage, "_" + option.defaultValue + "_");
[4755]708 }
709 return;
[634]710 }
[275]711 if (option.validValues.size() < 2) return;
[634]712
[4937]713 text_t macrovalue = "<select name=\"" + macroname + "\"";
714 if (add_js_update) {
715 macrovalue += " onChange=\"update"+macroname+"();\"";
716 }
717 macrovalue += ">\n";
[634]718
[275]719 if (current_value.empty()) current_value = option.defaultValue;
[634]720
[275]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";
[457]728 macrovalue += ">_" + *thisvalue + "_\n";
[9620]729 ++thisvalue;
[275]730 }
731 macrovalue += "</select>\n";
[7433]732 disp.setmacro (macroname + "selection", displayclass::defaultpackage, macrovalue);
[174]733}
734
[1915]735
[757]736void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args,
737 recptprotolistclass *protos, ostream &logout) {
[275]738
739 // define_external_macros sets the following macros:
740
741 // some or all of these may not be required to be set
[356]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
[275]746
[4755]747 // _gselection_, the selection box forlevels (mgpp)
748 // _fqfselection_, the selection box for index/fields (mgpp)
[275]749 // can't do anything if collectproto is null (i.e. no collection was specified)
[757]750 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
[275]751 if (collectproto == NULL) return;
752
[11988]753 ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(collectproto,
754 args["c"],
755 logout);
756 set_query_type_args(colinfo, args);
[12866]757 set_stem_index_args(colinfo, args);
[11988]758
[275]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) {
[356]766
[275]767 FilterOption_tmap::const_iterator it;
768 FilterOption_tmap::const_iterator end = response.filterOptions.end();
[356]769
770 // _hselection_ and _h2selection_ (Index)
[275]771 it = response.filterOptions.find ("Index");
[4937]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);
[356]774
775 // _jselection_ and _j2selection_ (Subcollection)
[275]776 it = response.filterOptions.find ("Subcollection");
[4937]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);
[356]779
780 // _nselection_ and _n2selection_ (Language)
781 it = response.filterOptions.find ("Language");
[4937]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);
[275]784
[356]785 // _cq2selection_ (CombineQuery)
786 it = response.filterOptions.find ("CombineQuery");
[4937]787 if (it != end) set_option_macro ("cq2", args["cq2"], true,false, (*it).second, disp);
[928]788
[8029]789 if ((args["ct"] == "1") || (args["ct"] == "2")) { // mgpp/lucene collections
[4780]790 // _gselection_ (Level)
791 it = response.filterOptions.find("Level");
792 if (it!=end) {
[4937]793 set_option_macro("g", args["g"], false, false, (*it).second, disp);
[4780]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");
[4937]800 if (it!=end) {
[12786]801 bool form_search = false;
802 if (args["qto"]=="2" || args["qt"]=="1") {
803 form_search = true;
[4937]804 }
[12786]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 }
[4937]810 }
[4780]811 }
812 }
813} // define external macros
[12786]814
815void queryaction::set_sfselection_macro(text_t current_value,
816 const FilterOption_t &option,
817 displayclass &disp) {
818
[13587]819 // we need at least one option here to continue
820 if (option.validValues.size() < 1) {
[12786]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
[4780]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;
[275]863 }
[4780]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();
[928]867
[4780]868 bool has_paras = false;
869 while (thisvalue != endvalue) {
[4809]870 if (*thisvalue == "Para") {
[4780]871 has_paras = true;
872 break;
873 }
[9620]874 ++thisvalue;
[4780]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;
[4809]881 if (option.validValues[0] == "Para") {
[4780]882 opt = 1;
883 }
[7433]884 disp.setmacro ("gformselection", displayclass::defaultpackage, "_"+option.validValues[opt]+"_");
[4780]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) {
[4809]896 if (*thisvalue != "Para") {
[4780]897 macrovalue += "<option value=\"" + *thisvalue + "\"";
898 if (*thisvalue == current_value)
899 macrovalue += " selected";
900 macrovalue += ">_" + *thisvalue + "_\n";
901 }
[9620]902 ++thisvalue;
[4780]903 }
904 macrovalue += "</select>\n";
[7433]905 disp.setmacro ("gformselection", displayclass::defaultpackage, macrovalue);
[4780]906}
[1915]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
[8029]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
[1915]915 return; // dont need these macros
916
917 text_t form = "";
918 int argfqn = args.getintarg("fqn");
919
[12768]920 if (args["b"] == "1") { // advanced form
[12786]921 form += "_firstadvformelement_\n";
[9620]922 for (int i=1; i<argfqn; ++i) {
[12786]923 form += "_advformelement_\n";
[1915]924 }
925 disp.setmacro("advformlist", "query", form);
926 }
927 else { // simple form
[9620]928 for (int i=0; i<argfqn; ++i) {
[12786]929 form += "_regformelement_\n";
[1915]930 }
931 disp.setmacro("regformlist", "query", form);
932 }
933
934}
935
[936]936void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args,
937 recptprotolistclass *protos, ostream &logout) {
[928]938
939 // defines the following macros
940 // _searchhistorylist_
941
942 text_t historylist;
943 int arghd = args.getintarg("hd");
[1915]944 if (arghd == 0) {
[928]945 historylist="";
946 }
947 else {
948 historylist = "<!-- Search History List -->\n";
949
950 text_t userid = args["z"];
951 text_tarray entries;
[2212]952 if (get_history_info (userid, entries, gdbmhome, logout)) {
[928]953 int count = 1;
954 text_tarray::iterator here = entries.begin();
955 text_tarray::iterator end = entries.end();
[1915]956 int numrecords=(int)entries.size();
957 if (numrecords>arghd) { // only display some of them
958 numrecords = arghd;
[928]959 }
[12720]960 historylist += "<form action=\"_gwcgi_\" name=\"HistoryForm\"><table width=\"537\">\n";
[928]961
[9620]962 for (int i=0; i<numrecords;++i) {
[928]963 text_t query;
964 text_t numdocs;
965 text_t cgiargs;
[1915]966 text_t userinfo;
967 text_t escquery;
968 split_saved_query(entries[i],numdocs,cgiargs);
[936]969 parse_saved_args(cgiargs, "q", query); // get query string out
[928]970 decode_cgi_arg(query); // un cgisafe it
[2745]971 escquery = escape_quotes(query); // escape the quotes and newlines
[1915]972 text_t histvalue = "histvalue";
973 histvalue += i;
974 disp.setmacro(histvalue, "query", escquery);
975 format_user_info(cgiargs, userinfo, args, protos, logout);
[928]976
[12488]977 historylist += "<tr><td align=\"right\">_imagehistbutton_(";
[1915]978 historylist += i;
979 historylist += ")</td>\n";
[12720]980 historylist += "<td><table border=\"1\" cellspacing=\"0\" ";
981 historylist += "cellpadding=\"0\"><tr><td width=\"365\" align=\"left\">"
[1915]982 + query
[12488]983 + "</td></tr></table></td><td width=\"110\" align=\"center\"><small>"
[1915]984 + numdocs;
985 if (numdocs == 1) historylist += " _texthresult_";
986 else historylist += " _texthresults_";
987 if (!userinfo.empty()) {
[12720]988 historylist += "<br>( "+userinfo+" )";
[1915]989 }
[12720]990 historylist += "</small></td>\n";
[928]991 }
[1915]992 historylist+="</table></form>\n\n";
[928]993
[1915]994 } // if get history info
[928]995 else {
[936]996 historylist += "_textnohistory_";
[928]997 }
[12720]998 historylist += "<! ---- end of history list ----->\n";
[928]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
[1270]1008 ColInfoResponse_t *cinfo = NULL;
[928]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"
[12488]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"
[928]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"
[12488]1036 << "<center><table width=\"_pagewidth_\">\n"
[928]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
[1270]1051 cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
[928]1052 // if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) {
[1270]1053 if (cinfo != NULL && (cinfo->buildDate > 0)) {
[928]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");
[9620]1062 if (it == end) {++collist_here; continue;}
[928]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;
[9620]1067 ++there;
[928]1068 }
[9620]1069 if (there == tend) {++collist_here; continue;}
[928]1070 }
1071 if (!subcollection.empty()) {
1072 it = fresponse.filterOptions.find ("Subcollection");
[9620]1073 if (it == end) {++collist_here; continue;}
[928]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;
[9620]1078 ++there;
[928]1079 }
[9620]1080 if (there == tend) {++collist_here; continue;}
[928]1081 }
1082 if (!language.empty()) {
1083 it = fresponse.filterOptions.find ("Language");
[9620]1084 if (it == end) {++collist_here; continue;}
[928]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;
[9620]1089 ++there;
[928]1090 }
[9620]1091 if (there == tend) {++collist_here; continue;}
[928]1092 }
1093
1094 // we've got a matching collection
[12488]1095 textout << outconvert << "<input type=\"checkbox\"";
[928]1096
1097 text_tset::const_iterator t = collections.find (*collist_here);
[3671]1098 if (t != collections.end()) textout << outconvert << " checked";
[9931]1099
1100 text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
1101 if (collectionname.empty()) {
1102 collectionname = *collist_here;
1103 }
1104 textout << outconvert << disp
[12488]1105 << " name=\"cc\" value=\"" << *collist_here << "\">"
[9931]1106 << collectionname << "<br>\n";
[928]1107
1108
1109 }
1110 }
[9620]1111 ++collist_here;
[928]1112 }
1113 }
1114 }
[9620]1115 ++rprotolist_here;
[928]1116 }
1117 textout << outconvert << disp
1118 << "</td></tr></table></center>\n"
1119 << "</form>\n"
1120 << "_query:footer_\n";
1121
[174]1122}
[275]1123
[757]1124bool queryaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
1125 browsermapclass *browsers, displayclass &disp,
[421]1126 outconvertclass &outconvert, ostream &textout,
1127 ostream &logout) {
[757]1128
[1270]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
[3152]1137
[865]1138 if (args["ccs"] == "1") {
1139 if (!args["cc"].empty()) {
[757]1140 // query the selected collections
[865]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 }
[337]1153 }
[421]1154
[800]1155 // simply query the current collection
[865]1156 if (!search_single_collection (args, args["c"], protos, browsers, disp,
1157 outconvert, textout, logout)) return false;
[757]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";
[865]1176 return search_single_collection (args, args["c"], protos, browsers, disp,
[757]1177 outconvert, textout, logout);
[447]1178 }
1179
[757]1180 // queryaction uses "VList" browser to display results,
1181 // a queries clasification is "Search"
1182 text_t browsertype = "VList";
1183 text_t classification = "Search";
[337]1184
[757]1185 QueryResult_tset results;
1186 map<text_t, colinfo_t, lttext_t> colinfomap;
[275]1187
[1270]1188 ColInfoResponse_t *cinfo = NULL;
[1695]1189 recptproto *collectproto = NULL;
[757]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;
[800]1196 isapprox isApprox = Exact;
[772]1197
[6584]1198 // what to do about segmentation for multiple colls??
1199 bool segment = false;
[4200]1200 text_t formattedstring = "";
[6584]1201 get_formatted_query_string(formattedstring, segment, args, disp, logout);
[4200]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 }
[4220]1212 bool syntax_error = false;
[4200]1213
[757]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
[865]1230 map<text_t, int, lttext_t> termfreqs;
[10789]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
[757]1264 while (col_here != col_end) {
1265
[1695]1266 collectproto = protos->getrecptproto (*col_here, logout);
[757]1267 if (collectproto == NULL) {
1268 logout << outconvert << "queryaction::search_multiple_collections: " << *col_here
1269 << " collection has a NULL collectproto, ignoring\n";
[9620]1270 ++col_here;
[757]1271 continue;
1272 }
[1270]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";
[9620]1276 ++col_here;
[1270]1277 continue;
1278 }
[757]1279
[10789]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
[757]1287 // get the formatstring if there is one
[10789]1288 if (!get_formatstring (classification, browsertype,
1289 cinfo->format, formatstring)) {
1290 formatstring = bptr->get_default_formatstring();
1291 }
[757]1292
[10789]1293 formatlistptr = new format_t();
1294 parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
1295 }
1296
[757]1297 colinfo_t thiscolinfo;
1298 thiscolinfo.formatlistptr = formatlistptr;
1299 thiscolinfo.browserptr = bptr;
1300 colinfomap[*col_here] = thiscolinfo;
1301
[275]1302 // do the query
[757]1303 collectproto->filter (*col_here, request, response, err, logout);
[4220]1304 if (err != noError && err != syntaxError) {
[757]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";
[275]1309 return false;
[757]1310 }
1311
[4220]1312 if (err == syntaxError) {
1313 syntax_error = true;
1314 freqmsg = "_textinvalidquery_";
1315 // assume the syntax will be invalid for all colls
1316 break;
1317 }
[12421]1318 if (response.error_message == "TOO_MANY_CLAUSES") {
1319 freqmsg = "_textlucenetoomanyclauses_";
1320 break;
1321 }
[800]1322 if (isApprox == Exact)
1323 isApprox = response.isApprox;
1324 else if (isApprox == MoreThan)
1325 if (response.isApprox == Approximate)
1326 isApprox = response.isApprox;
1327
[757]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) {
[865]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 }
[9620]1336 ++this_term;
[757]1337 }
[12380]1338
[757]1339 if (response.numDocs > 0) {
1340 numdocs += response.numDocs;
[13366]1341
[757]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);
[9620]1349 ++doc_here;
[447]1350 }
[347]1351 }
[9620]1352 ++col_here;
[4200]1353 } // for each coll
[13366]1354
1355 text_t numdocs_t = numdocs;
1356 args["nmd"] = numdocs_t;
[347]1357
[800]1358 disp.setmacro ("freqmsg", "query", freqmsg);
[349]1359
[4200]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);
[1690]1364
[4200]1365 textout << outconvert << disp << "_query:header_\n"
1366 << "_query:content_";
[757]1367
[4220]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) {
[9620]1387 if (count < firstdoc) {++count; ++res_here; continue;}
[4220]1388 if (count > thislast) break;
[13366]1389
[4220]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";
[9620]1399 ++res_here;
[4220]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";
[9620]1407 ++res_here;
1408 ++count;
[1695]1409 }
[757]1410 }
1411 textout << outconvert << disp << "_query:footer_";
[349]1412
[757]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);
[9620]1418 ++here;
[757]1419 }
[275]1420 return true;
1421}
[757]1422
[865]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) {
[757]1427
[865]1428 recptproto *collectproto = protos->getrecptproto (collection, logout);
[757]1429 if (collectproto == NULL) {
[865]1430 logout << outconvert << "queryaction::search_single_collection: " << collection
[757]1431 << " collection has a NULL collectproto\n";
[7067]1432
1433 // Display the "this collection is not installed on this system" page
[7433]1434 disp.setmacro("cvariable", displayclass::defaultpackage, collection);
[7067]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;
[757]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;
[1270]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 }
[757]1454
[6584]1455 bool segment = cinfo->isSegmented;
[757]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,
[4200]1461 cinfo->format, formatstring)) {
[757]1462 formatstring = bptr->get_default_formatstring();
[4200]1463 }
[757]1464 FilterRequest_t request;
1465 FilterResponse_t response;
[13366]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
[757]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;
[1915]1485 text_t formattedstring = "";
[6584]1486 get_formatted_query_string(formattedstring, segment, args, disp, logout);
[13366]1487
1488
[12421]1489 if (!formattedstring.empty()) { // do the query
[4200]1490 // note! formattedstring is in unicode! mg and mgpp must convert!
1491 set_queryfilter_options (request, formattedstring, args);
[13366]1492
[4200]1493 collectproto->filter (collection, request, response, err, logout);
[13366]1494
[9698]1495 if (err != noError) {
[4200]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";
[9698]1500
[4200]1501 }
[13280]1502
1503 // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
[9698]1504 if (err == noError && !args["ifl"].empty()) {
[13366]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
[14090]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();
[13366]1529
[14090]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 }
[13366]1546
[14090]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 }
[13366]1553
[13280]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";
[13366]1558
[7594]1559 }
1560
[9698]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 }
[12421]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 }
[4200]1580 }
1581 define_history_macros (disp, args, protos, logout);
[12421]1582
[4200]1583 textout << outconvert << disp << "_query:header_\n"
1584 << "_query:content_";
1585
[9698]1586 if (err == noError) {
1587 // output the results
[13366]1588 text_t numdocs_t = response.numDocs;
1589 args["nmd"] = numdocs_t;
[9698]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 }
[4200]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,
[6584]1607 bool segment,
[4200]1608 cgiargsclass &args,
1609 displayclass &disp,
1610 ostream &logout) {
[4755]1611 if (args["qt"]=="0" && args["qto"] != "2") { // normal text search
[1915]1612 formattedstring = args["q"];
[7197]1613 // remove & | ! for simple search,do segmentation if necessary
[6584]1614 format_querystring (formattedstring, args.getintarg("b"), segment);
[8357]1615 if (args["ct"]!=0) { // mgpp and lucene - need to add in tag info if appropriate
[12786]1616 format_field_info(formattedstring, args["fqf"], args.getintarg("ct"),
1617 args.getintarg("t"), args.getintarg("b"));
[4755]1618 }
[8029]1619
[1915]1620 add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
[8029]1621 args.getintarg("dsbc"), args.getintarg("debc"),
1622 args.getintarg("ct"));
[7199]1623 args["q"] = formattedstring;
[8357]1624
[928]1625 }
[4755]1626 else if (args["qt"]=="1" || args["qto"]=="2"){ // form search
[1347]1627
[12768]1628 if (args["b"]=="1" && args["fqa"]=="1") { // explicit query
[1915]1629 formattedstring = args["q"];
1630 }
1631 else { // form search
[12768]1632 if (args["b"]=="0") { // regular form
[12786]1633 parse_reg_query_form(formattedstring, args, segment);
[1915]1634 }
1635 else { // advanced form
[12786]1636 parse_adv_query_form(formattedstring, args, segment);
[1915]1637 }
[7199]1638 args["q"] = formattedstring;
1639
[3159]1640 // reset the cgiargfqv macro - need to escape any quotes in it
1641 disp.setmacro("cgiargfqv", "query", escape_quotes(args["fqv"]));
[7199]1642
1643 // also reset the _cgiargq_ macro as it has changed now
[7433]1644 disp.setmacro("cgiargq", displayclass::defaultpackage, html_safe(args["q"]));
[7199]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()) {
[7433]1649 disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
[7199]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)
[13463]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
[7433]1659 disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
[7199]1660 }
1661 } // form search
1662 } // args["qt"]=1
1663 else {
[4200]1664 logout << "ERROR (query_action::get_formatted_query_string): querytype not defined\n";
[757]1665 }
[4200]1666}
[928]1667
[757]1668
[298]1669// define_query_macros sets the macros that couldn't be set until the
[4200]1670// query had been done. Those macros are
[275]1671// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
[9698]1672// _thisfirst_, and _thislast_ and _quotedquery_
[4200]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
[275]1678 // set up _resultline_ macro
1679 text_t resline;
[398]1680 int maxdocs = args.getintarg("m");
[800]1681 if (num_phrases > 0) isApprox = Exact;
[1717]1682 if (maxdocs == -1) maxdocs = numdocs;
1683 else if (numdocs > maxdocs) {
1684 numdocs = maxdocs;
1685 isApprox = MoreThan;
1686 }
[403]1687
1688 if (isApprox == Approximate) resline = "_textapprox_";
1689 else if (isApprox == MoreThan) resline = "_textmorethan_";
[400]1690
[275]1691 if (numdocs == 0) resline = "_textnodocs_";
1692 else if (numdocs == 1) resline += "_text1doc_";
[400]1693 else resline += text_t(numdocs) + " _textlotsdocs_";
[398]1694
[275]1695 disp.setmacro("resultline", "query", resline);
1696
1697 int firstdoc = args.getintarg("r");
1698 int hitsperpage = args.getintarg("o");
[622]1699 if (hitsperpage == -1) hitsperpage = numdocs;
[275]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 }
[7197]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;
[9620]1740 ++phere;
[7197]1741 }
1742 if (args.getintarg("s") && !quotedquery.empty()) quotedquery += "_textstemon_";
1743 disp.setmacro ("quotedquery", "query", quotedquery);
1744 }
1745
[275]1746}
1747
[4200]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
[12380]1750// _freqmsg_ and _stopwordsmsg_
[4200]1751void queryaction::define_single_query_macros (cgiargsclass &args,
1752 displayclass &disp,
[9698]1753 const FilterResponse_t &response) {
[12380]1754 // set up _freqmsg_ and _stopwordsmsg_ macros
[4220]1755
1756 text_t freqmsg = "";
[9698]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;
[4200]1765 }
1766 disp.setmacro ("freqmsg", "query", freqmsg);
[12380]1767
[12389]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;
[12380]1778 }
[12389]1779 disp.setmacro("stopwordsmsg", "query", stopwordsmsg);
[12380]1780 }
[4200]1781}
1782
1783// should this change for cross coll search??
1784bool queryaction::save_search_history (cgiargsclass &args, int numdocs,
1785 isapprox isApprox) {
[928]1786 if (args["q"]=="") return true; // null query, dont save
[4200]1787 if (args["hs"]=="0") return true; // only save when submit query pressed
1788
[928]1789 // get userid
1790 text_t userid = args["z"];
[275]1791
[928]1792 // the number of docs goes on the front of the query string
1793 text_t query = text_t(numdocs);
[4200]1794 if (isApprox==MoreThan) { // there were more docs found
[928]1795 query.push_back('+');
1796 }
[1915]1797 query += "c="+args["c"];
[11751]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"];
[1915]1806
[928]1807 text_t qstring = args["q"];
[10262]1808 //text_t formattedquery =cgi_safe(qstring);
[10873]1809 //query += "&amp;q="+formattedquery;
[11751]1810 query += ";q="+qstring;
[1915]1811 bool display=false;
1812 int hd = args.getintarg("hd");
1813 if (hd > 0) display=true;
[2212]1814 if (set_history_info(userid, query, gdbmhome, display)) return true;
[928]1815 else return false;
1816
1817
1818}
[1373]1819
Note: See TracBrowser for help on using the repository browser.