Changeset 351 for trunk/gsdl/src/colservr/queryinfo.cpp
- Timestamp:
- 1999-07-07T18:19:47+12:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/colservr/queryinfo.cpp
r334 r351 12 12 /* 13 13 $Log$ 14 Revision 1.7 1999/07/07 06:19:47 rjmcnab 15 Added ability to combine two or more independant queries. 16 14 17 Revision 1.6 1999/07/01 09:29:21 rjmcnab 15 18 Changes for better reporting of number documents which match a query. Changes … … 44 47 // query parameters 45 48 46 queryparamclass &queryparamclass::operator=(const queryparamclass &q) 47 { 49 queryparamclass::queryparamclass () { 50 clear (); 51 } 52 53 void queryparamclass::clear () { 54 combinequery.clear(); 55 collection.clear(); 56 index.clear(); 57 subcollection.clear(); 58 language.clear(); 59 querystring.clear(); 60 search_type = 0; // 0 = boolean, 1 = ranked 61 casefolding = 0; 62 stemming = 0; 63 maxdocs = -1; // all 64 } 65 66 67 queryparamclass &queryparamclass::operator=(const queryparamclass &q) { 68 combinequery = q.combinequery; 48 69 collection = q.collection; 49 search_index = q.search_index; 70 index = q.index; 71 subcollection = q.subcollection; 72 language = q.language; 50 73 querystring = q.querystring; 51 74 search_type = q.search_type; … … 58 81 59 82 60 bool operator==(const queryparamclass &x, const queryparamclass &y) 61 { 62 return ((x.collection == y.collection) && 63 (x.search_index == y.search_index) && 83 bool operator==(const queryparamclass &x, const queryparamclass &y) { 84 return ((x.combinequery == y.combinequery) && 85 (x.collection == y.collection) && 86 (x.index == y.index) && 87 (x.subcollection == y.subcollection) && 88 (x.language == y.language) && 64 89 (x.querystring == y.querystring) && 65 90 (x.search_type == y.search_type) && … … 69 94 } 70 95 71 bool operator!=(const queryparamclass &x, const queryparamclass &y) 72 { 96 bool operator!=(const queryparamclass &x, const queryparamclass &y) { 73 97 return !(x == y); 74 98 } 75 99 76 100 77 ostream &operator<< (ostream &outs, queryparamclass &q) 78 { 101 ostream &operator<< (ostream &outs, queryparamclass &q) { 79 102 outconvertclass text_t2ascii; 80 103 81 104 outs << "*** queryparamclass\n"; 105 outs << text_t2ascii << " combinequery = \"" << q.combinequery << "\"\n"; 82 106 outs << text_t2ascii << " collection = \"" << q.collection << "\"\n"; 83 outs << text_t2ascii << " search_index = \"" << q.search_index << "\"\n"; 107 outs << text_t2ascii << " index = \"" << q.index << "\"\n"; 108 outs << text_t2ascii << " subcollection = \"" << q.subcollection << "\"\n"; 109 outs << text_t2ascii << " language = \"" << q.language << "\"\n"; 84 110 outs << text_t2ascii << " querystring = \"" << q.querystring << "\"\n"; 85 111 outs << " search_type = \"" << q.search_type << "\"\n"; … … 97 123 // term frequencies 98 124 99 termfreqclass &termfreqclass::operator=(const termfreqclass &t) 100 { 125 termfreqclass::termfreqclass () { 126 clear(); 127 } 128 129 void termfreqclass::clear() { 130 termstr.clear(); 131 termstemstr.clear(); 132 utf8equivterms.erase(utf8equivterms.begin(), utf8equivterms.end()); 133 termfreq = 0; 134 } 135 136 termfreqclass &termfreqclass::operator=(const termfreqclass &t) { 101 137 termstr = t.termstr; 102 138 termstemstr = t.termstemstr; … … 107 143 } 108 144 109 bool operator==(const termfreqclass &x, const termfreqclass &y) 110 { 145 bool operator==(const termfreqclass &x, const termfreqclass &y) { 111 146 return ((x.termstr == y.termstr) && 112 147 (x.termstemstr == y.termstemstr) && … … 114 149 } 115 150 116 bool operator!=(const termfreqclass &x, const termfreqclass &y) 117 { 151 bool operator!=(const termfreqclass &x, const termfreqclass &y) { 118 152 return !(x == y); 119 153 } 120 154 121 155 // ordered by termfreq and then by termstr 122 bool operator<(const termfreqclass &x, const termfreqclass &y) 123 { 156 bool operator<(const termfreqclass &x, const termfreqclass &y) { 124 157 return ((x.termfreq < y.termfreq) || 125 158 ((x.termfreq == y.termfreq) && (x.termstemstr < y.termstemstr)) || … … 127 160 } 128 161 129 bool operator>(const termfreqclass &x, const termfreqclass &y) 130 { 162 bool operator>(const termfreqclass &x, const termfreqclass &y) { 131 163 return ((x.termfreq > y.termfreq) || 132 164 ((x.termfreq == y.termfreq) && (x.termstemstr > y.termstemstr)) || … … 135 167 136 168 // stream output for debugging purposes 137 ostream &operator<< (ostream &outs, termfreqclass &t) 138 { 169 ostream &operator<< (ostream &outs, termfreqclass &t) { 139 170 outconvertclass text_t2ascii; 140 171 … … 150 181 // one query result 151 182 183 docresultclass::docresultclass() { 184 clear (); 185 } 186 187 void docresultclass::clear () { 188 docnum=-1; 189 docweight=0.0; 190 num_query_terms_matched=0; 191 num_phrase_match=0; 192 } 193 194 // merges two result classes relating to a single docnum 195 docresultclass &docresultclass::combine(const docresultclass &d) { 196 docweight += d.docweight; // budget! 197 num_query_terms_matched += d.num_query_terms_matched; 198 num_phrase_match += d.num_phrase_match; 199 200 return *this; 201 } 202 203 docresultclass &docresultclass::operator=(const docresultclass &d) { 204 docnum = d.docnum; 205 docweight = d.docweight; 206 num_query_terms_matched = d.num_query_terms_matched; 207 num_phrase_match = d.num_phrase_match; 208 209 return *this; 210 } 211 212 152 213 // stream output for debugging purposes 153 ostream &operator<< (ostream &outs, docresultclass &a) 154 { 214 ostream &operator<< (ostream &outs, docresultclass &a) { 155 215 outs << " d:" << a.docnum << " w:" << a.docweight << "\n"; 156 216 return outs; 157 217 } 218 219 220 221 // many document results 222 223 docresultsclass::docresultsclass () { 224 clear (); 225 } 226 227 void docresultsclass::clear () { 228 docset.erase(docset.begin(), docset.end()); 229 docorder.erase(docorder.begin(), docorder.end()); 230 } 231 232 void docresultsclass::docnum_order() { 233 docorder.erase(docorder.begin(), docorder.end()); 234 235 docresultmap::iterator here = docset.begin(); 236 docresultmap::iterator end = docset.end(); 237 while (here != end) { 238 docorder.push_back ((*here).first); 239 here++; 240 } 241 } 242 243 void docresultsclass::combine_and (const docresultsclass &d) { 244 docorder.erase(docorder.begin(), docorder.end()); 245 246 // put the resulting set in tempresults 247 docresultmap tempresults; 248 249 docresultmap::const_iterator d_here = d.docset.begin(); 250 docresultmap::const_iterator d_end = d.docset.end(); 251 docresultmap::iterator found = docset.end(); 252 while (d_here != d_end) { 253 found = docset.find((*d_here).first); 254 if (found != docset.end()) { 255 (*found).second.combine ((*d_here).second); 256 tempresults[(*found).first] = (*found).second; 257 } 258 d_here++; 259 } 260 261 // then copy it back to docset 262 docset = tempresults; 263 } 264 265 void docresultsclass::combine_or (const docresultsclass &d) { 266 docorder.erase(docorder.begin(), docorder.end()); 267 268 docresultmap::const_iterator d_here = d.docset.begin(); 269 docresultmap::const_iterator d_end = d.docset.end(); 270 docresultmap::iterator found = docset.end(); 271 while (d_here != d_end) { 272 found = docset.find((*d_here).first); 273 if (found != docset.end()) { 274 (*found).second.combine ((*d_here).second); 275 } else { 276 docset[(*d_here).first] = (*d_here).second; 277 } 278 d_here++; 279 } 280 } 281 282 void docresultsclass::combine_not (const docresultsclass &d) { 283 docorder.erase(docorder.begin(), docorder.end()); 284 285 docresultmap::const_iterator d_here = d.docset.begin(); 286 docresultmap::const_iterator d_end = d.docset.end(); 287 docresultmap::iterator found = docset.end(); 288 while (d_here != d_end) { 289 found = docset.find((*d_here).first); 290 if (found != docset.end()) docset.erase (found); 291 d_here++; 292 } 293 } 294 295 docresultsclass &docresultsclass::operator=(const docresultsclass &d) { 296 docset = d.docset; 297 docorder = d.docorder; 298 299 return *this; 300 } 301 158 302 159 303 … … 167 311 postprocessed = false; 168 312 169 docs. erase(docs.begin(),docs.end());313 docs.clear(); 170 314 orgterms.erase(orgterms.begin(),orgterms.end()); 171 315 terms.erase(terms.begin(),terms.end()); … … 186 330 187 331 void queryresultsclass::sortuniqqueryterms() { 188 terms = orgterms; 189 190 // sort the terms 332 vector<termfreqclass> tempterms = orgterms; 333 text_tset seenterms; 334 terms.clear(); 335 336 // sort the terms to get the frequencies in ascending order 337 sort (tempterms.begin(), tempterms.end()); 338 339 // insert first occurance of each term (maximum) 340 vector<termfreqclass>::reverse_iterator here = tempterms.rbegin(); 341 vector<termfreqclass>::reverse_iterator end = tempterms.rend(); 342 while (here != end) { 343 if (seenterms.find((*here).termstr) == seenterms.end()) { 344 // the termstemstr and utf8equivterms might be different for 345 // different occurances of the term 346 (*here).termstemstr.clear(); 347 (*here).utf8equivterms.erase((*here).utf8equivterms.begin(), 348 (*here).utf8equivterms.end()); 349 terms.push_back(*here); 350 seenterms.insert((*here).termstr); 351 } 352 here++; 353 } 354 355 // now re-sort in ascending order 191 356 sort (terms.begin(), terms.end()); 192 193 // and then unique them194 vector<termfreqclass>::iterator new_end = unique (terms.begin(), terms.end());195 terms.erase(new_end, terms.end());196 357 } 197 358 198 359 199 360 // stream output for debugging purposes 200 ostream &operator<< (ostream &outs, queryresultsclass &q) 201 { 361 ostream &operator<< (ostream &outs, queryresultsclass &q) { 202 362 outs << "*** queryresultsclass\n"; 203 363 outs << "docs\n"; 204 364 205 vector<docresultclass>::iterator docshere = q.docs.begin();206 vector<docresultclass>::iterator docsend = q.docs.end();365 docresultmap::iterator docshere = q.docs.docset.begin(); 366 docresultmap::iterator docsend = q.docs.docset.end(); 207 367 while (docshere != docsend) { 208 outs << (*docshere) ;368 outs << (*docshere).second; 209 369 docshere++; 210 370 }
Note:
See TracChangeset
for help on using the changeset viewer.