source: other-projects/trunk/protemix/src/recpt/ptmxqueryaction.cpp@ 14162

Last change on this file since 14162 was 3207, checked in by sjboddie, 22 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
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
34ptmxqueryaction::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
63ptmxqueryaction::~ptmxqueryaction () {
64}
65
66bool 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
111 if (!args["c1"].empty() && args["c1"] != "Any") {
112 formattedstring += "[" + args["c1"] + "]:CL";
113 }
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 formattedstring += args["c3"];
122 }
123 if (!args["q"].empty()) {
124 if (!formattedstring.empty()) formattedstring += " & ";
125 // do synonym searching stuff
126 text_t qstring = args["q"];
127 int insert_equiv_terms(text_t&); // forward declaration
128 insert_equiv_terms(qstring);
129 formattedstring += qstring;
130 }
131
132 outconvertclass text_t2ascii;
133 logout << text_t2ascii << "formattedstring: " << formattedstring << "\n";
134
135 if (!formattedstring.empty()) {
136 // note! formattedstring is in unicode! mg and mgpp must convert!
137 set_queryfilter_options (request, formattedstring, args);
138 collectproto->filter (collection, request, response, err, logout);
139 if (err != noError) {
140 outconvertclass text_t2ascii;
141 logout << text_t2ascii
142 << "queryaction::search_single_collections: call to QueryFilter failed "
143 << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
144 return false;
145 }
146
147 define_query_macros (args, disp, response);
148 }
149
150 textout << outconvert << disp << "_query:header_\n"
151 << "_query:content_";
152
153 // output the results
154 bool use_table = is_table_content (formatlistptr);
155 bptr->output_section_group (response, args, collection, 0, formatlistptr,
156 use_table, request.fields, request.getParents,
157 collectproto, disp, outconvert, textout, logout);
158
159
160 textout << outconvert << disp << "_query:footer_";
161
162 delete (formatlistptr);
163
164 return true;
165}
Note: See TracBrowser for help on using the repository browser.