Changeset 11987


Ignore:
Timestamp:
2006-06-30T16:05:50+12:00 (18 years ago)
Author:
kjdon
Message:

added a new method set_query_type_args, which sets ct, qt and qto args. Also made addstemcase allow special characters in words - it was removing * from query terms

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

Legend:

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

    r11765 r11987  
    2828#include "unitool.h" // for is_unicode_letdig
    2929
     30void set_query_type_args(ColInfoResponse_t *cinfo, cgiargsclass &args) {
     31
     32  if (args["ct"].empty()) {
     33    text_t build_type = cinfo->buildType;
     34    if (build_type == "mgpp") {
     35      args["ct"] = "1";
     36    } else if (build_type == "lucene") {
     37      args["ct"] = "2";
     38    } else {
     39      args["ct"] = "0";
     40    }
     41  }
     42  text_t arg_ct = args["ct"];
     43  if (arg_ct == "0") {
     44    // mg
     45    args["qt"] = "0";
     46    args["qto"] = "0";
     47    return;
     48  }
     49
     50  if (!args["qt"].empty() && !args["qto"].empty()) {
     51    return;
     52  }
     53 
     54  text_tmap::iterator check = cinfo->format.find("SearchTypes");
     55  text_t search_types = "plain,form";
     56  if(check != cinfo->format.end()){
     57    search_types = (*check).second;
     58    if (search_types.empty()) {
     59      search_types = "plain,form";
     60    }
     61  }
     62 
     63  if (args["qto"].empty()) {
     64    unsigned int type = 0;
     65    if (findword(search_types.begin(), search_types.end(), "form") != search_types.end()) {
     66      type |= 2;
     67    }
     68    if (findword(search_types.begin(), search_types.end(), "plain") != search_types.end()) {
     69      type |= 1;
     70    }
     71    args.setintarg("qto", type);
     72  }
     73 
     74  if (args["qt"].empty()) {
     75    bool form_default = false;
     76    int arg_qto = args.getintarg("qto");
     77    if (arg_qto == 2 || (arg_qto == 3 && starts_with(search_types, "form"))) {
     78      args["qt"] = "1";
     79    } else {
     80      args["qt"] = "0";
     81    }
     82  }
     83}
     84
    3085// request.filterResultOptions and request.fields (if required) should
    3186// be set from the calling code
     
    157212  //  option.value = endresults;
    158213  //  request.filterOptions.push_back (option);
     214}
     215
     216bool is_special_character(int indexer_type, unsigned short character) {
     217  // mgpp
     218  if (indexer_type == 1) {
     219    return (character == '#' || character == '/' || character == '*');
     220  }
     221  // lucene
     222  else if (indexer_type ==2) {
     223    return (character == '?' || character == '*' || character == '~' ||
     224        character == '^');
     225  }
     226  return false;
    159227}
    160228
     
    386454    }
    387455      }
    388       text_t term = addstemcase(values[i], stems[i], folds[i]);
     456      text_t term = addstemcase(values[i], stems[i], folds[i], ct);
    389457      mgpp_addqueryelem(querystring, fields[i], term, combine);
    390458    }
     
    393461}
    394462
    395 text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold) {
     463text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold,
     464           const int indexer_type) {
    396465 
    397466  text_t outtext;
     
    403472  while (here !=end) {
    404473
    405     if (is_unicode_letdig(*here)) {
     474    if (is_unicode_letdig(*here) || is_special_character(indexer_type, *here)) {
    406475      // not word boundary
    407476      word.push_back(*here);
     
    598667}
    599668
    600 bool is_special_character(int indexer_type, unsigned short character) {
    601   // mgpp
    602   if (indexer_type == 1) {
    603     return (character == '#' || character == '/' || character == '*');
    604   }
    605   // lucene
    606   else if (indexer_type ==2) {
    607     return (character == '?' || character == '*' || character == '~' ||
    608         character == '^');
    609   }
    610   return false;
    611 }
    612669
    613670void format_field_info_lucene(text_t &querystring, cgiargsclass &args) {
     
    691748
    692749void format_field_info_mgpp(text_t &querystring, cgiargsclass &args) {
    693  
    694750  text_t tag = args["fqf"];
    695751  if (tag == "ZZ") tag = ""; // ZZ is a special tag meaning no tag (all fields)
  • trunk/gsdl/src/recpt/querytools.h

    r11004 r11987  
    3030#include "cgiargs.h"
    3131#include "recptproto.h"
     32
     33void set_query_type_args(ColInfoResponse_t *cinfo, cgiargsclass &args);
    3234
    3335void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring,
     
    6466             const text_t &terms, const text_t &stem, const text_t &fold,
    6567             const text_t& combine, const text_t& word_combine);
    66 text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold);
     68text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold,
     69           const int indexer_type);
    6770text_t formatelem(text_t &text);
    6871void format_field_info(text_t &querystring, cgiargsclass &args);
Note: See TracChangeset for help on using the changeset viewer.