Changeset 7734
- Timestamp:
- 2004-07-13T10:57:05+12:00 (20 years ago)
- Location:
- trunk/gsdl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/java/org/nzdl/gsdl/Phind/Phind.java
r6269 r7734 90 90 91 91 import java.net.Socket; 92 import java.net.SocketTimeoutException; 92 93 import java.net.InetAddress; 93 94 import java.net.UnknownHostException; … … 187 188 // ignored. 188 189 189 190 /** We're adding a timeout to the loop used to read the result from the 191 * server - partially because of the 'fails to return anything' death 192 * spiral - but also because its a good idea anyway. Why DataInputStream 193 * doesn't have a TimeOutException, given its most often used to get data 194 * from a URL, I don't know. Lets default it to 60 seconds. 195 * DLConsulting 12-07-2004 196 */ 197 private int timeout = 60; 198 190 199 public String getAppletInfo() { 191 200 return "Phind by Gordon Paynter ([email protected]). Copyright 1997-2000."; … … 457 466 // Send the query to the phindcgi program 458 467 System.out.println("sending query: " + query); 468 /** Start timeout counter. 469 * DLConsulting 12-07-2004 470 */ 471 int time = 0; 459 472 try { 460 473 URL phindcgi = new URL(query); … … 467 480 if (availableBytes == 0) { 468 481 // if i had threads i'd do a wait here for 1 second 482 /** Ah-ha but we do have threads here - at least one thread 483 * anyway! Note that we want to prevent interrupted 484 * exceptions flinging us out of the read loop. 485 * We also check that the time count hasn't reached out 486 * timeout threshold yet. If so, make use of the nifty 487 * execption handling. 488 * DLConsulting 12-07-2004 489 * Start... 490 */ 491 if(time >= timeout) { 492 throw new SocketTimeoutException( 493 "No data recieved in " + time + 494 " seconds. Connection timed-out."); 495 } 496 try { 497 Thread.sleep(1000); 498 } 499 catch(InterruptedException exception) { 500 System.err.println("Unexpected InterruptedException. Non-fatal."); 501 exception.printStackTrace(); 502 } 503 time++; 504 /** ...End */ 469 505 } else { 470 506 buffer = new byte[availableBytes]; … … 685 721 // expansion_bg = parameterValue("expansion_bg", Color.white); 686 722 // document_bg = parameterValue("document_bg", Color.white); 723 724 /** How long should the read loop wait before timing out? 725 * DLConsulting 12-07-2004 726 */ 727 timeout = parameterValue("timeout", 60); 687 728 } 688 729 … … 917 958 918 959 } 960 -
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 -
trunk/gsdl/src/recpt/phindaction.h
r7371 r7734 45 45 protected: 46 46 47 voidfind_phrase_number_from_word(const text_t &basepath,47 bool find_phrase_number_from_word(const text_t &basepath, 48 48 const text_t &query, 49 49 DocNumArray &result); 50 50 51 voidget_phrase_all_data(TextData &textdata, unsigned long phrase,51 bool get_phrase_all_data(TextData &textdata, unsigned long phrase, 52 52 text_t &word, unsigned long &tf, unsigned long &ef, 53 53 unsigned long &lf, unsigned long &df, … … 58 58 vector <unsigned long> &docfrq); 59 59 60 voidprint_thesaurus_links(const text_t &collection, bool XMLmode,60 bool print_thesaurus_links(const text_t &collection, bool XMLmode, 61 61 TextData &textdata, vector <unsigned long> &linkdest, 62 62 vector <UCArray> &linktype, unsigned long first, … … 64 64 outconvertclass &outconvert, ostream &textout); 65 65 66 voidget_phrase_freq_data(TextData &textdata, unsigned long phrase,66 bool get_phrase_freq_data(TextData &textdata, unsigned long phrase, 67 67 UCArray &word, unsigned long &tf, 68 68 unsigned long &ef, unsigned long &df); … … 81 81 UCArray::const_iterator end); 82 82 83 voidprint_documents(bool XMLmode, const text_t &basepath,83 bool print_documents(bool XMLmode, const text_t &basepath, 84 84 const text_t &collection, 85 85 const vector <unsigned long> &docNums, … … 89 89 ostream &textout); 90 90 91 voidget_document_all_data(TextData &docdata, unsigned long docNum,91 bool get_document_all_data(TextData &docdata, unsigned long docNum, 92 92 UCArray &title, UCArray &hash); 93 93 … … 120 120 #endif //!PHINDACTION_H 121 121 #endif //GSDL_USE_PHIND_ACTION 122
Note:
See TracChangeset
for help on using the changeset viewer.