Changeset 7734 for trunk/gsdl/src/recpt/phindaction.cpp
- Timestamp:
- 2004-07-13T10:57:05+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/phindaction.cpp
r7417 r7734 181 181 182 182 DocNumArray result; 183 find_phrase_number_from_word(basepath, word, result); 183 /** In order to prevent browser crashing problems, any method which 184 * previously suffered a silent fatal error, now instead returns false 185 * to indicate a fatal error has occured. We can then dispatch an 186 * appropriate error tag to the Phind applet (rather than leave it 187 * whiling away the milliseconds until the end of existence - or at 188 * least your browser - in an infinite loop!) 189 * DLConsulting 12-07-2004 190 */ 191 if(!find_phrase_number_from_word(basepath, word, result)) { 192 output_error("phindaction: Fatal Error! Couldn't load index information in find_phrase_number_from_word()", 193 textout, outconvert, disp, logout, XMLmode); 194 return true; 195 } 184 196 185 197 if (result.empty()) { … … 205 217 if (!textdata.LoadData (base, fullpathc)) { 206 218 // FatalError (1, "Couldn't load text information for \"%s\"", fullpathc); 207 exit (0); 219 //exit(0); 220 /** We must return something to the client, whether this error is fatal or 221 * no, otherwise we risk sending their browser into an infinite loop! 222 * DLConsulting 12-07-2004 223 */ 224 output_error("phindaction: Fatal Error! Couldn't load text information for collection", 225 textout, outconvert, disp, logout, XMLmode); 226 return true; 208 227 } 209 228 210 229 delete []fullpathc; 211 230 212 get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el, 213 linkdest, linktype, docNums, docfreq); 231 /** Another previously silent method can now cry out. 232 * DLConsulting 12-07-2004 233 */ 234 if(!get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el, 235 linkdest, linktype, docNums, docfreq)) { 236 output_error( 237 "phindaction: Fatal Error! Couldn't parse phrase in get_phrase_all_data()", 238 textout, outconvert, disp, logout, XMLmode); 239 return true; 240 } 214 241 215 242 // Output the header … … 243 270 << "\" start=\"" << first_l 244 271 << "\" end=\"" << last_l << "\">\n"; 245 print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype, 246 first_l, last_l, disp, outconvert, textout); 272 /** DLConsulting 12-07-2004 */ 273 if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype, 274 first_l, last_l, disp, outconvert, textout)) { 275 output_error( 276 "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()", 277 textout, outconvert, disp, logout, XMLmode); 278 return true; 279 } 247 280 textout << "</thesauruslist>\n"; 248 281 } … … 257 290 258 291 textout << "<p><table border=1><tr><th>type</th><th>topic</th><th>freq</th><th>docs</th></tr>\n"; 259 print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype, 260 first_l, last_l, disp, outconvert, textout); 292 /** DLConsulting 12-07-2004 */ 293 if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype, 294 first_l, last_l, disp, outconvert, textout)) { 295 output_error( 296 "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()", 297 textout, outconvert, disp, logout, XMLmode); 298 return true; 299 } 261 300 textout << "</table>\n"; 262 301 … … 368 407 << "\" end=\"" << last_d << "\">\n"; 369 408 370 print_documents(XMLmode, basepath, args["c"], docNums, docfreq, 371 first_d, last_d, disp, outconvert, textout); 409 if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq, 410 first_d, last_d, disp, outconvert, textout)) { 411 output_error( 412 "phindaction: Fatal Error! Couldn't load text information in print_documents() or get_document_all_data()", 413 textout, outconvert, disp, logout, XMLmode); 414 return true; 415 } 372 416 373 417 textout << "</documentlist>\n"; … … 384 428 385 429 textout << "<p><table border=1><tr><th align=left>document</th><th>freq</th></tr>\n"; 386 print_documents(XMLmode, basepath, args["c"], docNums, docfreq, 387 first_d, last_d, disp, outconvert, textout); 430 if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq, 431 first_d, last_d, disp, outconvert, textout)) { 432 output_error( 433 "phindaction: Fatal Error! Couldn't load text information in print_documents()", 434 textout, outconvert, disp, logout, XMLmode); 435 return true; 436 } 388 437 textout << "</table>\n"; 389 438 … … 430 479 431 480 // Find the phrase number of a word in the index file 432 voidphindaction::find_phrase_number_from_word(const text_t &basepath,481 bool phindaction::find_phrase_number_from_word(const text_t &basepath, 433 482 const text_t &query, 434 483 DocNumArray &result) { … … 447 496 if (!indexData.LoadData (base, fullpathc)) { 448 497 // FatalError (1, "Couldn't load index information for \"%s\"", fullpathc); 449 exit (0); 498 //exit(0); 499 /** Don't handle fatal errors here anymore. 500 * DLConsulting 12-07-2004 501 */ 502 return false; // Indicates something very bad has happened 450 503 } 451 504 … … 478 531 479 532 indexData.UnloadData(); 533 534 /** This method now returns a boolean, so... 535 * DLConsulting 12-07-2004 536 */ 537 return true; // Indicates that what happened is all good, baby. 480 538 } 481 539 … … 492 550 // ll - the list of phrases that are thesaurus links 493 551 // dl - the list of documents that contain phrase 494 voidphindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase,552 bool phindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase, 495 553 text_t &word, unsigned long &tf, unsigned long &ef, 496 554 unsigned long &lf, unsigned long &df, … … 507 565 if (!GetDocText (textdata, docLevel, phrase, text)) { 508 566 // FatalError (1, "Error while trying to get phrase %u", phrase); 509 exit (0); 567 //exit(0); 568 return false; // Something very bad has happened. 510 569 } 511 570 … … 630 689 } 631 690 } 632 } 633 634 void phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode, 691 692 return true; // Indicates that what happened is all good, baby. 693 } 694 695 bool phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode, 635 696 TextData &textdata, vector <unsigned long> &linkdest, 636 697 vector <UCArray> &linktype, unsigned long first, … … 647 708 phrase = linkdest[l]; 648 709 type = linktype[l]; 649 get_phrase_freq_data(textdata, phrase, text, tf, ef, df); 710 711 /** DLConsulting 12-07-2004 */ 712 if(!get_phrase_freq_data(textdata, phrase, text, tf, ef, df)) { 713 return false; 714 } 650 715 651 716 if (XMLmode) { … … 665 730 } 666 731 } 732 733 /** DLConsulting 12-07-2004 */ 734 return true; 667 735 } 668 736 … … 675 743 // ef - the expansion frequency of the phrase 676 744 // df - the document frequency of the phrase 677 void phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase, 745 /** 746 * Returns: 747 * false if the method suffered a fatal error, true otherwise 748 */ 749 bool phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase, 678 750 UCArray &word, unsigned long &tf, 679 751 unsigned long &ef, unsigned long &df) { … … 686 758 if (!GetDocText (textdata, docLevel, phrase, text)) { 687 759 // FatalError (1, "Error while trying to get phrase %u", phrase); 688 exit (0); 760 //exit(0); 761 /** DLConsulting 12-07-2004 */ 762 return false; 689 763 } 690 764 … … 719 793 df += (*next - '0'); 720 794 } 795 796 /** DLConsulting 12-07-2004 */ 797 return true; 721 798 } 722 799 … … 844 921 } 845 922 846 voidphindaction::print_documents(bool XMLmode, const text_t &basepath,923 bool phindaction::print_documents(bool XMLmode, const text_t &basepath, 847 924 const text_t &collection, 848 925 const vector <unsigned long> &docNums, … … 865 942 if (!docdata.LoadData (base, fullpathc)) { 866 943 // FatalError (1, "Couldn't load text information for \"%s\"", fullpathc); 867 exit (0); 944 //exit(0); 945 /** DLConsulting 12-07-2004 */ 946 return false; 868 947 } 869 948 … … 877 956 freq = docFreq[d]; 878 957 879 get_document_all_data(docdata, doc, title, hash); 958 /** DLConsulting 13-07-2004 */ 959 if(!get_document_all_data(docdata, doc, title, hash)) { 960 return false; 961 } 880 962 881 963 if (XMLmode) { … … 894 976 895 977 docdata.UnloadData(); 978 979 /** DLConsulting 12-07-2004 */ 980 return true; 896 981 } 897 982 … … 902 987 // title - the document's title 903 988 // hash - the document's unique OID 904 void phindaction::get_document_all_data(TextData &docdata, unsigned long docNum, 989 /** Returns: 990 * false if a fatal error occured, true otherwise 991 * DLConsulting 12-07-2004 992 */ 993 bool phindaction::get_document_all_data(TextData &docdata, unsigned long docNum, 905 994 UCArray &title, UCArray &hash) { 906 995 … … 912 1001 if (!GetDocText (docdata, docLevel, docNum, text)) { 913 1002 // FatalError (1, "Error while trying to get document %u", docNum); 914 exit (0); 1003 //exit(0); 1004 /** DLConsulting 13-07-2004 */ 1005 return false; 915 1006 } 916 1007 … … 931 1022 title.push_back(*next); 932 1023 } 1024 1025 /** DLConsulting 13-07-2004 */ 1026 return true; 933 1027 } 934 1028 … … 966 1060 967 1061 #endif //GSDL_USE_PHIND_ACTION 1062
Note:
See TracChangeset
for help on using the changeset viewer.