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