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