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