Changeset 275 for trunk/gsdl/src/recpt


Ignore:
Timestamp:
1999-06-16T14:08:38+12:00 (25 years ago)
Author:
sjboddie
Message:

got queryaction working

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

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/Makefile

    r257 r275  
    1313CCFLAGS = -g -Wall -Wunused -pedantic -W -Woverloaded-virtual # -Wshadow
    1414DEFS = -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DUSE_FASTCGI -DGSDLSERVER \
    15        -D_LITTLE_ENDIAN
     15       -D_LITTLE_ENDIAN -DGSDLSERVER
    1616INCLUDES = -I../../lib -I../../packages/mg-1.3d -I../../packages/mg-1.3d/lib \
    1717           -I../../packages/mg-1.3d/src/text -I../../packages/fcgi/include
     
    3838                converter.h recptconfig.h cgiutils.h OIDtools.h browsetools.h htmlgen.h \
    3939        statusaction.h pageaction.h comtypes.h recptproto.h \
    40         pingaction.h queryaction.h documentaction.h
     40        pingaction.h queryaction.h documentaction.h htmlutils.h \
     41        querytools.h
    4142
    4243RECEPTHEADERS =
     
    5556                converter.cpp recptconfig.cpp cgiutils.cpp OIDtools.cpp browsetools.cpp \
    5657        htmlgen.cpp statusaction.cpp pageaction.cpp comtypes.cpp \
    57         recptproto.cpp pingaction.cpp queryaction.cpp documentaction.cpp
     58        recptproto.cpp pingaction.cpp queryaction.cpp documentaction.cpp \
     59        htmlutils.cpp querytools.cpp
    5860
    5961RECPTSOURCES = recptmain.cpp
     
    7274                converter.o recptconfig.o cgiutils.o OIDtools.o browsetools.o \
    7375        htmlgen.o statusaction.o pageaction.o comtypes.o \
    74         recptproto.o pingaction.o queryaction.o documentaction.o
     76        recptproto.o pingaction.o queryaction.o documentaction.o \
     77        htmlutils.o querytools.o
    7578
    7679RECPTOBJECTS = recptmain.o
     
    154157 /usr/include/g++/fstream.h action.h recptproto.h comtypes.h \
    155158 converter.h ../../lib/gsdlunicode.h ../../lib/fileutil.h cgiutils.h \
    156  OIDtools.h /usr/include/assert.h /usr/include/time.h \
     159 htmlutils.h OIDtools.h /usr/include/assert.h /usr/include/time.h \
    157160 /usr/include/sys/time.h /usr/include/linux/types.h \
    158161 /usr/include/linux/posix_types.h /usr/include/asm/posix_types.h \
     
    522525 /usr/include/g++/algorithm /usr/include/g++/algo.h \
    523526 /usr/include/g++/heap.h /usr/include/g++/tempbuf.h \
    524  /usr/include/g++/fstream.h recptproto.h comtypes.h
     527 /usr/include/g++/fstream.h recptproto.h comtypes.h querytools.h
    525528documentaction.o: documentaction.cpp documentaction.h action.h \
    526529 ../../lib/gsdlconf.h ../../lib/site.h ../../lib/text_t.h \
     
    548551 /usr/include/g++/heap.h /usr/include/g++/tempbuf.h \
    549552 /usr/include/g++/fstream.h recptproto.h comtypes.h browsetools.h \
    550  OIDtools.h
     553 OIDtools.h querytools.h ../../packages/mg-1.3d/lib/unitool.h
     554htmlutils.o: htmlutils.cpp htmlutils.h ../../lib/gsdlconf.h \
     555 ../../lib/site.h ../../lib/text_t.h /usr/include/g++/vector \
     556 /usr/include/g++/vector.h /usr/include/g++/function.h \
     557 /usr/include/g++/algobase.h /usr/include/g++/pair.h \
     558 /usr/include/g++/iterator.h \
     559 /usr/lib/gcc-lib/i486-linux/2.7.2/include/stddef.h \
     560 /usr/include/g++/iostream.h /usr/include/g++/streambuf.h \
     561 /usr/include/libio.h /usr/include/_G_config.h \
     562 /usr/include/sys/cdefs.h /usr/include/g++/defalloc.h \
     563 /usr/include/g++/new.h /usr/include/g++/std/new.h \
     564 /usr/include/g++/std/cstddef.h /usr/include/stdlib.h \
     565 /usr/include/features.h /usr/include/errno.h \
     566 /usr/include/linux/errno.h /usr/include/asm/errno.h \
     567 /usr/include/alloca.h \
     568 /usr/lib/gcc-lib/i486-linux/2.7.2/include/limits.h \
     569 /usr/lib/gcc-lib/i486-linux/2.7.2/include/syslimits.h \
     570 /usr/include/limits.h /usr/include/posix1_lim.h \
     571 /usr/include/linux/limits.h /usr/include/posix2_lim.h \
     572 /usr/include/g++/list /usr/include/g++/list.h /usr/include/g++/set \
     573 /usr/include/g++/set.h /usr/include/g++/tree.h \
     574 /usr/include/g++/projectn.h /usr/include/g++/map \
     575 /usr/include/g++/map.h
     576querytools.o: querytools.cpp querytools.h cgiargs.h \
     577 ../../lib/gsdlconf.h ../../lib/site.h ../../lib/text_t.h \
     578 /usr/include/g++/vector /usr/include/g++/vector.h \
     579 /usr/include/g++/function.h /usr/include/g++/algobase.h \
     580 /usr/include/g++/pair.h /usr/include/g++/iterator.h \
     581 /usr/lib/gcc-lib/i486-linux/2.7.2/include/stddef.h \
     582 /usr/include/g++/iostream.h /usr/include/g++/streambuf.h \
     583 /usr/include/libio.h /usr/include/_G_config.h \
     584 /usr/include/sys/cdefs.h /usr/include/g++/defalloc.h \
     585 /usr/include/g++/new.h /usr/include/g++/std/new.h \
     586 /usr/include/g++/std/cstddef.h /usr/include/stdlib.h \
     587 /usr/include/features.h /usr/include/errno.h \
     588 /usr/include/linux/errno.h /usr/include/asm/errno.h \
     589 /usr/include/alloca.h \
     590 /usr/lib/gcc-lib/i486-linux/2.7.2/include/limits.h \
     591 /usr/lib/gcc-lib/i486-linux/2.7.2/include/syslimits.h \
     592 /usr/include/limits.h /usr/include/posix1_lim.h \
     593 /usr/include/linux/limits.h /usr/include/posix2_lim.h \
     594 /usr/include/g++/list /usr/include/g++/list.h /usr/include/g++/set \
     595 /usr/include/g++/set.h /usr/include/g++/tree.h \
     596 /usr/include/g++/projectn.h /usr/include/g++/map \
     597 /usr/include/g++/map.h recptproto.h comtypes.h
    551598recptmain.o: recptmain.cpp receptionist.h ../../lib/gsdlconf.h \
    552599 ../../lib/site.h ../../lib/text_t.h /usr/include/g++/vector \
  • trunk/gsdl/src/recpt/queryaction.cpp

    r206 r275  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/06/16 02:08:38  sjboddie
     15   got queryaction working
     16
    1417   Revision 1.3  1999/03/25 03:06:45  sjboddie
    1518
     
    3033
    3134#include "queryaction.h"
    32 
     35#include "querytools.h"
    3336
    3437queryaction::queryaction () {
     
    142145}
    143146
    144 bool queryaction::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) {
     147bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
     148                 ostream &logout) {
     149
    145150  // check t argument
     151  int arg_t = args.getintarg("t");
     152  if (arg_t != 0 && arg_t != 1) {
     153    logout << "Warning: \"t\" argument out of range (" << arg_t << ")\n";
     154    args["t"] = argsinfo["t"].argdefault;
     155  }
    146156
    147157  // check k argument
     158  int arg_k = args.getintarg("k");
     159  if (arg_k != 0 && arg_k != 1) {
     160    logout << "Warning: \"k\" argument out of range (" << arg_k << ")\n";
     161    args["k"] = argsinfo["k"].argdefault;
     162  }
    148163
    149164  // check s argument
     165  int arg_s = args.getintarg("s");
     166  if (arg_s != 0 && arg_s != 1) {
     167    logout << "Warning: \"s\" argument out of range (" << arg_s << ")\n";
     168    args["s"] = argsinfo["s"].argdefault;
     169  }
    150170
    151171  // check m argument
     172  int arg_m = args.getintarg("m");
     173  if (arg_m < 0) {
     174    logout << "Warning: \"m\" argument less than 0 (" << arg_m << ")\n";
     175    args["m"] = argsinfo["m"].argdefault;
     176  }
    152177
    153178  // check o argument
     179  int arg_o = args.getintarg("o");
     180  if (arg_o < 0) {
     181    logout << "Warning: \"o\" argument less than 0 (" << arg_o << ")\n";
     182    args["o"] = argsinfo["o"].argdefault;
     183  }
    154184
    155185  // check r argument
     186  int arg_r = args.getintarg("r");
     187  if (arg_r < 1) {
     188    logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";
     189    args["r"] = argsinfo["r"].argdefault;
     190  }
    156191
    157192  return true;
     
    166201void queryaction::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
    167202                      recptproto */*collectproto*/, ostream &/*logout*/) {
    168 }
    169 
    170 void queryaction::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
    171                       recptproto */*collectproto*/, ostream &/*logout*/) {
    172 }
    173 
    174 bool queryaction::do_action (cgiargsclass &/*args*/, recptproto */*collectproto*/,
    175                   displayclass &/*disp*/, outconvertclass &/*outconvert*/,
    176                   ostream &/*textout*/, ostream &/*logout*/) {
    177   return false;
    178 }
     203
     204  // define_internal_macros doesn't set anything for this action. The following
     205  // macros are set later though in define_query_macros (they can't be set until
     206  // the query has been done).
     207
     208  // _freqmsg_      the term frequency string
     209
     210  // _quotedquery_  the part of the query string that was quoted for post-processing
     211
     212  // _resultline_   the "x documents matched the query" string
     213
     214  // _prevfirst_    these are used when setting up the links to previous/next
     215  // _prevlast_     pages of results (_thisfirst_ and _thislast_ are used to set
     216  // _nextfirst_    the 'results x-x for query: xxxx' string in the title bar)
     217  // _nextlast_
     218  // _thisfirst_
     219  // _thislast_
     220 
     221}
     222
     223// sets the selection box macros _hselection_, _jselection_, and _nselection_.
     224// each option will need an _optionxoption_ macro (i.e. an _hselection_ macro
     225// with options stx and ptx will need _optionhstx_ and _optionhptx_ macros)
     226void queryaction::set_option_macro (const text_t &macroname, text_t current_value,
     227                    const FilterOption_t &option, displayclass &disp) {
     228 
     229  if (option.validValues.size() < 2) return;
     230
     231  text_t macrovalue = "<select name=\"" + macroname + "\">\n";
     232
     233  if (current_value.empty()) current_value = option.defaultValue;
     234
     235  text_tarray::const_iterator thisvalue = option.validValues.begin();
     236  text_tarray::const_iterator endvalue = option.validValues.end();
     237
     238  while (thisvalue != endvalue) {
     239    macrovalue += "<option value=\"" + *thisvalue + "\"";
     240    if (*thisvalue == current_value)
     241      macrovalue += " selected";
     242    macrovalue += ">_option" + macroname + *thisvalue + "_\n";
     243    thisvalue ++;
     244  }
     245  macrovalue += "</select>\n";
     246  disp.setmacro (macroname + "selection", "Global", macrovalue);
     247}
     248
     249void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args,
     250                      recptproto *collectproto, ostream &logout) {
     251
     252  // define_external_macros sets the following macros:
     253
     254  // some or all of these may not be required to be set
     255  // _hselection_  the selection box for the main part of the index
     256  // _jselection_  the selection box for the subcollection part of the index
     257  // _nselection_  the selection box for the language part of the index
     258
     259 
     260  // can't do anything if collectproto is null (i.e. no collection was specified)
     261  if (collectproto == NULL) return;
     262
     263  comerror_t err;
     264  InfoFilterOptionsResponse_t response;
     265  InfoFilterOptionsRequest_t request;
     266  request.filterName = "QueryFilter";
     267 
     268  collectproto->get_filteroptions (args["c"], request, response, err, logout);
     269  if (err == noError) {
     270
     271    FilterOption_tmap::const_iterator it;
     272    FilterOption_tmap::const_iterator end = response.filterOptions.end();
     273
     274    // _hselection_ (Index)
     275    it = response.filterOptions.find ("Index");
     276      if (it != end) set_option_macro ("h", args["h"], (*it).second, disp);
     277
     278    // _jselection_ (Subcollection)
     279    it = response.filterOptions.find ("Subcollection");
     280      if (it != end) set_option_macro ("j", args["j"], (*it).second, disp);
     281
     282    // _nselection_ (Language)
     283    it = response.filterOptions.find ("Language");
     284      if (it != end) set_option_macro ("n", args["n"], (*it).second, disp);
     285  }
     286}
     287
     288bool queryaction::do_action (cgiargsclass &args, recptproto *collectproto,
     289                 displayclass &disp, outconvertclass &outconvert,
     290                 ostream &textout, ostream &logout) {
     291
     292  if (collectproto == NULL) {
     293    logout << "queryaction::do_action called with NULL collectproto\n";
     294    textout << outconvert << disp << "_query:header_\n"
     295        << "Error: Attempt to do query without setting collection\n"
     296        << "_query:footer_\n";
     297  } else { 
     298
     299    text_t quotedstring;
     300    FilterResponse_t response;
     301   
     302    // do the query
     303    FilterRequest_t request;
     304    request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
     305    request.fields.push_back ("Title");
     306    request.getParents = true;
     307    if (!do_query (request, args, collectproto, quotedstring, response, logout))
     308      return false;
     309   
     310    // set macros
     311    define_query_macros (args, disp, response, quotedstring);
     312   
     313    // output the header
     314    textout << outconvert << disp << "_query:header_\n_query:content_";
     315   
     316    // output results
     317    ResultDocInfo_tarray::const_iterator this_doc = response.docInfo.begin();
     318    ResultDocInfo_tarray::const_iterator end_doc = response.docInfo.end();
     319   
     320    textout << "<table cellspacing=4>\n";
     321    while (this_doc != end_doc) {
     322
     323      text_t link = "<a href=\"_httpdocument_&d=" + (*this_doc).OID + "\">";
     324
     325      text_t title;
     326      text_tarray::const_iterator this_title = (*this_doc).metadata[0].values.begin();
     327      text_tarray::const_iterator end_title = (*this_doc).metadata[0].values.end();
     328      while (this_title != end_title) {
     329    if ((this_title + 1) == end_title)
     330      title += link + *this_title + "</a>";
     331    else
     332      title += *this_title + ": ";
     333    this_title ++;
     334      }
     335     
     336      textout << outconvert << disp << "<tr><td valign=top nowrap>" << link
     337          << "_icontext_</a></td><td>" << title << "</td></tr>\n";
     338     
     339      this_doc ++;
     340    }
     341    textout << "</table>\n";
     342   
     343    // output the footer
     344    textout << outconvert << disp << "_query:footer_";
     345  }
     346  return true;
     347}
     348 
     349// set_query_macros sets the macros that couldn't be set until the
     350// query had been done. Those macros are _freqmsg_, _quotedquery_,
     351// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
     352// _thisfirst_, and _thislast_
     353void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
     354                       const FilterResponse_t &response,
     355                       const text_t &quotedstring) {
     356
     357  int numdocs = response.numDocs;
     358  int arg_m = args.getintarg("m");
     359  if (numdocs > arg_m)
     360    numdocs = arg_m;
     361
     362  // set up _freqmsg_ and _quotedquery_ macros
     363  text_t freqmsg = "_textfreqmsg1_";
     364  TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
     365  TermInfo_tarray::const_iterator end_term = response.termInfo.end();
     366  while (this_term != end_term) {
     367    freqmsg += (*this_term).term + ": " + (*this_term).freq;
     368    if ((this_term + 1) != end_term)
     369      freqmsg += ", ";
     370    this_term ++;
     371  }
     372 
     373  disp.setmacro ("quotedquery", "query", quotedstring);
     374  disp.setmacro ("freqmsg", "query", freqmsg);
     375
     376
     377  // set up _resultline_ macro
     378  text_t resline;
     379
     380  // can't use isApprox here as it will be false as long
     381  // as numDocs < MAXDOCS (currently 200). If arg_m is less
     382  // than MAXDOCS numDocs can be greater than arg_m while
     383  // isApprox is false.
     384  if (response.numDocs >= numdocs) resline = "_textmorethan_";
     385  if (numdocs == 0) resline = "_textnodocs_";
     386  else if (numdocs == 1) resline += "_text1doc_";
     387  else resline += text_t(numdocs) + "_textlotsdocs_";
     388
     389  disp.setmacro("resultline", "query", resline);
     390
     391
     392  int firstdoc = args.getintarg("r");
     393  int hitsperpage = args.getintarg("o");
     394
     395  // set up _thisfirst_ and _thislast_ macros
     396  disp.setmacro ("thisfirst", "query", firstdoc);
     397  int thislast = firstdoc + (hitsperpage - 1);
     398  if (thislast > numdocs) thislast = numdocs;
     399  disp.setmacro ("thislast", "query", thislast);
     400
     401  // set up _prevfirst_ and _prevlast_ macros
     402  if (firstdoc > 1) {
     403    disp.setmacro ("prevlast", "query", firstdoc - 1);
     404    int prevfirst = firstdoc - hitsperpage;
     405    if (prevfirst < 1) prevfirst = 1;
     406    disp.setmacro ("prevfirst", "query", prevfirst);
     407  }
     408
     409  // set up _nextfirst_ and _nextlast_ macros
     410  if (thislast < numdocs) {
     411    disp.setmacro ("nextfirst", "query", thislast + 1);
     412    int nextlast = thislast + hitsperpage;
     413    if (nextlast > numdocs) nextlast = numdocs;
     414    disp.setmacro ("nextlast", "query", nextlast);
     415  }
     416}
     417
     418
     419
  • trunk/gsdl/src/recpt/queryaction.h

    r206 r275  
    1919
    2020class queryaction : public action {
     21
     22protected:
     23  void define_query_macros (cgiargsclass &args, displayclass &disp,
     24                const FilterResponse_t &response,
     25                const text_t &quotedstring);
     26  void set_option_macro (const text_t &macroname, text_t current_value,
     27             const FilterOption_t &option, displayclass &disp);
     28
     29
    2130public:
    2231  queryaction ();
     
    2837  text_t get_action_name () {return "q";}
    2938 
    30   bool check_cgiargs (cgiargsclass &args, ostream &logout);
     39  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
     40              ostream &logout);
    3141  void get_cgihead_info (cgiargsclass &args, response_t &response,
    3242             text_t &response_data, ostream &logout);
Note: See TracChangeset for help on using the changeset viewer.