Changeset 1914


Ignore:
Timestamp:
2001-02-07T12:11:44+13:00 (23 years ago)
Author:
kjm18
Message:

new functions added for search history and form queries (mgpp)

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

Legend:

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

    r1889 r1914  
    2626#include "querytools.h"
    2727#include <ctype.h>
     28#include "unitool.h" // for is_unicode_letdig
    2829
    2930// request.filterResultOptions and request.fields (if required) should
     
    288289  }
    289290}
     291
     292// search history tool
     293text_t escape_quotes(const text_t &querystring) {
     294
     295  text_t::const_iterator here = querystring.begin();
     296  text_t::const_iterator end = querystring.end();
     297 
     298  text_t escquery = "";
     299  while (here != end) {
     300    if (*here != '\'' && *here != '\"') escquery.push_back(*here);
     301    else {
     302      escquery +="\\\\";
     303      escquery.push_back(*here);
     304    }
     305
     306    here++;
     307  }
     308  return escquery;
     309
     310}
     311
     312// some query form parsing functions for use with mgpp
     313
     314void parse_reg_query_form(text_t &querystring, cgiargsclass &args){
     315
     316  querystring.clear();
     317  text_t combine;
     318  int argt = args.getintarg("t");// t=0 -and, t=1 - or
     319  if (argt == 0) combine = "&";
     320  else combine = "|";
     321 
     322  text_t field = args["fqf"];
     323  if (field.empty()) return; // no query
     324  text_tarray fields;
     325  splitchar(field.begin(), field.end(), ',', fields);
     326 
     327  text_t value = args["fqv"];
     328  if (value.empty()) return; // somethings wrong
     329  text_tarray values;
     330  splitchar(value.begin(), value.end(), ',', values);
     331
     332  for (int i=0; i< values.size(); i++) {
     333    if (!values[i].empty()) {
     334      text_t text = formatelem(values[i]);
     335      addqueryelem(querystring, fields[i], values[i], combine);
     336    }
     337  }
     338 
     339}
     340
     341text_t formatelem(text_t &text) {
     342
     343  text_t::iterator here = text.begin();
     344  text_t::iterator end = text.end();
     345
     346  bool space = false;
     347  text_t newtext = "";
     348  while (here != end) {
     349    if (is_unicode_letdig(*here)) {
     350      newtext.push_back(*here);
     351      space = true;
     352    }
     353    else {
     354      if (space) {
     355    newtext.push_back(' ');
     356    space = false;
     357      }
     358    }
     359    here++;
     360  }
     361
     362  return newtext;
     363}
     364
     365void parse_adv_query_form(text_t &querystring, cgiargsclass &args){
     366
     367  querystring.clear();
     368  text_t combine = "&";
     369
     370  text_t field = args["fqf"];
     371  if (field.empty()) return; // no query
     372  text_tarray fields;
     373  splitchar(field.begin(), field.end(), ',', fields);
     374 
     375  text_t value = args["fqv"];
     376  if (value.empty()) return; // somethings wrong
     377  text_tarray values;
     378  splitchar(value.begin(), value.end(), ',', values);
     379
     380  text_t stem = args["fqs"];
     381  if (stem.empty()) return; // somethings wrong
     382  text_tarray stems;
     383  splitchar(stem.begin(), stem.end(), ',', stems);
     384
     385  text_t fold = args["fqk"];
     386  if (fold.empty()) return; // somethings wrong
     387  text_tarray folds;
     388  splitchar(fold.begin(), fold.end(), ',', folds);
     389
     390  text_t comb = args["fqc"];
     391  if (comb.empty()) return; //somethings wrong
     392  text_tarray combs;
     393  splitchar(comb.begin(), comb.end(), ',', combs);
     394 
     395  for(int i=0; i< values.size(); i++) {
     396    if (!values[i].empty()) {
     397      if (i!=0) {
     398    if (combs[i-1]=="and") combine = "&";
     399    else if (combs[i-1]=="or")combine = "|";
     400    else if (combs[i-1]=="not")combine = "!";
     401      }
     402      text_t term = values[i];
     403      term = addstemcase(term, stems[i], folds[i]);
     404      addqueryelem(querystring, fields[i], term, combine);
     405    }
     406   
     407  }
     408}
     409
     410text_t addstemcase(text_t &terms, text_t &stem, text_t &fold) {
     411 
     412  text_t outtext;
     413  text_t word;
     414  //unsigned short c;                                                           
     415  text_t::iterator here = terms.begin();
     416  text_t::iterator end = terms.end();
     417
     418  while (here !=end) {
     419    if (is_unicode_letdig(*here)) {
     420      // not word boundary
     421      word.push_back(*here);
     422      here++;   
     423    }
     424    else {
     425      // found word boundary   
     426      if (!word.empty() ) {
     427    if (stem == "1" || fold =="1") {
     428      word += "#";
     429      if (stem == "1") word += "s";
     430      //else word += "u";
     431     
     432      if (fold == "1") word += "i";
     433      //else word += "c";
     434    }
     435    word += " ";
     436    outtext += word;
     437    word.clear();
     438      }
     439      //outtext.push_back(*here);
     440      here++;
     441    }
     442  }
     443   
     444  // get last word
     445  if (!word.empty()) {
     446    if (stem == "1"|| fold == "1") {
     447      word += "#";
     448      if (stem == "1") word += "s";
     449      //else word += "u";
     450     
     451      if (fold == "1") word += "i";
     452      //else word += "c";
     453    }
     454    word += " ";
     455    outtext += word;
     456  }
     457  return outtext;
     458}
     459
     460
     461
     462void addqueryelem(text_t &querystring, text_t &tag,
     463                  text_t &query, text_t combine) {
     464  if (!querystring.empty()) { // have to put and/or
     465    querystring += " "+combine + " ";
     466 
     467  }
     468  if (tag=="ZZ") { // just add onto querystring
     469       querystring +=  query;
     470  }
     471  else {
     472    querystring += "["+query+"]:"+tag;
     473  }
     474
     475}
     476
     477
     478
  • trunk/gsdl/src/recpt/querytools.h

    r1373 r1914  
    3737                  const text_t &querystring2, cgiargsclass &args);
    3838
    39 // don't hastle the function name ... it's been a long day ;)
     39// don't hassle the function name ... it's been a long day ;)
    4040void set_more_queryfilter_options (FilterRequest_t &request, cgiargsclass &args);
    4141
     
    4949void add_ands(text_t& querystring, int querytype);
    5050
     51// search history tool
     52text_t escape_quotes(const text_t &querystring);
     53
     54// some query parsing functions for form processing (only for mgpp collections)
     55void parse_reg_query_form(text_t &formattedstring, cgiargsclass &args);
     56void parse_adv_query_form(text_t &formattedstring, cgiargsclass &args);
     57
     58void addqueryelem(text_t &querystring, text_t &tag,
     59          text_t &query, text_t combine);
     60text_t addstemcase(text_t &terms, text_t &stem, text_t &fold);
     61text_t formatelem(text_t &text);
     62
    5163#endif
    5264
Note: See TracChangeset for help on using the changeset viewer.