Ignore:
Timestamp:
2013-03-12T14:37:44+13:00 (11 years ago)
Author:
kjdon
Message:

adding reverse sort/sort order in for lucene search results sorting. reorganising code to avoid duplication, added fieldedqueryfilter in the chain of inheritance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp

    r22050 r27064  
    2828#include "lucenesearch.h"
    2929
    30 /////////////////////////////////
    31 // functions for queryfilterclass
    32 /////////////////////////////////
    33 
    34 
    3530lucenequeryfilterclass::lucenequeryfilterclass ()
    36   : queryfilterclass() {
     31  : fieldedqueryfilterclass() {
    3732
    3833 
    3934  FilterOption_t filtopt;
    4035 
    41   // -- onePerTerm  Level          enumerated
    42   // likely to be Doc, Sec, Para, but we dont assume anything now
     36  // -- onePerQuery SortField, enumerated, used to list available sorting fields
    4337  filtopt.clear();
    44   filtopt.name = "Level";
     38  filtopt.name = "SortField";
    4539  filtopt.type = FilterOption_t::enumeratedt;
    46   filtopt.repeatable = FilterOption_t::onePerTerm;
     40  filtopt.repeatable = FilterOption_t::onePerQuery;
    4741  filtopt.defaultValue = "";
    48   filterOptions["Level"] = filtopt;
    49 
    50   // --  IndexField, enumerated, used to list available fields
     42  filterOptions["SortField"] = filtopt;
     43
     44  // -- onePerQuery SortOder      enumerated (0=ascending, 1=descending)
    5145  filtopt.clear();
    52   filtopt.name = "IndexField";
     46  filtopt.name = "SortOrder";
    5347  filtopt.type = FilterOption_t::enumeratedt;
    54   filtopt.repeatable = FilterOption_t::onePerTerm;
     48  filtopt.repeatable = FilterOption_t::onePerQuery;
     49  filtopt.defaultValue = "ascending";
     50  filtopt.validValues.push_back("ascending");
     51  filtopt.validValues.push_back("descending");
     52  filterOptions["SortOrder"] = filtopt;
     53
     54  // -- onePerQuery Fuzziness string 0.0-1.0
     55  filtopt.clear();
     56  filtopt.name = "Fuzziness";
     57  filtopt.type = FilterOption_t::stringt;
     58  filtopt.repeatable = FilterOption_t::onePerQuery;
    5559  filtopt.defaultValue = "";
    56   filterOptions["IndexField"] = filtopt;
    57 
     60  filterOptions["Fuzziness"] = filtopt;
     61
     62 // -- onePerQuery FilterString  string
     63  filtopt.clear();
     64  filtopt.name = "FilterString";
     65  filtopt.type = FilterOption_t::stringt;
     66  filtopt.repeatable = FilterOption_t::onePerQuery;
     67  filtopt.defaultValue = "";
     68  filterOptions["FilterString"] = filtopt;
    5869}
    5970
     
    6273
    6374
    64 //whether a query is a full text browse
    65 bool lucenequeryfilterclass::full_text_browse (int filterRequestOptions) {
    66   return (filterRequestOptions & FRfullTextBrowse);
    67 }
    6875
    6976void lucenequeryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
    70   queryfilterclass::configure(key, cfgline);
    71 
    72   if (key == "indexfieldmap") {
    73     indexfieldmap.importmap (cfgline);
    74    
    75     // update the list of indexes in the filter information
    76     text_tarray options;
    77     indexfieldmap.gettoarray (options);
    78     filterOptions["IndexField"].validValues = options;
    79   } else if (key == "levelmap") {
    80     levelmap.importmap (cfgline);
    81   } else if (key == "indexlevels") {
    82     text_tarray::const_iterator here = cfgline.begin();
    83     text_tarray::const_iterator end = cfgline.end();
    84     while (here != end) {
    85       if (!(*here).empty()) {
    86     filterOptions["Level"].validValues.push_back(*here);
    87       }
    88       ++here;
    89     }
    90   } else if (key == "textlevel") {
    91       ((lucenesearchclass *)textsearchptr)->set_text_level(cfgline[0]);
    92   } else if (key == "defaultindex") {
    93     indexfieldmap.from2to (cfgline[0], filterOptions["IndexField"].defaultValue);
    94   } else if (key == "defaultlevel") {
    95     levelmap.from2to (cfgline[0], filterOptions["Level"].defaultValue);
    96   }
    97  
     77  fieldedqueryfilterclass::configure(key, cfgline);
     78
     79  if (key == "textlevel") {
     80    ((lucenesearchclass *)textsearchptr)->set_text_level(cfgline[0]);
     81  }
    9882}
    9983
    10084bool lucenequeryfilterclass::init (ostream &logout) {
    10185 
    102   if (!queryfilterclass::init(logout)) {
     86  if (!fieldedqueryfilterclass::init(logout)) {
    10387    return false;
    10488  }
    10589 
    106   if (filterOptions["IndexField"].defaultValue.empty()) {
    107     // use first index in map as default if no default is set explicitly
    108     text_tarray fromarray;
    109     indexfieldmap.getfromarray(fromarray);
    110     if (fromarray.size()) {
    111       filterOptions["IndexField"].defaultValue = fromarray[0];
    112     }
    113   }
    114   if (filterOptions["Levels"].defaultValue.empty()) {
    115     // use first level as default if no default is set explicitly
    116     if (!filterOptions["Level"].validValues[0].empty())
    117       filterOptions["Levels"].defaultValue = filterOptions["Level"].validValues[0];
    118   }
    119 
     90  text_tarray field_array;
     91  indexfieldmap.gettoarray(field_array);
     92  for (int i=0; i<field_array.size(); i++) {
     93    text_t field = field_array[i];
     94    if (field!="ZZ" && field !="ZZ") {
     95      filterOptions["SortField"].validValues.push_back("by"+field);
     96    }
     97  }
    12098  return true;
    12199}
     100
     101void lucenequeryfilterclass::set_queryparam_defaults(queryparamclass &query ) {
     102
     103  fieldedqueryfilterclass::set_queryparam_defaults(query);
     104  query.filterstring = filterOptions["FilterString"].defaultValue; 
     105  query.sortfield = filterOptions["SortField"].defaultValue;
     106  query.sortorder = (filterOptions["SortOrder"].defaultValue == "descending");
     107  query.fuzziness = filterOptions["Fuzziness"].defaultValue; 
     108
     109}
     110
    122111
    123112void lucenequeryfilterclass::filter(const FilterRequest_t &request,
     
    160149  // get the query parameters
    161150  int startresults, endresults;
    162   text_t phrasematch; // not used here any more
    163151  vector<queryparamclass> queryfilterparams;
    164152  parse_query_params (request, queryfilterparams, startresults,
    165               endresults, phrasematch, logout); 
     153              endresults, logout); 
    166154 
    167155   
     
    258246  // get the query parameters
    259247  int startresults, endresults;
    260   text_t phrasematch; // not used here any more, just have it so can use
    261                       // parse_query_params function
    262248 
    263249  vector<queryparamclass> queryfilterparams;
    264250  parse_query_params (request, queryfilterparams, startresults,
    265               endresults, phrasematch, logout); 
     251              endresults, logout); 
    266252
    267253  vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
     
    392378
    393379
    394 
Note: See TracChangeset for help on using the changeset viewer.