Ignore:
Timestamp:
1999-06-15T13:55:32+12:00 (25 years ago)
Author:
sjboddie
Message:
  • got text highlighting working
  • got multiple collections working (now outputs error message if an attempt is made to get a document when the "c" arg isn't set.
File:
1 edited

Legend:

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

    r261 r267  
    1212/*
    1313   $Log$
     14   Revision 1.4  1999/06/15 01:55:29  sjboddie
     15   - got text highlighting working
     16   - got multiple collections working (now outputs error message if an
     17     attempt is made to get a document when the "c" arg isn't set.
     18
    1419   Revision 1.3  1999/06/08 04:29:37  sjboddie
    1520   added argsinfo to the call to check_cgiargs to make it easy to set
     
    3843#include "browsetools.h"
    3944#include "OIDtools.h"
     45#include "querytools.h"
     46#include "unitool.h"
    4047
    4148documentaction::documentaction () {
     
    163170  // _cgiargcl_
    164171 
     172  // can't do anything if collectproto is null (i.e. no collection was specified)
     173  if (collectproto == NULL) return;
    165174
    166175  outconvertclass text_t2ascii;
     
    312321  // _javaimagescontent_    this is the javascript code to shove in to make the
    313322  //                        flashy buttons work
     323
     324 
     325  // can't do anything if collectproto is null (i.e. no collection was specified)
     326  if (collectproto == NULL) return;
    314327
    315328 
     
    423436
    424437bool documentaction::do_action (cgiargsclass &args, recptproto *collectproto,
    425                   displayclass &disp, outconvertclass &outconvert,
    426                   ostream &textout, ostream &logout) {
    427 
    428   text_tarray metadata;
    429   FilterResponse_t response;
    430   DocumentRequest_t docrequest;
    431   DocumentResponse_t docresponse;
    432   text_t topparent, classifytype, classifytitle;
    433   comerror_t err;
    434 
    435   text_t &arg_d = args["d"];
    436   text_t &arg_cl = args["cl"];
    437   text_t &collection = args["c"];
    438 
    439   text_t OID = arg_d;
    440   if (arg_d.empty()) OID = arg_cl;
    441 
    442   textout << outconvert << disp << "_document:header_\n"
    443       << "_document:content_\n";
    444  
    445   if (arg_d.empty() && arg_cl.empty()) {
    446     textout << outconvert << disp << "Document contains no data_document:footer_\n";
    447     return true;
    448   }
    449 
    450   // get the classifytitle and classifytype
    451   get_top (OID, topparent);
    452   metadata.push_back ("Title");
    453   metadata.push_back ("classifytype");
    454   if (get_info (topparent, collection, metadata, collectproto, response, logout)) {
    455     classifytitle = response.docInfo[0].metadata[0].values[0];
    456     classifytype = response.docInfo[0].metadata[1].values[0];
    457   }
    458 
    459   if (!arg_d.empty()) {
    460    
    461     if (classifytype == "Hierarchy")
    462       output_hierarchy_toc (classifytitle, args, collectproto, disp,
    463                 outconvert, textout, logout);
    464     else
    465       // Book is the default for a document level toc - AZList and Datelist don't
    466       // make sense for document level
    467       output_book_toc (classifytitle, args, collectproto, disp,
    468                outconvert, textout, logout);
    469   } else {
    470    
    471     if (classifytype == "Hierarchy")
    472       output_hierarchy_toc (classifytitle, args, collectproto, disp,
    473                 outconvert, textout, logout);
    474     else if (classifytype == "Datelist")
    475       output_datelist_toc (classifytitle, args, collectproto, disp,
     438                displayclass &disp, outconvertclass &outconvert,
     439                ostream &textout, ostream &logout) {
     440
     441  if (collectproto == NULL) {
     442    logout << "documentaction::do_action called with NULL collectproto\n";
     443    textout << outconvert << disp << "_document:header_\n"
     444        << "Error: Attempt to get document without setting collection\n"
     445        << "_document:footer_\n";
     446  } else { 
     447
     448    text_tarray metadata;
     449    FilterResponse_t response;
     450    FilterResponse_t queryresponse;
     451    DocumentRequest_t docrequest;
     452    DocumentResponse_t docresponse;
     453    text_t topparent, classifytype, classifytitle;
     454    comerror_t err;
     455    bool highlight = false;
     456   
     457    text_t &arg_d = args["d"];
     458    text_t &arg_cl = args["cl"];
     459    text_t &collection = args["c"];
     460   
     461    text_t OID = arg_d;
     462    if (arg_d.empty()) OID = arg_cl;
     463   
     464    textout << outconvert << disp << "_document:header_\n"
     465        << "_document:content_\n";
     466   
     467    if (arg_d.empty() && arg_cl.empty()) {
     468      textout << outconvert << disp << "Document contains no data_document:footer_\n";
     469      return true;
     470    }
     471   
     472    // if we have a query string and highlighting is turned on we need
     473    // to redo the query to get the terms for highlighting
     474    if (!args["q"].empty() && args.getintarg("hl")) {
     475      FilterRequest_t request;
     476      text_t quotedstring; // don't use this here
     477      request.filterResultOptions = FRmatchTerms;
     478      if (do_query (request, args, collectproto, quotedstring, queryresponse, logout))
     479    highlight = true;
     480    }
     481   
     482    // get the classifytitle and classifytype
     483    get_top (OID, topparent);
     484    metadata.push_back ("Title");
     485    metadata.push_back ("classifytype");
     486    if (get_info (topparent, collection, metadata, collectproto, response, logout)) {
     487      classifytitle = response.docInfo[0].metadata[0].values[0];
     488      classifytype = response.docInfo[0].metadata[1].values[0];
     489    }
     490   
     491    if (!arg_d.empty()) {
     492     
     493      if (classifytype == "Hierarchy")
     494    output_hierarchy_toc (classifytitle, args, collectproto, disp,
     495                  outconvert, textout, logout);
     496      else
     497    // Book is the default for a document level toc - AZList and Datelist don't
     498    // make sense for document level
     499    output_book_toc (classifytitle, args, collectproto, disp,
     500             outconvert, textout, logout);
     501    } else {
     502   
     503      if (classifytype == "Hierarchy")
     504    output_hierarchy_toc (classifytitle, args, collectproto, disp,
     505                  outconvert, textout, logout);
     506      else if (classifytype == "Datelist")
     507    output_datelist_toc (classifytitle, args, collectproto, disp,
     508                 outconvert, textout, logout);
     509      else
     510    // AZList is the default for a classification level toc - Book doesn't make
     511    // sense for classification level
     512    output_azlist_toc (classifytitle, args, collectproto, disp,
    476513               outconvert, textout, logout);
    477     else
    478       // AZList is the default for a classification level toc - Book doesn't make
    479       // sense for classification level
    480       output_azlist_toc (classifytitle, args, collectproto, disp,
    481              outconvert, textout, logout);
    482   }
    483 
    484   // get info on this document
    485   metadata.erase (metadata.begin(), metadata.end());
    486   metadata.push_back("Title");
    487   metadata.push_back("hastxt");
    488   metadata.push_back("haschildren");
    489 
    490   if (get_info (OID, collection, metadata, collectproto, response, logout)) {
    491     text_t &title = response.docInfo[0].metadata[0].values[0];
    492     int hastxt = response.docInfo[0].metadata[1].values[0].getint();
    493     int haschildren = response.docInfo[0].metadata[2].values[0].getint();
    494 
    495     int gt = args.getintarg("gt");
    496     if (gt == 0) {
    497       if (hastxt == 1) {
    498     // get the text
    499     docrequest.OID = OID;
    500     collectproto->get_document (collection, docrequest, docresponse, err, logout);
    501    
    502     textout << outconvert << disp
    503         << "<p>\n<h3>" << title << "</h3>" << docresponse.doc;
    504       }
     514    }
     515   
     516    // get info on this document
     517    metadata.erase (metadata.begin(), metadata.end());
     518    metadata.push_back("Title");
     519    metadata.push_back("hastxt");
     520    metadata.push_back("haschildren");
     521   
     522    if (get_info (OID, collection, metadata, collectproto, response, logout)) {
     523      text_t &title = response.docInfo[0].metadata[0].values[0];
     524      int hastxt = response.docInfo[0].metadata[1].values[0].getint();
     525      int haschildren = response.docInfo[0].metadata[2].values[0].getint();
     526     
     527      int gt = args.getintarg("gt");
     528      if (gt == 0) {
     529    if (hastxt == 1) {
     530      // get the text
     531      docrequest.OID = OID;
     532      collectproto->get_document (collection, docrequest, docresponse, err, logout);
     533     
     534      textout << outconvert << disp << "<p>\n<h3>" << title << "</h3>";
     535      if (highlight)
     536        highlighttext(docresponse.doc, queryresponse.termInfo, disp,
     537              outconvert, textout, logout);
     538      else
     539        textout << outconvert << disp << docresponse.doc;
     540    }
     541      } else {
     542   
     543    // text is to be expanded
     544    int tmp; // this doesn't get used here
     545    if (!haschildren)
     546      OID = get_parent (OID);
     547   
     548    get_contents (OID, classifytype, tmp, collection, collectproto, response, logout);
     549   
     550    ResultDocInfo_tarray::const_iterator sechere = response.docInfo.begin();
     551    ResultDocInfo_tarray::const_iterator secend = response.docInfo.end();
     552   
     553    if (gt == 1) {
     554      // check if there are more than 10 sections containing text to be expanded -
     555      // if there are output warning message - this isn't a great way to do this
     556      // since the sections may be very large or very small - one day I'll fix it
     557      // -- Stefan.
     558      int seccount = 0;
     559      while (sechere != secend) {
     560        if ((*sechere).metadata[3].values[0] == "1") seccount ++;
     561        if (seccount > 10) break;
     562        sechere ++;
     563      }
     564      if (seccount > 10) textout << outconvert << disp << "_document:textltwarning_";
     565      else gt = 2;
     566    }
     567
     568    if (gt == 2) {
     569    // get the text for each section
     570      sechere = response.docInfo.begin();
     571      int count = 0;
     572      while (sechere != secend) {
     573        textout << outconvert << disp << "\n<p><a name=" << count << "><h3>"
     574            << (*sechere).metadata[0].values[0] << "</h3></a>\n";
     575        if ((*sechere).metadata[3].values[0] == "1") {
     576          docrequest.OID = (*sechere).OID;
     577          collectproto->get_document (collection, docrequest, docresponse, err, logout);
     578          if (highlight)
     579        highlighttext(docresponse.doc, queryresponse.termInfo, disp,
     580                  outconvert, textout, logout);
     581          else
     582        textout << outconvert << disp << docresponse.doc;
     583        }
     584        count ++;
     585        sechere ++;
     586      }
     587    }
     588      }
     589    }
     590    textout << outconvert << disp << "_document:footer_\n";
     591  }
     592  return true;
     593}
     594
     595
     596// highlighttext highlights query terms in text string and outputs the resulting text string
     597void documentaction::highlighttext(text_t &text, TermInfo_tarray &terms, displayclass &disp,
     598                   outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) {
     599
     600  text_tmap allterms;
     601  text_tmap::const_iterator it;
     602
     603  // first load all the term variations into a map
     604  TermInfo_tarray::const_iterator this_term = terms.begin();
     605  TermInfo_tarray::const_iterator last_term = terms.end();
     606  while (this_term != last_term) {
     607    text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();
     608    text_tarray::const_iterator last_var = (*this_term).matchTerms.end();
     609    while (this_var != last_var) {
     610      allterms[*this_var] = 1;
     611      this_var ++;
     612    }
     613    this_term ++;
     614  }
     615
     616  // get the text to start and end a hightlight
     617  text_t starthighlight = "<b><u>";
     618  text_t endhighlight = "</u></b>";
     619  if (disp.isdefaultmacro("Global", "starthighlight"))
     620    disp.expandstring("Global", "_starthighlight_", starthighlight);
     621  if (disp.isdefaultmacro("Global", "endhighlight"))
     622    disp.expandstring("Global", "_endhighlight_", endhighlight);
     623
     624
     625  text_t::iterator here = text.begin();
     626  text_t::iterator end = text.end();
     627  text_t word, buffer;
     628  while (here != end) {
     629    if (is_unicode_letdig(*here)) {
     630      // not word boundary
     631      word.push_back(*here);
     632      here++;
     633
    505634    } else {
    506 
    507       // text is to be expanded
    508       int tmp; // this doesn't get used here
    509       if (!haschildren)
    510     OID = get_parent (OID);
    511 
    512       get_contents (OID, classifytype, tmp, collection, collectproto, response, logout);
    513          
    514       ResultDocInfo_tarray::const_iterator sechere = response.docInfo.begin();
    515       ResultDocInfo_tarray::const_iterator secend = response.docInfo.end();
    516          
    517       if (gt == 1) {
    518     // check if there are more than 10 sections containing text to be expanded -
    519     // if there are output warning message - this isn't a great way to do this
    520     // since the sections may be very large or very small - one day I'll fix it
    521     // -- Stefan.
    522     int seccount = 0;
    523     while (sechere != secend) {
    524       if ((*sechere).metadata[3].values[0] == "1") seccount ++;
    525       if (seccount > 10) break;
    526       sechere ++;
    527     }
    528     if (seccount > 10) textout << outconvert << disp << "_document:textltwarning_";
    529     else gt = 2;
    530       }
    531 
    532       if (gt == 2) {
    533     // get the text for each section
    534     sechere = response.docInfo.begin();
    535     int count = 0;
    536     while (sechere != secend) {
    537       textout << outconvert << disp << "\n<p><a name=" << count << "><h3>"
    538           << (*sechere).metadata[0].values[0] << "</h3></a>\n";
    539       if ((*sechere).metadata[3].values[0] == "1") {
    540         docrequest.OID = (*sechere).OID;
    541         collectproto->get_document (collection, docrequest, docresponse, err, logout);
    542         textout << outconvert << disp << docresponse.doc;
    543       }
    544       count ++;
    545       sechere ++;
    546     }
    547       }
    548     }
    549   }
    550   textout << outconvert << disp << "_document:footer_\n";
    551   return true;
    552 }
    553 
     635      // found word boundary
     636      // add last word if there was one
     637      if (!word.empty()) {
     638    it = allterms.find(word);
     639    if (it != allterms.end()) {
     640      word = starthighlight + word + endhighlight;
     641    }
     642    buffer += word;
     643        word.clear();
     644      }
     645
     646      if (*here == '<') {
     647        // skip over rest of html tag
     648    while ((here != end) && (*here != '>')) {
     649      buffer.push_back(*here);
     650      here++;
     651    }
     652      }
     653
     654      buffer.push_back(*here);
     655      here++;
     656
     657      if (buffer.size() > 1024) {
     658    textout << outconvert << disp << buffer;
     659    buffer.clear();
     660      }
     661    }
     662  }
     663  textout << outconvert << disp << buffer;
     664}
Note: See TracChangeset for help on using the changeset viewer.