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