/********************************************************************** * * cstrqueryaction.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * 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. * * $Id: cstrqueryaction.cpp 891 2000-02-01 22:32:36Z sjboddie $ * *********************************************************************/ /* $Log$ Revision 1.1 2000/02/01 22:32:37 sjboddie Initial revision Revision 1.1 1999/09/07 21:49:43 sjboddie new cstr receptionist */ #include "cstrqueryaction.h" #include "cstrquerytools.h" #include "formattools.h" #include "OIDtools.h" #include "text_t.h" struct ltint { bool operator()(const int &t1, const int &t2) const { return t1 < t2; } }; bool cstrqueryaction::do_action (cgiargsclass &args, const ColInfoResponse_t &collectinfo, recptproto *collectproto, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { if (formatstring.empty()) { text_tmap::const_iterator result = collectinfo.format.find("result"); if (result != collectinfo.format.end()) formatstring = (*result).second; } // if we still don't have a format string use the default if (formatstring.empty()) formatstring = "[link]_icontext_[/link][Title]"; if (collectproto == NULL) { logout << "cstrqueryaction::do_action called with NULL collectproto\n"; textout << outconvert << disp << "_query:header_\n" << "Error: Attempt to do query without setting collection\n" << "_query:footer_\n"; } else { FilterRequest_t request; FilterResponse_t response; format_t *formatlistptr = new format_t(); parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents); request.fields.push_back ("Title"); int metasize = request.fields.size(); // do the query request.filterResultOptions = FROID | FRmetadata | FRtermFreq; if (!do_query (request, args, collectproto, response, logout)) return false; // set macros define_query_macros (args, disp, response); // output the header textout << outconvert << disp << "_query:header_\n" << "_query:content_"; // output the results textout << "\n"; ResultDocInfo_tarray::const_iterator this_doc = response.docInfo.begin(); ResultDocInfo_tarray::const_iterator end_doc = response.docInfo.end(); text_t top; map topOIDs; map OIDs; int count = 0; // sort the result set to get document pages together while (this_doc != end_doc) { // don't include docs that didn't match phrases (if there were any) // those that did match will have been sorted to the top if ((*this_doc).num_phrase_match < num_phrases) break; get_top ((*this_doc).OID, top); map::const_iterator it = topOIDs.find (top); if (it == topOIDs.end()) { // haven't seen this document before topOIDs[top] = count; OIDs[count].push_back (*this_doc); count ++; } else { OIDs[(*it).second].push_back (*this_doc); } this_doc ++; } text_t link, icon; map::iterator here = OIDs.begin(); map::iterator end = OIDs.end(); count = 1; bool done = false; int arg_r = args.getintarg("r"); int arg_o = args.getintarg("o"); int arg_m = args.getintarg("m"); while (here != end) { ResultDocInfo_tarray::const_iterator thisOID = (*here).second.begin(); ResultDocInfo_tarray::const_iterator lastOID = (*here).second.end(); icon.clear(); link.clear(); // link will always be empty as we're including the link in the icon bool first = true; while (thisOID != lastOID) { if (count < arg_r) {thisOID ++; count ++; continue;} if ((count >= (arg_o + arg_r)) || count > arg_m) { done = true; if (!icon.empty()) { textout << outconvert << disp << "\n" << get_formatted_string (*thisOID, formatlistptr, link, icon) << "\n" << "\n"; } break; } else { const text_t &title = (*thisOID).metadata[metasize-1].values.back(); if (title.empty() && ((*here).second.size() == 1)) icon = "_iconclosedbook_"; else { if (first) icon += "_icontext_
"; icon += "page " + title + "
\n"; } if ((thisOID + 1) == lastOID) { textout << outconvert << disp << "\n" << get_formatted_string (*thisOID, formatlistptr, link, icon) << "\n" << "\n"; } count ++; } if (done) break; first = false; thisOID ++; } here ++; } textout << "
\n"; delete (formatlistptr); // output the footer textout << outconvert << disp << "_query:footer_"; } return true; }