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