[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 | bool ptmxqueryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
|
---|
| 67 | recptprotolistclass *protos, browsermapclass *browsers,
|
---|
| 68 | displayclass &disp, outconvertclass &outconvert,
|
---|
| 69 | ostream &textout, ostream &logout) {
|
---|
| 70 |
|
---|
| 71 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
| 72 | if (collectproto == NULL) {
|
---|
| 73 | logout << outconvert << "queryaction::search_single_collection: " << collection
|
---|
| 74 | << " collection has a NULL collectproto\n";
|
---|
| 75 | return false;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | // queryaction uses "VList" browser to display results,
|
---|
| 79 | // a queries clasification is "Search"
|
---|
| 80 | text_t browsertype = "VList";
|
---|
| 81 | text_t classification = "Search";
|
---|
| 82 |
|
---|
| 83 | comerror_t err;
|
---|
| 84 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
|
---|
| 85 |
|
---|
| 86 | if (cinfo == NULL) {
|
---|
| 87 | logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
|
---|
| 88 | return false;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | browserclass *bptr = browsers->getbrowser (browsertype);
|
---|
| 92 |
|
---|
| 93 | // get the formatstring if there is one
|
---|
| 94 | text_t formatstring;
|
---|
| 95 | if (!get_formatstring (classification, browsertype,
|
---|
| 96 | cinfo->format, formatstring))
|
---|
| 97 | formatstring = bptr->get_default_formatstring();
|
---|
| 98 |
|
---|
| 99 | FilterRequest_t request;
|
---|
| 100 | FilterResponse_t response;
|
---|
| 101 | bptr->set_filter_options (request, args);
|
---|
| 102 | bptr->load_metadata_defaults (request.fields);
|
---|
| 103 |
|
---|
| 104 | format_t *formatlistptr = new format_t();
|
---|
| 105 | parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
|
---|
| 106 |
|
---|
| 107 | // do the query
|
---|
| 108 | request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
|
---|
| 109 | text_t formattedstring = "";
|
---|
| 110 |
|
---|
[3167] | 111 | if (!args["c1"].empty() && args["c1"] != "Any") {
|
---|
| 112 | formattedstring = "[" + args["c1"] + "]:CL";
|
---|
[3162] | 113 | }
|
---|
[3167] | 114 | if (!args["c2"].empty() && args["c2"] != "Any") {
|
---|
| 115 | if (!formattedstring.empty()) formattedstring += " & ";
|
---|
| 116 | formattedstring += "[" + args["c2"] + "]:CA";
|
---|
| 117 | }
|
---|
| 118 | if (!args["c3"].empty() && args["c3"] != "Any") {
|
---|
| 119 | if (!formattedstring.empty()) formattedstring += " & ";
|
---|
| 120 | formattedstring += "[" + args["c3"] + "]:CS";
|
---|
| 121 | }
|
---|
| 122 | if (!args["q"].empty()) {
|
---|
| 123 | if (!formattedstring.empty()) formattedstring += " & ";
|
---|
| 124 | formattedstring += args["q"];
|
---|
| 125 | }
|
---|
[3162] | 126 |
|
---|
[3167] | 127 | logout << outconvert << "formattedstring: " << formattedstring << "\n";
|
---|
[3162] | 128 |
|
---|
[3167] | 129 | if (!formattedstring.empty()) {
|
---|
[3162] | 130 | // note! formattedstring is in unicode! mg and mgpp must convert!
|
---|
| 131 | set_queryfilter_options (request, formattedstring, args);
|
---|
| 132 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 133 | if (err != noError) {
|
---|
| 134 | outconvertclass text_t2ascii;
|
---|
| 135 | logout << text_t2ascii
|
---|
| 136 | << "queryaction::search_single_collections: call to QueryFilter failed "
|
---|
| 137 | << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
|
---|
| 138 | return false;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | define_query_macros (args, disp, response);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | textout << outconvert << disp << "_query:header_\n"
|
---|
| 145 | << "_query:content_";
|
---|
| 146 |
|
---|
| 147 | // output the results
|
---|
| 148 | bool use_table = is_table_content (formatlistptr);
|
---|
| 149 | bptr->output_section_group (response, args, collection, 0, formatlistptr,
|
---|
| 150 | use_table, request.fields, request.getParents,
|
---|
| 151 | collectproto, disp, outconvert, textout, logout);
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | textout << outconvert << disp << "_query:footer_";
|
---|
| 155 |
|
---|
| 156 | delete (formatlistptr);
|
---|
| 157 |
|
---|
| 158 | return true;
|
---|
| 159 | }
|
---|