- Timestamp:
- 2013-03-12T14:37:44+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp
r22050 r27064 28 28 #include "lucenesearch.h" 29 29 30 /////////////////////////////////31 // functions for queryfilterclass32 /////////////////////////////////33 34 35 30 lucenequeryfilterclass::lucenequeryfilterclass () 36 : queryfilterclass() {31 : fieldedqueryfilterclass() { 37 32 38 33 39 34 FilterOption_t filtopt; 40 35 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 43 37 filtopt.clear(); 44 filtopt.name = " Level";38 filtopt.name = "SortField"; 45 39 filtopt.type = FilterOption_t::enumeratedt; 46 filtopt.repeatable = FilterOption_t::onePer Term;40 filtopt.repeatable = FilterOption_t::onePerQuery; 47 41 filtopt.defaultValue = ""; 48 filterOptions[" Level"] = filtopt;49 50 // -- IndexField, enumerated, used to list available fields42 filterOptions["SortField"] = filtopt; 43 44 // -- onePerQuery SortOder enumerated (0=ascending, 1=descending) 51 45 filtopt.clear(); 52 filtopt.name = " IndexField";46 filtopt.name = "SortOrder"; 53 47 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; 55 59 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; 58 69 } 59 70 … … 62 73 63 74 64 //whether a query is a full text browse65 bool lucenequeryfilterclass::full_text_browse (int filterRequestOptions) {66 return (filterRequestOptions & FRfullTextBrowse);67 }68 75 69 76 void 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 } 98 82 } 99 83 100 84 bool lucenequeryfilterclass::init (ostream &logout) { 101 85 102 if (! queryfilterclass::init(logout)) {86 if (!fieldedqueryfilterclass::init(logout)) { 103 87 return false; 104 88 } 105 89 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 } 120 98 return true; 121 99 } 100 101 void 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 122 111 123 112 void lucenequeryfilterclass::filter(const FilterRequest_t &request, … … 160 149 // get the query parameters 161 150 int startresults, endresults; 162 text_t phrasematch; // not used here any more163 151 vector<queryparamclass> queryfilterparams; 164 152 parse_query_params (request, queryfilterparams, startresults, 165 endresults, phrasematch,logout);153 endresults, logout); 166 154 167 155 … … 258 246 // get the query parameters 259 247 int startresults, endresults; 260 text_t phrasematch; // not used here any more, just have it so can use261 // parse_query_params function262 248 263 249 vector<queryparamclass> queryfilterparams; 264 250 parse_query_params (request, queryfilterparams, startresults, 265 endresults, phrasematch,logout);251 endresults, logout); 266 252 267 253 vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin(); … … 392 378 393 379 394
Note:
See TracChangeset
for help on using the changeset viewer.