Ticket #235: xapian_omega_make_sortstuff_options.diff

File xapian_omega_make_sortstuff_options.diff, 3.5 KB (added by tv+xapian.org, 17 years ago)

patch as described

  • omega.cc

    diff -urN /semitmp/xapian/svn/xapian/xapian-applications/omega/omega.cc ./omega.cc
    old new  
    6868// percentage cut-off
    6969int threshold = 0;
    7070
    71 bool sort_numeric = false;
    72 Xapian::valueno sort_key = Xapian::BAD_VALUENO; // Don't sort.
    73 bool sort_ascending = true;
    74 bool sort_after = false;
    7571Xapian::Enquire::docid_order docid_order = Xapian::Enquire::ASCENDING;
    7672
    7773Xapian::valueno collapse_key = 0;
     
    9490    // set default thousands and decimal separators: e.g. "16,729 hits" "1.4K"
    9591    option["decimal"] = ".";
    9692    option["thousand"] = ",";
    97    
     93    option["sort_numeric"] = "false";
     94    option["sort_ascending"] = "true";
     95    option["sort_after"] = "false";
     96    option["sort_key"] = ""; // don't sort
     97
    9898    // set the default stemming language
    9999    option["stemmer"] = DEFAULT_STEM_LANGUAGE;
    100100
     
    317317        const string & v = val->second;
    318318        if (v[0] == '#') {
    319319            // FIXME not supported currently!
    320             sort_numeric = true;
    321             sort_key = atoi(v.c_str() + 1);
     320            option["sort_numeric"] = "true";
     321            option["sort_key"] = v.substr(1);
    322322        } else {
    323             sort_key = atoi(v.c_str());
     323            option["sort_key"] = v;
    324324        }
    325325        val = cgi_params.find("SORTREVERSE");
    326326        if (val != cgi_params.end()) {
    327             sort_ascending = (atoi(val->second.c_str()) == 0);
     327            if (atoi(val->second.c_str()) != 0)
     328                option["sort_ascending"] = "false";
    328329        }
    329330        val = cgi_params.find("SORTAFTER");
    330331        if (val != cgi_params.end()) {
    331             sort_after = (atoi(val->second.c_str()) != 0);
     332            if (atoi(val->second.c_str()) != 0)
     333                option["sort_after"] = "true";
    332334        }
    333335        // Add the sorting related options to filters too.
    334         filters += int_to_string(sort_key);
    335         if (sort_after) {
    336             if (sort_ascending) {
     336        filters += option["sort_key"];
     337        if (option["sort_after"] == "true") {
     338            if (option["sort_ascending"] == "true") {
    337339                filters += 'F';
    338340            } else {
    339341                filters += 'R';
    340342            }
    341343        } else {
    342             if (!sort_ascending) {
     344            if (option["sort_ascending"] == "false") {
    343345                filters += 'r';
    344346            }
    345347        }
  • omega.h

    diff -urN /semitmp/xapian/svn/xapian/xapian-applications/omega/omega.h ./omega.h
    old new  
    5656
    5757extern int threshold;
    5858
    59 extern bool sort_numeric;
    60 extern Xapian::valueno sort_key;
    61 extern bool sort_ascending;
    62 extern bool sort_after;
    6359extern Xapian::Enquire::docid_order docid_order;
    6460
    6561extern Xapian::valueno collapse_key;
  • query.cc

    diff -urN /semitmp/xapian/svn/xapian/xapian-applications/omega/query.cc ./query.cc
    old new  
    375375
    376376    enquire->set_cutoff(threshold);
    377377
    378     if (sort_key != Xapian::BAD_VALUENO) {
    379         if (sort_after) {
    380             enquire->set_sort_by_relevance_then_value(sort_key, sort_ascending);
     378    if (! option["sort_key"].empty()) {
     379        if (option["sort_after"] == "true") {
     380            enquire->set_sort_by_relevance_then_value(string_to_int(option["sort_key"]), option["sort_ascending"]=="true");
    381381        } else {
    382             enquire->set_sort_by_value_then_relevance(sort_key, sort_ascending);
     382            enquire->set_sort_by_value_then_relevance((string_to_int(option["sort_key"]), option["sort_ascending"]=="true");
    383383        }
    384384    }
    385385