/********************************************************************** * * ptmxqueryaction.cpp -- * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Copyright (C) 2002 The New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * *********************************************************************/ #include "ptmxqueryaction.h" #include "querytools.h" #include "formattools.h" #include "htmlutils.h" #include "gsdltools.h" #include "cgiutils.h" ptmxqueryaction::ptmxqueryaction () { cgiarginfo arg_ainfo; arg_ainfo.shortname = "c1"; arg_ainfo.longname = "classification 1"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); arg_ainfo.shortname = "c2"; arg_ainfo.longname = "classification 2"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); arg_ainfo.shortname = "c3"; arg_ainfo.longname = "classification 3"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); } ptmxqueryaction::~ptmxqueryaction () { } bool ptmxqueryaction::search_single_collection (cgiargsclass &args, const text_t &collection, recptprotolistclass *protos, browsermapclass *browsers, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { recptproto *collectproto = protos->getrecptproto (collection, logout); if (collectproto == NULL) { logout << outconvert << "queryaction::search_single_collection: " << collection << " collection has a NULL collectproto\n"; return false; } // queryaction uses "VList" browser to display results, // a queries clasification is "Search" text_t browsertype = "VList"; text_t classification = "Search"; comerror_t err; ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout); if (cinfo == NULL) { logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n"; return false; } browserclass *bptr = browsers->getbrowser (browsertype); // get the formatstring if there is one text_t formatstring; if (!get_formatstring (classification, browsertype, cinfo->format, formatstring)) formatstring = bptr->get_default_formatstring(); FilterRequest_t request; FilterResponse_t response; bptr->set_filter_options (request, args); bptr->load_metadata_defaults (request.fields); format_t *formatlistptr = new format_t(); parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents); // do the query request.filterResultOptions = FROID | FRmetadata | FRtermFreq; text_t formattedstring = ""; if (!args["c1"].empty() && args["c1"] != "Any") { formattedstring += "[" + args["c1"] + "]:CL"; } if (!args["c2"].empty() && args["c2"] != "Any") { if (!formattedstring.empty()) formattedstring += " & "; formattedstring += "[" + args["c2"] + "]:CA"; } if (!args["c3"].empty() && args["c3"] != "Any") { if (!formattedstring.empty()) formattedstring += " & "; // formattedstring += "[" + args["c3"] + "]:CS"; formattedstring += args["c3"]; } if (!args["q"].empty()) { if (!formattedstring.empty()) formattedstring += " & "; // do synonym searching stuff text_t qstring = args["q"]; int insert_equiv_terms(text_t&); // forward declaration insert_equiv_terms(qstring); formattedstring += qstring; } outconvertclass text_t2ascii; logout << text_t2ascii << "formattedstring: " << formattedstring << "\n"; if (!formattedstring.empty()) { // note! formattedstring is in unicode! mg and mgpp must convert! set_queryfilter_options (request, formattedstring, args); collectproto->filter (collection, request, response, err, logout); if (err != noError) { outconvertclass text_t2ascii; logout << text_t2ascii << "queryaction::search_single_collections: call to QueryFilter failed " << "for " << collection << " collection (" << get_comerror_string (err) << ")\n"; return false; } define_query_macros (args, disp, response); } textout << outconvert << disp << "_query:header_\n" << "_query:content_"; // output the results bool use_table = is_table_content (formatlistptr); bptr->output_section_group (response, args, collection, 0, formatlistptr, use_table, request.fields, request.getParents, collectproto, disp, outconvert, textout, logout); textout << outconvert << disp << "_query:footer_"; delete (formatlistptr); return true; }