Changeset 4220


Ignore:
Timestamp:
2003-05-01T14:38:08+12:00 (21 years ago)
Author:
kjdon
Message:

the call to filter gets an err of syntaxError if the query was invalid. in this case, we set the freqmsg macro to say invalid query syntax, rather than word count: ... and dont bother to display the results.

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/queryaction.cpp

    r4200 r4220  
    10771077    return true;
    10781078  }
     1079  bool syntax_error = false;
    10791080
    10801081  set_queryfilter_options (request, formattedstring, args);
     
    11341135    // do the query
    11351136    collectproto->filter (*col_here, request, response, err, logout);
    1136     if (err != noError) {
     1137    if (err != noError && err != syntaxError) {
    11371138      outconvertclass text_t2ascii;
    11381139      logout << text_t2ascii
     
    11421143    }
    11431144
     1145    if (err == syntaxError) {
     1146      syntax_error = true;
     1147      freqmsg = "_textinvalidquery_";
     1148      // assume the syntax will be invalid for all colls
     1149      break;
     1150    }
    11441151    if (isApprox == Exact)
    11451152      isApprox = response.isApprox;
     
    11851192      << "_query:content_";
    11861193
    1187   // now go through each result and output it
    1188   QueryResult_tset::iterator res_here = results.begin();
    1189   QueryResult_tset::iterator res_end = results.end();
    1190   text_tset metadata; // empty !!
    1191   bool getParents = false; // don't care !!
    1192   bool use_table;
    1193   ResultDocInfo_t thisdoc;
    1194   format_t *formatlistptr = NULL;
    1195   browserclass *browserptr = NULL;
    1196 
    1197   int count = 1;
    1198   int firstdoc = args.getintarg("r");
    1199   int hitsperpage = args.getintarg("o");
    1200   int thislast = firstdoc + (hitsperpage - 1);
    1201 
    1202   // output results
    1203   while (res_here != res_end) {
    1204     if (count < firstdoc) {count ++; res_here ++; continue;}
    1205     if (count > thislast) break;
    1206     formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
    1207     browserptr = colinfomap[(*res_here).collection].browserptr;
    1208     thisdoc = (*res_here).doc;
    1209     use_table = is_table_content (formatlistptr);
    1210 
    1211     collectproto = protos->getrecptproto ((*res_here).collection, logout);
    1212     if (collectproto == NULL) {
    1213       logout << outconvert << "queryaction::search_multiple_collections: " << (*res_here).collection
    1214          << " collection has a NULL collectproto, ignoring results\n";
     1194  if (!syntax_error) {
     1195   
     1196    // now go through each result and output it
     1197    QueryResult_tset::iterator res_here = results.begin();
     1198    QueryResult_tset::iterator res_end = results.end();
     1199    text_tset metadata; // empty !!
     1200    bool getParents = false; // don't care !!
     1201    bool use_table;
     1202    ResultDocInfo_t thisdoc;
     1203    format_t *formatlistptr = NULL;
     1204    browserclass *browserptr = NULL;
     1205   
     1206    int count = 1;
     1207    int firstdoc = args.getintarg("r");
     1208    int hitsperpage = args.getintarg("o");
     1209    int thislast = firstdoc + (hitsperpage - 1);
     1210   
     1211    // output results
     1212    while (res_here != res_end) {
     1213      if (count < firstdoc) {count ++; res_here ++; continue;}
     1214      if (count > thislast) break;
     1215      formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
     1216      browserptr = colinfomap[(*res_here).collection].browserptr;
     1217      thisdoc = (*res_here).doc;
     1218      use_table = is_table_content (formatlistptr);
     1219     
     1220      collectproto = protos->getrecptproto ((*res_here).collection, logout);
     1221      if (collectproto == NULL) {
     1222    logout << outconvert << "queryaction::search_multiple_collections: " << (*res_here).collection
     1223           << " collection has a NULL collectproto, ignoring results\n";
     1224    res_here ++;
     1225    continue;
     1226      }
     1227     
     1228      browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0,
     1229                    formatlistptr, use_table, metadata, getParents,
     1230                    collectproto, disp, outconvert, textout, logout);
     1231      //    textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
    12151232      res_here ++;
    1216       continue;
    1217     }
    1218 
    1219     browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0,
    1220                           formatlistptr, use_table, metadata, getParents,
    1221                           collectproto, disp, outconvert, textout, logout);
    1222     //    textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
    1223     res_here ++;
    1224     count ++;
    1225   }
    1226 
     1233      count ++;
     1234    }
     1235  }
    12271236  textout << outconvert << disp << "_query:footer_";
    12281237 
     
    12881297    set_queryfilter_options (request, formattedstring, args);
    12891298    collectproto->filter (collection, request, response, err, logout);
    1290     if (err != noError) {
     1299    if (err != noError && err != syntaxError) {
    12911300      outconvertclass text_t2ascii;
    12921301      logout << text_t2ascii
     
    12951304      return false;
    12961305    }
    1297  
     1306
     1307    bool syntax_error = false;
     1308    if (err == syntaxError) syntax_error = true;
     1309    //return false;
    12981310    define_query_macros (args, disp, response.numDocs, response.isApprox);
    1299     define_single_query_macros(args, disp, response);
     1311    define_single_query_macros(args, disp, response, syntax_error);
    13001312
    13011313    // save the query if appropriate
     
    14321444void queryaction::define_single_query_macros (cgiargsclass &args,
    14331445                          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 ++;
     1446                          const FilterResponse_t &response,
     1447                          bool syntax_error) {
     1448    // set up _freqmsg_ and _quotedquery_ macros
     1449
     1450  text_t freqmsg = "";
     1451  if (syntax_error) {
     1452    freqmsg = "_textinvalidquery_";
     1453  } else {
     1454    freqmsg = "_textfreqmsg1_";
     1455    TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
     1456    TermInfo_tarray::const_iterator end_term = response.termInfo.end();
     1457    while (this_term != end_term) {
     1458      freqmsg += (*this_term).term + ": " + (*this_term).freq;
     1459      if ((this_term + 1) != end_term)
     1460    freqmsg += ", ";
     1461      this_term ++;
     1462    }
    14441463  }
    14451464  disp.setmacro ("freqmsg", "query", freqmsg);
  • trunk/gsdl/src/recpt/queryaction.h

    r4200 r4220  
    6868  virtual void define_single_query_macros (cgiargsclass &args,
    6969                       displayclass &disp,
    70                        const FilterResponse_t &response);
     70                       const FilterResponse_t &response,
     71                       bool syntax_error);
    7172  virtual void define_query_macros (cgiargsclass &args, displayclass &disp,
    7273                int numDocs, isapprox isApprox);
Note: See TracChangeset for help on using the changeset viewer.