Changeset 3322 for trunk/gsdl/src/recpt/documentaction.cpp
- Timestamp:
- 2002-08-05T15:15:18+12:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/documentaction.cpp
r3087 r3322 31 31 #include "unitool.h" 32 32 #include "gsdltools.h" 33 #include "highlighttext.h" 33 34 34 35 documentaction::documentaction () { … … 106 107 107 108 // in this action "hl" is the "highlighting on/ 108 // highlighting off control 109 // highlighting off control ("hl" == "2" is a 110 // special case that forces phrase highlighting 111 // to be used even if the query string doesn't 112 // appear to be a phrase) 109 113 arg_ainfo.shortname = "hl"; 110 114 arg_ainfo.longname = "highlighting on/off"; … … 181 185 // check hl argument 182 186 int arg_hl = args.getintarg("hl"); 183 if (arg_hl != 0 && arg_hl != 1) {187 if (arg_hl < 0 || arg_hl > 2) { 184 188 logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n"; 185 189 cgiarginfo *hlinfo = argsinfo.getarginfo ("hl"); … … 782 786 text_t &collection, recptproto *collectproto, 783 787 displayclass &disp, outconvertclass &outconvert, 784 ostream &textout, ostream &logout) { 788 ostream &textout, ostream &logout, 789 cgiargsclass &args) { 785 790 786 791 DocumentRequest_t docrequest; … … 798 803 // (wanttext will equal 2 if we want text and other stuff too) 799 804 if (wanttext == 1) 800 if (highlight) 801 highlighttext(docresponse.doc, terminfo, disp, outconvert, textout, logout);802 else805 if (highlight) { 806 highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout); 807 } else { 803 808 textout << outconvert << disp << docresponse.doc; 809 } 804 810 } 805 811 806 812 if (wanttext != 1) { 807 813 text_t doctext 808 809 810 814 = get_formatted_string (collection, collectproto, 815 docinfo, disp, formatlistptr, docresponse.doc, 816 logout); 811 817 812 if (highlight) 813 highlighttext(doctext, terminfo, disp, outconvert, textout, logout);814 else818 if (highlight) { 819 highlighttext(doctext, args, terminfo, disp, outconvert, textout); 820 } else { 815 821 textout << outconvert << disp << doctext; 822 } 816 823 } 817 824 } … … 876 883 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo, 877 884 OID, highlight, hastxt, wanttext, collection, collectproto, 878 disp, outconvert, textout, logout );885 disp, outconvert, textout, logout, args); 879 886 880 887 … … 919 926 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo, 920 927 OID, highlight, hastxt, wanttext, collection, 921 collectproto, disp, outconvert, textout, logout );928 collectproto, disp, outconvert, textout, logout, args); 922 929 923 930 } … … 936 943 output_text (*sechere, formatlistptr, queryresponse.termInfo, 937 944 (*sechere).OID, highlight, shastxt, wanttext, collection, 938 collectproto, disp, outconvert, textout, logout );945 collectproto, disp, outconvert, textout, logout, args); 939 946 count ++; 940 947 sechere ++; … … 945 952 delete formatlistptr; 946 953 } 947 948 // highlighttext highlights query terms in text string and outputs the resulting text string949 void documentaction::highlighttext(text_t &text, const TermInfo_tarray &terms,950 displayclass &disp, outconvertclass &outconvert,951 ostream &textout, ostream &/*logout*/) {952 953 text_tmap allterms;954 text_tmap::const_iterator it;955 956 // first load all the term variations into a map957 TermInfo_tarray::const_iterator this_term = terms.begin();958 TermInfo_tarray::const_iterator last_term = terms.end();959 while (this_term != last_term) {960 text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();961 text_tarray::const_iterator last_var = (*this_term).matchTerms.end();962 while (this_var != last_var) {963 allterms[*this_var] = 1;964 this_var ++;965 }966 this_term ++;967 }968 969 // get the text to start and end a hightlight970 text_t starthighlight = "<b><u>";971 text_t endhighlight = "</u></b>";972 if (disp.isdefaultmacro("Global", "starthighlight"))973 disp.expandstring("Global", "_starthighlight_", starthighlight);974 if (disp.isdefaultmacro("Global", "endhighlight"))975 disp.expandstring("Global", "_endhighlight_", endhighlight);976 977 978 text_t::iterator here = text.begin();979 text_t::iterator end = text.end();980 text_t word, buffer;981 while (here != end) {982 if (is_unicode_letdig(*here)) {983 // not word boundary984 word.push_back(*here);985 here++;986 987 } else {988 // found word boundary989 // add last word if there was one990 if (!word.empty()) {991 it = allterms.find(word);992 if (it != allterms.end()) {993 word = starthighlight + word + endhighlight;994 }995 buffer += word;996 word.clear();997 }998 999 if (*here == '<') {1000 // skip over rest of html tag1001 while ((here != end) && (*here != '>')) {1002 buffer.push_back(*here);1003 here++;1004 }1005 }1006 1007 buffer.push_back(*here);1008 here++;1009 1010 if (buffer.size() > 1024) {1011 textout << outconvert << disp << buffer;1012 buffer.clear();1013 }1014 }1015 }1016 textout << outconvert << disp << buffer;1017 }
Note:
See TracChangeset
for help on using the changeset viewer.