[891] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * cstrqueryaction.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 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.
|
---|
| 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 | * $Id: cstrqueryaction.cpp 891 2000-02-01 22:32:36Z sjboddie $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*
|
---|
| 29 | $Log$
|
---|
| 30 | Revision 1.1 2000/02/01 22:32:37 sjboddie
|
---|
| 31 | Initial revision
|
---|
| 32 |
|
---|
| 33 | Revision 1.1 1999/09/07 21:49:43 sjboddie
|
---|
| 34 | new cstr receptionist
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | #include "cstrqueryaction.h"
|
---|
| 41 | #include "cstrquerytools.h"
|
---|
| 42 | #include "formattools.h"
|
---|
| 43 | #include "OIDtools.h"
|
---|
| 44 | #include "text_t.h"
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | struct ltint
|
---|
| 48 | {
|
---|
| 49 | bool operator()(const int &t1, const int &t2) const
|
---|
| 50 | { return t1 < t2; }
|
---|
| 51 | };
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | bool cstrqueryaction::do_action (cgiargsclass &args, const ColInfoResponse_t &collectinfo,
|
---|
| 55 | recptproto *collectproto, displayclass &disp,
|
---|
| 56 | outconvertclass &outconvert, ostream &textout,
|
---|
| 57 | ostream &logout) {
|
---|
| 58 |
|
---|
| 59 | if (formatstring.empty()) {
|
---|
| 60 | text_tmap::const_iterator result = collectinfo.format.find("result");
|
---|
| 61 | if (result != collectinfo.format.end())
|
---|
| 62 | formatstring = (*result).second;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | // if we still don't have a format string use the default
|
---|
| 66 | if (formatstring.empty())
|
---|
| 67 | formatstring = "<td valign=top nowrap>[link]_icontext_[/link]</td><td>[Title]</td>";
|
---|
| 68 |
|
---|
| 69 | if (collectproto == NULL) {
|
---|
| 70 | logout << "cstrqueryaction::do_action called with NULL collectproto\n";
|
---|
| 71 | textout << outconvert << disp << "_query:header_\n"
|
---|
| 72 | << "Error: Attempt to do query without setting collection\n"
|
---|
| 73 | << "_query:footer_\n";
|
---|
| 74 | } else {
|
---|
| 75 |
|
---|
| 76 | FilterRequest_t request;
|
---|
| 77 | FilterResponse_t response;
|
---|
| 78 | format_t *formatlistptr = new format_t();
|
---|
| 79 |
|
---|
| 80 | parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
|
---|
| 81 |
|
---|
| 82 | request.fields.push_back ("Title");
|
---|
| 83 | int metasize = request.fields.size();
|
---|
| 84 |
|
---|
| 85 | // do the query
|
---|
| 86 | request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
|
---|
| 87 | if (!do_query (request, args, collectproto, response, logout))
|
---|
| 88 | return false;
|
---|
| 89 |
|
---|
| 90 | // set macros
|
---|
| 91 | define_query_macros (args, disp, response);
|
---|
| 92 |
|
---|
| 93 | // output the header
|
---|
| 94 | textout << outconvert << disp << "_query:header_\n"
|
---|
| 95 | << "_query:content_";
|
---|
| 96 |
|
---|
| 97 | // output the results
|
---|
| 98 | textout << "<table cellspacing=4>\n";
|
---|
| 99 | ResultDocInfo_tarray::const_iterator this_doc = response.docInfo.begin();
|
---|
| 100 | ResultDocInfo_tarray::const_iterator end_doc = response.docInfo.end();
|
---|
| 101 |
|
---|
| 102 | text_t top;
|
---|
| 103 | map<text_t, int, lttext_t> topOIDs;
|
---|
| 104 | map<int, ResultDocInfo_tarray, ltint> OIDs;
|
---|
| 105 | int count = 0;
|
---|
| 106 |
|
---|
| 107 | // sort the result set to get document pages together
|
---|
| 108 | while (this_doc != end_doc) {
|
---|
| 109 | // don't include docs that didn't match phrases (if there were any)
|
---|
| 110 | // those that did match will have been sorted to the top
|
---|
| 111 | if ((*this_doc).num_phrase_match < num_phrases) break;
|
---|
| 112 |
|
---|
| 113 | get_top ((*this_doc).OID, top);
|
---|
| 114 | map<text_t, int, lttext_t>::const_iterator it = topOIDs.find (top);
|
---|
| 115 | if (it == topOIDs.end()) {
|
---|
| 116 | // haven't seen this document before
|
---|
| 117 | topOIDs[top] = count;
|
---|
| 118 | OIDs[count].push_back (*this_doc);
|
---|
| 119 | count ++;
|
---|
| 120 | } else {
|
---|
| 121 | OIDs[(*it).second].push_back (*this_doc);
|
---|
| 122 | }
|
---|
| 123 | this_doc ++;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | text_t link, icon;
|
---|
| 127 | map<int, ResultDocInfo_tarray, ltint>::iterator here = OIDs.begin();
|
---|
| 128 | map<int, ResultDocInfo_tarray, ltint>::iterator end = OIDs.end();
|
---|
| 129 | count = 1;
|
---|
| 130 | bool done = false;
|
---|
| 131 | int arg_r = args.getintarg("r");
|
---|
| 132 | int arg_o = args.getintarg("o");
|
---|
| 133 | int arg_m = args.getintarg("m");
|
---|
| 134 | while (here != end) {
|
---|
| 135 | ResultDocInfo_tarray::const_iterator thisOID = (*here).second.begin();
|
---|
| 136 | ResultDocInfo_tarray::const_iterator lastOID = (*here).second.end();
|
---|
| 137 |
|
---|
| 138 | icon.clear();
|
---|
| 139 | link.clear(); // link will always be empty as we're including the link in the icon
|
---|
| 140 | bool first = true;
|
---|
| 141 |
|
---|
| 142 | while (thisOID != lastOID) {
|
---|
| 143 |
|
---|
| 144 | if (count < arg_r) {thisOID ++; count ++; continue;}
|
---|
| 145 | if ((count >= (arg_o + arg_r)) || count > arg_m) {
|
---|
| 146 | done = true;
|
---|
| 147 | if (!icon.empty()) {
|
---|
| 148 | textout << outconvert << disp << "<tr>\n"
|
---|
| 149 | << get_formatted_string (*thisOID, formatlistptr, link, icon) << "\n"
|
---|
| 150 | << "</tr>\n";
|
---|
| 151 | }
|
---|
| 152 | break;
|
---|
| 153 |
|
---|
| 154 | } else {
|
---|
| 155 |
|
---|
| 156 | const text_t &title = (*thisOID).metadata[metasize-1].values.back();
|
---|
| 157 |
|
---|
| 158 | if (title.empty() && ((*here).second.size() == 1))
|
---|
| 159 | icon = "<a href=\"_httpdocument_&cl=search&d=" + (*thisOID).OID + "\">_iconclosedbook_</a>";
|
---|
| 160 | else {
|
---|
| 161 | if (first) icon += "_icontext_<br>";
|
---|
| 162 | icon += "<a href=\"_httpdocument_&cl=search&d=" + (*thisOID).OID + "\">page " +
|
---|
| 163 | title + "</a><br>\n";
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | if ((thisOID + 1) == lastOID) {
|
---|
| 167 | textout << outconvert << disp << "<tr>\n"
|
---|
| 168 | << get_formatted_string (*thisOID, formatlistptr, link, icon) << "\n"
|
---|
| 169 | << "</tr>\n";
|
---|
| 170 | }
|
---|
| 171 | count ++;
|
---|
| 172 | }
|
---|
| 173 | if (done) break;
|
---|
| 174 | first = false;
|
---|
| 175 | thisOID ++;
|
---|
| 176 | }
|
---|
| 177 | here ++;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | textout << "</table>\n";
|
---|
| 181 |
|
---|
| 182 | delete (formatlistptr);
|
---|
| 183 |
|
---|
| 184 | // output the footer
|
---|
| 185 | textout << outconvert << disp << "_query:footer_";
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | return true;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 |
|
---|