Changeset 4200
- Timestamp:
- 2003-04-30T14:41:06+12:00 (21 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/queryaction.cpp
r4194 r4200 1061 1061 FilterResponse_t response; 1062 1062 request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking; 1063 text_t formattedstring = args["q"];1064 1063 text_t freqmsg = "_textfreqmsg1_"; 1065 1064 int numdocs = 0; 1066 1065 isapprox isApprox = Exact; 1067 1066 1068 format_querystring (formattedstring, args.getintarg("b")); 1067 text_t formattedstring = ""; 1068 get_formatted_query_string(formattedstring, args, disp, logout); 1069 1070 if (formattedstring.empty()) { 1071 // dont bother doing a query if no query string 1072 define_history_macros (disp, args, protos, logout); 1073 textout << outconvert << disp << "_query:header_\n" 1074 << "_query:content_"; 1075 textout << outconvert << disp << "_query:footer_"; 1076 1077 return true; 1078 } 1079 1069 1080 set_queryfilter_options (request, formattedstring, args); 1070 1081 … … 1162 1173 } 1163 1174 col_here ++; 1164 } 1175 } // for each coll 1165 1176 1166 1177 disp.setmacro ("freqmsg", "query", freqmsg); 1167 1178 1168 int maxdocs = args.getintarg("m"); 1169 int firstdoc = args.getintarg("r"); 1170 int hitsperpage = args.getintarg("o"); 1171 if (num_phrases > 0) isApprox = Exact; 1172 if (maxdocs == -1) maxdocs = numdocs; 1173 else if (numdocs > maxdocs) { 1174 numdocs = maxdocs; 1175 isApprox = MoreThan; 1176 } 1177 if (hitsperpage == -1) hitsperpage = numdocs; 1178 1179 text_t resline; 1180 if (isApprox == Approximate) resline = "_textapprox_"; 1181 else if (isApprox == MoreThan) resline = "_textmorethan_"; 1182 1183 if (numdocs == 0) resline = "_textnodocs_"; 1184 else if (numdocs == 1) resline += "_text1doc_"; 1185 else resline += text_t(numdocs) + " _textlotsdocs_"; 1186 disp.setmacro("resultline", "query", resline); 1187 1179 define_query_macros( args, disp, numdocs, isApprox); 1180 // save the query if appropriate 1181 save_search_history(args, numdocs, isApprox); 1182 define_history_macros (disp, args, protos, logout); 1183 1184 textout << outconvert << disp << "_query:header_\n" 1185 << "_query:content_"; 1186 1187 // now go through each result and output it 1188 1188 QueryResult_tset::iterator res_here = results.begin(); 1189 1189 QueryResult_tset::iterator res_end = results.end(); … … 1195 1195 browserclass *browserptr = NULL; 1196 1196 1197 // set up _thisfirst_ and _thislast_ macros 1198 disp.setmacro ("thisfirst", "query", firstdoc); 1197 int count = 1; 1198 int firstdoc = args.getintarg("r"); 1199 int hitsperpage = args.getintarg("o"); 1199 1200 int thislast = firstdoc + (hitsperpage - 1); 1200 if (thislast > numdocs) thislast = numdocs;1201 disp.setmacro ("thislast", "query", thislast);1202 1203 // set up _prevfirst_ and _prevlast_ macros1204 if (firstdoc > 1) {1205 disp.setmacro ("prevlast", "query", firstdoc - 1);1206 int prevfirst = firstdoc - hitsperpage;1207 if (prevfirst < 1) prevfirst = 1;1208 disp.setmacro ("prevfirst", "query", prevfirst);1209 }1210 1211 // set up _nextfirst_ and _nextlast_ macros1212 if (thislast < numdocs) {1213 disp.setmacro ("nextfirst", "query", thislast + 1);1214 int nextlast = thislast + hitsperpage;1215 if (nextlast > numdocs) nextlast = numdocs;1216 disp.setmacro ("nextlast", "query", nextlast);1217 }1218 1219 textout << outconvert << disp << "_query:header_\n"1220 << "_query:content_";1221 1222 int count = 1;1223 1201 1224 1202 // output results … … 1289 1267 text_t formatstring; 1290 1268 if (!get_formatstring (classification, browsertype, 1291 cinfo->format, formatstring)) 1269 cinfo->format, formatstring)) { 1292 1270 formatstring = bptr->get_default_formatstring(); 1293 1271 } 1294 1272 FilterRequest_t request; 1295 1273 FilterResponse_t response; … … 1303 1281 request.filterResultOptions = FROID | FRmetadata | FRtermFreq; 1304 1282 text_t formattedstring = ""; 1305 1283 get_formatted_query_string(formattedstring, args, disp, logout); 1284 1285 1286 if (!formattedstring.empty()) { // do the query 1287 // note! formattedstring is in unicode! mg and mgpp must convert! 1288 set_queryfilter_options (request, formattedstring, args); 1289 collectproto->filter (collection, request, response, err, logout); 1290 if (err != noError) { 1291 outconvertclass text_t2ascii; 1292 logout << text_t2ascii 1293 << "queryaction::search_single_collections: call to QueryFilter failed " 1294 << "for " << collection << " collection (" << get_comerror_string (err) << ")\n"; 1295 return false; 1296 } 1297 1298 define_query_macros (args, disp, response.numDocs, response.isApprox); 1299 define_single_query_macros(args, disp, response); 1300 1301 // save the query if appropriate 1302 save_search_history(args, response.numDocs, response.isApprox); 1303 } 1304 define_history_macros (disp, args, protos, logout); 1305 1306 textout << outconvert << disp << "_query:header_\n" 1307 << "_query:content_"; 1308 1309 // output the results 1310 bool use_table = is_table_content (formatlistptr); 1311 bptr->output_section_group (response, args, collection, 0, formatlistptr, 1312 use_table, request.fields, request.getParents, 1313 collectproto, disp, outconvert, textout, logout); 1314 1315 1316 textout << outconvert << disp << "_query:footer_"; 1317 1318 delete (formatlistptr); 1319 1320 return true; 1321 } 1322 1323 // does the formatting of the query string - either uses q for a text search 1324 // or the form values for an form search 1325 // also adds dates if appropriate in text search 1326 void queryaction::get_formatted_query_string (text_t &formattedstring, 1327 cgiargsclass &args, 1328 displayclass &disp, 1329 ostream &logout) { 1306 1330 if (args["qt"]=="0") { // normal text search 1307 1331 formattedstring = args["q"]; 1308 1332 format_querystring (formattedstring, args.getintarg("b")); 1309 1333 add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"), 1310 args.getintarg("dsbc"), args.getintarg("debc"));1334 args.getintarg("dsbc"), args.getintarg("debc")); 1311 1335 } 1312 1336 else if (args["qt"]=="1" ){ // form search … … 1343 1367 } // args["qt"]=1 1344 1368 else { 1345 logout << "ERROR (query_action::search_single_collection): querytype not defined\n"; 1346 return false; 1347 } 1348 1349 if (!formattedstring.empty()) { // do the query 1350 // note! formattedstring is in unicode! mg and mgpp must convert! 1351 set_queryfilter_options (request, formattedstring, args); 1352 collectproto->filter (collection, request, response, err, logout); 1353 if (err != noError) { 1354 outconvertclass text_t2ascii; 1355 logout << text_t2ascii 1356 << "queryaction::search_single_collections: call to QueryFilter failed " 1357 << "for " << collection << " collection (" << get_comerror_string (err) << ")\n"; 1358 return false; 1359 } 1360 1361 define_query_macros (args, disp, response); 1362 1363 // save the query if appropriate 1364 if (!save_search_history(args, response)) 1365 logout << "save failed"; 1366 } 1367 1368 define_history_macros (disp, args, protos, logout); 1369 1370 textout << outconvert << disp << "_query:header_\n" 1371 << "_query:content_"; 1372 1373 // output the results 1374 bool use_table = is_table_content (formatlistptr); 1375 bptr->output_section_group (response, args, collection, 0, formatlistptr, 1376 use_table, request.fields, request.getParents, 1377 collectproto, disp, outconvert, textout, logout); 1378 1379 1380 textout << outconvert << disp << "_query:footer_"; 1381 1382 delete (formatlistptr); 1383 1384 return true; 1385 } 1386 1369 logout << "ERROR (query_action::get_formatted_query_string): querytype not defined\n"; 1370 } 1371 } 1372 1373 1387 1374 // define_query_macros sets the macros that couldn't be set until the 1388 // query had been done. Those macros are _freqmsg_, _quotedquery_,1375 // query had been done. Those macros are 1389 1376 // _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_, 1390 1377 // _thisfirst_, and _thislast_ 1391 void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp, 1392 const FilterResponse_t &response) { 1393 // set up _freqmsg_ and _quotedquery_ macros 1394 text_t freqmsg = "_textfreqmsg1_"; 1395 TermInfo_tarray::const_iterator this_term = response.termInfo.begin(); 1396 TermInfo_tarray::const_iterator end_term = response.termInfo.end(); 1397 while (this_term != end_term) { 1398 // check that the term doesn't consist completely of digits... 1399 // char *term = (*this_term).term.getcstr(); 1400 // char *lastchar; 1401 // strtol(term,&lastchar,10); 1402 // if(*lastchar != '\0'){ 1403 freqmsg += (*this_term).term + ": " + (*this_term).freq; 1404 if ((this_term + 1) != end_term) 1405 freqmsg += ", "; 1406 // } 1407 // delete term; 1408 this_term ++; 1409 } 1410 disp.setmacro ("freqmsg", "query", freqmsg); 1411 1378 // this has been simplified so it can be used with both search_single_coll 1379 // and search_multiple_coll 1380 void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp, 1381 int numdocs, isapprox isApprox) { 1382 1412 1383 // set up _resultline_ macro 1413 1384 text_t resline; 1414 1385 int maxdocs = args.getintarg("m"); 1415 int numdocs = response.numDocs;1416 isapprox isApprox = response.isApprox;1417 1386 if (num_phrases > 0) isApprox = Exact; 1418 1387 if (maxdocs == -1) maxdocs = numdocs; … … 1458 1427 } 1459 1428 1460 bool queryaction::save_search_history (cgiargsclass &args, const FilterResponse_t &response) 1461 { 1429 // define_single_query_macros sets the extra macros for search_single_coll 1430 // that couldn't be set until the query had been done. Those macros are 1431 // _freqmsg_, _quotedquery_ 1432 void queryaction::define_single_query_macros (cgiargsclass &args, 1433 displayclass &disp, 1434 const FilterResponse_t &response) { 1435 // set up _freqmsg_ and _quotedquery_ macros 1436 text_t freqmsg = "_textfreqmsg1_"; 1437 TermInfo_tarray::const_iterator this_term = response.termInfo.begin(); 1438 TermInfo_tarray::const_iterator end_term = response.termInfo.end(); 1439 while (this_term != end_term) { 1440 freqmsg += (*this_term).term + ": " + (*this_term).freq; 1441 if ((this_term + 1) != end_term) 1442 freqmsg += ", "; 1443 this_term ++; 1444 } 1445 disp.setmacro ("freqmsg", "query", freqmsg); 1446 } 1447 1448 // should this change for cross coll search?? 1449 bool queryaction::save_search_history (cgiargsclass &args, int numdocs, 1450 isapprox isApprox) { 1462 1451 if (args["q"]=="") return true; // null query, dont save 1463 if (args["hs"]=="0") return true; // only save when submit query 1464 // displayed1452 if (args["hs"]=="0") return true; // only save when submit query pressed 1453 1465 1454 // get userid 1466 1455 text_t userid = args["z"]; 1467 1456 1468 1457 // the number of docs goes on the front of the query string 1469 int numdocs= response.numDocs;1470 1458 text_t query = text_t(numdocs); 1471 if ( response.isApprox==MoreThan) { // there were more docs found1459 if (isApprox==MoreThan) { // there were more docs found 1472 1460 query.push_back('+'); 1473 1461 } -
trunk/gsdl/src/recpt/queryaction.h
r3546 r4200 66 66 int num_phrases; 67 67 68 virtual void define_single_query_macros (cgiargsclass &args, 69 displayclass &disp, 70 const FilterResponse_t &response); 68 71 virtual void define_query_macros (cgiargsclass &args, displayclass &disp, 69 const FilterResponse_t &response);72 int numDocs, isapprox isApprox); 70 73 74 void get_formatted_query_string (text_t &formattedstring, cgiargsclass &args, 75 displayclass &disp, ostream &logout); 71 76 void define_query_interface(displayclass &disp, cgiargsclass &args, 72 recptprotolistclass *protos, ostream &logout);73 77 recptprotolistclass *protos, ostream &logout); 78 74 79 void define_form_macros (displayclass &disp, cgiargsclass &args, 75 80 recptprotolistclass *protos, ostream &logout); … … 110 115 111 116 112 bool save_search_history(cgiargsclass &args, 113 const FilterResponse_t &response); 117 bool save_search_history(cgiargsclass &args, int numdocs, isapprox isApprox); 114 118 115 119 public:
Note:
See TracChangeset
for help on using the changeset viewer.