Changeset 8029


Ignore:
Timestamp:
2004-08-23T23:24:20+12:00 (20 years ago)
Author:
davidb
Message:

Introduction of code for elementary use of lucene indexer.

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

Legend:

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

    r7594 r8029  
    6363  argsinfo.addarginfo (NULL, arg_ainfo);
    6464 
    65    // "ct" - 0 = mg, 1 = mgpp
     65   // "ct" - 0 = mg, 1 = mgpp, 2=lucene
    6666  arg_ainfo.shortname = "ct";
    6767  arg_ainfo.longname = "collection type";
     
    506506  // check ct argument
    507507  int arg_ct = args.getintarg("ct");
    508   if (arg_ct !=0 && arg_ct !=1) {
     508  if (arg_ct <0 && arg_ct >2) {
    509509    logout << "Warning: \"ct\" argument out of range (" << arg_ct << ")\n";
    510510    cgiarginfo *ctinfo = argsinfo.getarginfo ("ct");
     
    708708    if (it != end) set_option_macro ("cq2", args["cq2"], true,false, (*it).second, disp);
    709709
    710     if (args["ct"] == "1") { // mgpp collections
     710    if ((args["ct"] == "1") || (args["ct"] == "2"))  { // mgpp/lucene collections
    711711      // _gselection_ (Level)
    712712      it = response.filterOptions.find("Level");
     
    789789  // _advformlist_
    790790
    791   if (args["ct"]=="0" || args["qto"]=="1" || (args["qto"]=="3" && args["qt"] == "0") ) // mg, or mgpp with plain only, or mgpp with both, but set to plain
     791  if (args["ct"]=="0" || args["qto"]=="1" || (args["qto"]=="3" && args["qt"] == "0") ) // mg, or mgpp/lucene with plain only, or mgpp with both, but set to plain
    792792    return; // dont need these macros
    793793
    794     // mgpp & form query only needs the macros defined
     794  // mgpp & form query only needs the macros defined
    795795  text_t form = "";
    796796  int argfqn = args.getintarg("fqn");
     
    13981398    format_querystring (formattedstring, args.getintarg("b"), segment);
    13991399    if (args["ct"]=="1") { // mgpp - we need to add in the field info
    1400       format_field_info(formattedstring, args["fqf"]);
    1401     }
     1400      mgpp_format_field_info(formattedstring, args["fqf"]);
     1401    }
     1402    else if (args["ct"]=="2") { // lucene - we need to add in the field info
     1403      lucene_format_field_info(formattedstring, args["fqf"]);
     1404    }
     1405
    14021406    add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
    1403           args.getintarg("dsbc"), args.getintarg("debc"));
     1407          args.getintarg("dsbc"), args.getintarg("debc"),
     1408          args.getintarg("ct"));
    14041409    args["q"] = formattedstring;
    14051410  }
  • trunk/gsdl/src/recpt/querytools.cpp

    r7432 r8029  
    198198   
    199199void add_dates(text_t &querystring, int startdate, int enddate,
    200            int startbc, int endbc)
     200           int startbc, int endbc, int ct)
    201201{
    202202  if(startdate)
     
    232232       if(!enddate)
    233233     {
    234        querystring.appendcstr(" [");
    235        if(startdate<0)
    236          {
    237            querystring.appendcstr("bc");
    238            querystring.appendint((startdate*-1));
    239          }
    240        else
    241          querystring.appendint(startdate);
    242        querystring.appendcstr("]:CV");
     234       if (ct==1) {
     235         mgpp_adddateelem(querystring,startdate);
     236       }
     237       else { // lucene
     238         lucene_adddateelem(querystring,startdate);
     239       }
    243240     }
    244241       else{
     
    247244     while(nextdate<=enddate)
    248245       {
    249          if(nextdate!=0)
    250            {
    251          querystring.appendcstr(" [");
    252          if(nextdate<0)
    253            {
    254              querystring.appendcstr("bc");
    255              querystring.appendint((nextdate*-1));
    256            }
    257          else
    258            querystring.appendint(nextdate);
    259          querystring.appendcstr("]:CV");
     246         if(nextdate!=0) {
     247           if (ct==1) {
     248         mgpp_adddateelem(querystring,nextdate);
    260249           }
     250           else { // lucene
     251         lucene_adddateelem(querystring,nextdate);
     252           }
     253         }
    261254         nextdate++;
    262255       }
     
    320313// some query form parsing functions for use with mgpp
    321314
    322 void parse_reg_query_form(text_t &querystring, cgiargsclass &args){
    323 
     315void parse_reg_query_form(text_t &querystring, cgiargsclass &args)
     316{
    324317  querystring.clear();
     318
     319  const int ct = args.getintarg("ct");
     320  int argt = args.getintarg("t");// t=0 -and, t=1 - or
     321
    325322  text_t combine;
    326   int argt = args.getintarg("t");// t=0 -and, t=1 - or
    327   if (argt == 0) combine = "&";
    328   else combine = "|";
     323  if (ct==1) {
     324    if (argt == 0) combine = "&";
     325    else combine = "|";
     326  }
     327  else { // lucene
     328    if (argt == 0) combine = "AND";
     329    else combine = "OR";
     330  }
    329331 
    330332  text_t field = args["fqf"];
     
    338340  splitchar(value.begin(), value.end(), ',', values);
    339341
     342
    340343  for (int i=0; i< values.size(); i++) {
    341344    if (!values[i].empty()) {
    342       addqueryelem(querystring, fields[i], values[i], combine);
     345      if (ct == 1) {
     346    mgpp_addqueryelem(querystring, fields[i], values[i], combine);
     347      }
     348      else { // lucene
     349    lucene_addqueryelem(querystring, fields[i], values[i], combine);
     350      }
    343351    }
    344352  }
     
    350358
    351359  querystring.clear();
    352   text_t combine = "&";
     360
     361  const int ct = args.getintarg("ct");
     362  text_t combine;
     363  if (ct==1) {
     364    combine = "&";
     365  }
     366  else { // lucene
     367    combine = "AND";
     368  }
    353369
    354370  text_t field = args["fqf"];
     
    380396    if (!values[i].empty()) {
    381397      if (i!=0) {
    382     if (combs[i-1]=="and") combine = "&";
    383     else if (combs[i-1]=="or")combine = "|";
    384     else if (combs[i-1]=="not")combine = "!";
     398    if (ct==1) {
     399      if (combs[i-1]=="and") combine = "&";
     400      else if (combs[i-1]=="or")combine = "|";
     401      else if (combs[i-1]=="not")combine = "!";
     402    }
     403    else { // lucene
     404      if (combs[i-1]=="and") combine = "AND";
     405      else if (combs[i-1]=="or")combine = "OR";
     406      else if (combs[i-1]=="not")combine = "NOT";
     407    }
    385408      }
    386409      text_t term = addstemcase(values[i], stems[i], folds[i]);
    387       addqueryelem(querystring, fields[i], term, combine);
     410      mgpp_addqueryelem(querystring, fields[i], term, combine);
    388411    }
    389412   
     
    446469
    447470
    448 void addqueryelem(text_t &querystring, text_t &tag,
     471void mgpp_adddateelem(text_t& querystring, const int date)
     472{
     473  querystring.appendcstr(" [");
     474  if(date<0) {
     475      querystring.appendcstr("bc");
     476      querystring.appendint((date*-1));
     477  }
     478  else {
     479    querystring.appendint(date);
     480  }
     481  querystring.appendcstr("]:CV");
     482}
     483
     484void lucene_adddateelem(text_t& querystring, const int date)
     485{
     486  querystring.appendcstr(" CV:(");
     487  if(date<0) {
     488      querystring.appendcstr("bc");
     489      querystring.appendint((date*-1));
     490  }
     491  else {
     492    querystring.appendint(date);
     493  }
     494  querystring.appendcstr(")");
     495}
     496
     497
     498void mgpp_addqueryelem(text_t &querystring, text_t &tag,
    449499          text_t &query, text_t &combine) {
    450500  if (!querystring.empty()) { // have to put and/or
    451     querystring += " "+combine + " ";
     501    querystring += " " + combine + " ";
    452502 
    453503  }
     
    459509  }
    460510
     511}
     512
     513void lucene_addqueryelem(text_t &querystring, text_t &tag,
     514          text_t &query, text_t &combine) {
     515  if (!querystring.empty()) { // have to put and/or
     516    querystring += " " + combine + " ";
     517 
     518  }
     519  if (tag=="ZZ" || tag=="") { // just add onto querystring
     520       querystring +=  query;
     521  }
     522  else {
     523    querystring += tag+":("+query+")";
     524  }
    461525}
    462526
     
    544608
    545609
    546 void format_field_info(text_t & querystring, const text_t &tag) {
     610void mgpp_format_field_info(text_t & querystring, const text_t &tag) {
    547611
    548612  if (tag == "ZZ" || tag == "") {
     
    552616  querystring = "["+querystring+"]:"+tag;
    553617}
     618
     619void lucene_format_field_info(text_t & querystring, const text_t &tag) {
     620
     621  if (tag == "ZZ" || tag == "") {
     622    return; // do nothing
     623  }
     624
     625  querystring = tag+":("+querystring+")";
     626}
  • trunk/gsdl/src/recpt/querytools.h

    r7383 r8029  
    4343
    4444void add_dates(text_t &querystring, int startdate, int enddate,
    45            int startbc, int endbc);
     45           int startbc, int endbc, int ct);
    4646
    4747void get_phrases (const text_t &querystring, text_tarray &phrases);
     
    5656void parse_adv_query_form(text_t &formattedstring, cgiargsclass &args);
    5757
    58 void addqueryelem(text_t &querystring, text_t &tag,
     58void mgpp_adddateelem(text_t& querystring, const int date);
     59void lucene_adddateelem(text_t& querystring, const int date);
     60
     61void mgpp_addqueryelem(text_t &querystring, text_t &tag,
     62          text_t &query, text_t &combine);
     63void lucene_addqueryelem(text_t &querystring, text_t &tag,
    5964          text_t &query, text_t &combine);
    6065void addqueryelem_ex(text_t &querystring, const text_t &tag,
     
    6368text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold);
    6469text_t formatelem(text_t &text);
    65 void format_field_info(text_t &querystring, const text_t &tag);
     70void mgpp_format_field_info(text_t &querystring, const text_t &tag);
     71void lucene_format_field_info(text_t &querystring, const text_t &tag);
    6672
    6773#endif
Note: See TracChangeset for help on using the changeset viewer.