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