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