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

Introduction of code for elementary use of lucene indexer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.