[3162] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * ptmxqueryaction.cpp --
|
---|
| 4 | * A component of the Greenstone digital library software
|
---|
| 5 | * from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 2002 The New Zealand Digital Library Project
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | *
|
---|
| 25 | *********************************************************************/
|
---|
| 26 |
|
---|
| 27 | #include "ptmxqueryaction.h"
|
---|
| 28 | #include "querytools.h"
|
---|
| 29 | #include "formattools.h"
|
---|
| 30 | #include "htmlutils.h"
|
---|
| 31 | #include "gsdltools.h"
|
---|
| 32 | #include "cgiutils.h"
|
---|
| 33 |
|
---|
| 34 | ptmxqueryaction::ptmxqueryaction () {
|
---|
| 35 |
|
---|
| 36 | cgiarginfo arg_ainfo;
|
---|
| 37 | arg_ainfo.shortname = "c1";
|
---|
| 38 | arg_ainfo.longname = "classification 1";
|
---|
| 39 | arg_ainfo.multiplechar = true;
|
---|
| 40 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 41 | arg_ainfo.argdefault = "";
|
---|
| 42 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 43 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 44 |
|
---|
| 45 | arg_ainfo.shortname = "c2";
|
---|
| 46 | arg_ainfo.longname = "classification 2";
|
---|
| 47 | arg_ainfo.multiplechar = true;
|
---|
| 48 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 49 | arg_ainfo.argdefault = "";
|
---|
| 50 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 51 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 52 |
|
---|
| 53 | arg_ainfo.shortname = "c3";
|
---|
| 54 | arg_ainfo.longname = "classification 3";
|
---|
| 55 | arg_ainfo.multiplechar = true;
|
---|
| 56 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 57 | arg_ainfo.argdefault = "";
|
---|
| 58 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 59 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 60 |
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | ptmxqueryaction::~ptmxqueryaction () {
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | bool ptmxqueryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
|
---|
| 68 | recptprotolistclass *protos, browsermapclass *browsers,
|
---|
| 69 | displayclass &disp, outconvertclass &outconvert,
|
---|
| 70 | ostream &textout, ostream &logout) {
|
---|
| 71 |
|
---|
| 72 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
| 73 | if (collectproto == NULL) {
|
---|
| 74 | logout << outconvert << "queryaction::search_single_collection: " << collection
|
---|
| 75 | << " collection has a NULL collectproto\n";
|
---|
| 76 | return false;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | // queryaction uses "VList" browser to display results,
|
---|
| 80 | // a queries clasification is "Search"
|
---|
| 81 | text_t browsertype = "VList";
|
---|
| 82 | text_t classification = "Search";
|
---|
| 83 |
|
---|
| 84 | comerror_t err;
|
---|
| 85 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
| 86 |
|
---|
| 87 | if (cinfo == NULL) {
|
---|
| 88 | logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
|
---|
| 89 | return false;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | browserclass *bptr = browsers->getbrowser (browsertype);
|
---|
| 93 |
|
---|
| 94 | // get the formatstring if there is one
|
---|
| 95 | text_t formatstring;
|
---|
| 96 | if (!get_formatstring (classification, browsertype,
|
---|
| 97 | cinfo->format, formatstring))
|
---|
| 98 | formatstring = bptr->get_default_formatstring();
|
---|
| 99 |
|
---|
| 100 | FilterRequest_t request;
|
---|
| 101 | FilterResponse_t response;
|
---|
| 102 | bptr->set_filter_options (request, args);
|
---|
| 103 | bptr->load_metadata_defaults (request.fields);
|
---|
| 104 |
|
---|
| 105 | format_t *formatlistptr = new format_t();
|
---|
| 106 | parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
|
---|
| 107 |
|
---|
| 108 | // do the query
|
---|
| 109 | request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
|
---|
| 110 | text_t formattedstring = "";
|
---|
| 111 |
|
---|
| 112 | logout << "here we go...\n";
|
---|
| 113 |
|
---|
| 114 | if (args["qt"]=="0") { // normal text search
|
---|
| 115 | logout << "normal text search ...\n";
|
---|
| 116 | formattedstring = args["q"];
|
---|
| 117 | format_querystring (formattedstring, args.getintarg("b"));
|
---|
| 118 | add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
|
---|
| 119 | args.getintarg("dsbc"), args.getintarg("debc"));
|
---|
| 120 | }
|
---|
| 121 | else if (args["qt"]=="1" ){ // form search
|
---|
| 122 |
|
---|
| 123 | logout << "form search ...\n";
|
---|
| 124 |
|
---|
| 125 | if (args["b"]=="1" && args["fqa"]=="1") { // explicit query
|
---|
| 126 | formattedstring = args["q"];
|
---|
| 127 | }
|
---|
| 128 | else { // form search
|
---|
| 129 | if (args["b"]=="0") { // regular form
|
---|
| 130 | parse_reg_query_form(formattedstring, args);
|
---|
| 131 | }
|
---|
| 132 | else { // advanced form
|
---|
| 133 | parse_adv_query_form(formattedstring, args);
|
---|
| 134 | }
|
---|
| 135 | args["q"] = formattedstring;
|
---|
| 136 |
|
---|
| 137 | // reset the cgiargfqv macro - need to escape any quotes in it
|
---|
| 138 | disp.setmacro("cgiargfqv", "query", escape_quotes(args["fqv"]));
|
---|
| 139 |
|
---|
| 140 | // also reset the _cgiargq_ macro as it has changed now
|
---|
| 141 | disp.setmacro("cgiargq", "Global", html_safe(args["q"]));
|
---|
| 142 |
|
---|
| 143 | // reset the compressed options to include the q arg
|
---|
| 144 | text_t compressedoptions = recpt->get_compressed_arg(args, logout);
|
---|
| 145 | if (!compressedoptions.empty()) {
|
---|
| 146 | disp.setmacro ("compressedoptions", "Global", dm_safe(compressedoptions));
|
---|
| 147 | // need a decoded version of compressedoptions for use within forms
|
---|
| 148 | // as browsers encode values from forms before sending to server
|
---|
| 149 | // (e.g. %25 becomes %2525)
|
---|
| 150 | decode_cgi_arg (compressedoptions);
|
---|
| 151 | disp.setmacro ("decodedcompressedoptions", "Global", dm_safe(compressedoptions));
|
---|
| 152 | }
|
---|
| 153 | } // form search
|
---|
| 154 | } // args["qt"]=1
|
---|
| 155 | else {
|
---|
| 156 | logout << "ERROR (query_action::search_single_collection): querytype not defined\n";
|
---|
| 157 | return false;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | if (!formattedstring.empty()) { // do the query
|
---|
| 161 | // note! formattedstring is in unicode! mg and mgpp must convert!
|
---|
| 162 | set_queryfilter_options (request, formattedstring, args);
|
---|
| 163 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 164 | if (err != noError) {
|
---|
| 165 | outconvertclass text_t2ascii;
|
---|
| 166 | logout << text_t2ascii
|
---|
| 167 | << "queryaction::search_single_collections: call to QueryFilter failed "
|
---|
| 168 | << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
|
---|
| 169 | return false;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | define_query_macros (args, disp, response);
|
---|
| 173 |
|
---|
| 174 | // save the query if appropriate
|
---|
| 175 | if (!save_search_history(args, response))
|
---|
| 176 | logout << "save failed";
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | define_history_macros (disp, args, protos, logout);
|
---|
| 180 |
|
---|
| 181 | textout << outconvert << disp << "_query:header_\n"
|
---|
| 182 | << "_query:content_";
|
---|
| 183 |
|
---|
| 184 | // output the results
|
---|
| 185 | bool use_table = is_table_content (formatlistptr);
|
---|
| 186 | bptr->output_section_group (response, args, collection, 0, formatlistptr,
|
---|
| 187 | use_table, request.fields, request.getParents,
|
---|
| 188 | collectproto, disp, outconvert, textout, logout);
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | textout << outconvert << disp << "_query:footer_";
|
---|
| 192 |
|
---|
| 193 | delete (formatlistptr);
|
---|
| 194 |
|
---|
| 195 | return true;
|
---|
| 196 | }
|
---|