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