Date: Fri, 05 Jan 2001 19:43:00 +0100 From: Peter Stieglecker To: htdig3-dev@htdig.org Subject: [htdig3-dev] [PATCH] htsearch, new CGI params: nohead, startat, stopat Parts/attachments: 1 Shown 30 lines Text 2 1.9 KB Application 3 Shown 4 lines Text ---------------------------------------- Hi List, I hope I am not too rude, but in my attached patch (against htdig-3.2.0b2), I would like to suggest a few additional CGI parameters to htsearch: * nohead: If set to 'true' will immediately start the output of results without any HTTP headers. * startat, stopat: If they are set to integer values, they will override paging (if they are not set, the behaviour is unchanged). Output will start at the requested item (starting at 1) and continue up to stopat. If only one of the parameters is set, the other one will default to 1 for startat, total number of matches for stop at. FIRSTDISPLAYED and LASTDISPLAYED are set accordingly. If both are unset, the behaviour is the same as before. The reason for doing this is I am currently writing a small wrapper for htsearch, to make live easier with our template system. We would like to use our own paging mechanism. The patch is downward compatible, coming to life only when startat and/or stopat are actually used. What I really would _love_ to have, was a Python Module for ht://Dig searches. Does anybody know of any development going into this direction? Regards, Peter -- ________________________________________________________________________ ICAN Internet Services GmbH - www.ican.at www.loq12.at Peter Stieglecker Loquaiplatz 12/1, A-1060 Vienna pstieglecker@ican.at Tel: +43(1) 595 41 24/15 Fax: +43(1) 595 41 24/99 ICQ: 45696226 diff -rup htdig-3.2.0b2.orig/ChangeLog htdig-3.2.0b2.new/ChangeLog --- htdig-3.2.0b2.orig/ChangeLog Wed Apr 12 00:53:09 2000 +++ htdig-3.2.0b2.new/ChangeLog Fri Jan 5 18:54:46 2001 @@ -1,3 +1,16 @@ +Fri Jan 5 18:49:37 2001 Peter Stieglecker + + * htsearch/htsearch.cc: Add boolean CGI parameter nohead that + removes HTTP headers from output. + + * htsearch/Display.cc: Add handling of nohead. + + * htsearch/htsearch.cc: Add integer parameters startat, stopat + that override paging if they are there. They can be used to get + an arbitrary slice of the result list. + + * htsearch/Display.cc: Add handling of startat, stopat. + Tue Apr 11 00:21:48 2000 Geoff Hutchison * htsearch/htsearch.cc (setupWords): Does not apply fuzzy diff -rup htdig-3.2.0b2.orig/htsearch/Display.cc htdig-3.2.0b2.new/htsearch/Display.cc --- htdig-3.2.0b2.orig/htsearch/Display.cc Wed Apr 12 00:53:21 2000 +++ htdig-3.2.0b2.new/htsearch/Display.cc Fri Jan 5 18:31:37 2001 @@ -123,7 +123,17 @@ Display::display(int pageNumber) number = config.Value("matches_per_page"); if (number <= 0) number = 10; - int startAt = (pageNumber - 1) * number; + int startAt = config.Value("start_at"); + if (startAt <= 0) + startAt = (pageNumber - 1) * number; + int stopAt = config.Value("stop_at"); + if (stopAt > 0 && (stopAt >= startAt)) + number = 1 + stopAt - startAt; + else if (startAt > 0) + number = -1; + + if (stopAt > 0 && startAt <= 0) + number = stopAt; if (config.Boolean("logging")) { @@ -131,6 +141,11 @@ Display::display(int pageNumber) } setVariables(pageNumber, matches); + + if (startAt > 0) + startAt--; + if (stopAt > 0) + stopAt--; // // The first match is guaranteed to have the highest score of @@ -144,15 +159,19 @@ Display::display(int pageNumber) // No matches. // delete matches; - if( config.Boolean("nph") ) cout << "HTTP/1.0 200 OK\r\n"; - cout << "Content-type: text/html\r\n\r\n"; + if( !config.Boolean("nohead") ) { + if( config.Boolean("nph") ) cout << "HTTP/1.0 200 OK\r\n"; + cout << "Content-type: text/html\r\n\r\n"; + } displayNomatch(); return; } // maxScore = match->getScore(); // now done in buildMatchList() - if( config.Boolean("nph") ) cout << "HTTP/1.0 200 OK\r\n"; - cout << "Content-type: text/html\r\n\r\n"; + if( !config.Boolean("nohead") ) { + if( config.Boolean("nph") ) cout << "HTTP/1.0 200 OK\r\n"; + cout << "Content-type: text/html\r\n\r\n"; + } String wrap_file = config["search_results_wrapper"]; String *wrapper = 0; char *header = 0, *footer = 0; @@ -199,7 +218,7 @@ Display::display(int pageNumber) matches->Start_Get(); while ((match = (ResultMatch *)matches->Get_Next()) && - numberDisplayed < number) + number < 0 || numberDisplayed < number) { if (currentMatch >= startAt) { @@ -405,6 +424,10 @@ Display::setVariables(int pageNumber, Li int matchesPerPage = config.Value("matches_per_page"); if (matchesPerPage <= 0) matchesPerPage = 10; + + int startAt = config.Value ("start_at"); + int stopAt = config.Value ("stop_at"); + int nPages = (nMatches + matchesPerPage - 1) / matchesPerPage; if (nPages > config.Value("maximum_pages", 10)) @@ -426,9 +449,13 @@ Display::setVariables(int pageNumber, Li vars.Add("PLURAL_MATCHES", new String((nMatches == 1) ? (char *)"" : (const char *) config["plural_suffix"])); vars.Add("PAGE", new String(form("%d", pageNumber))); vars.Add("PAGES", new String(form("%d", nPages))); - vars.Add("FIRSTDISPLAYED", + if (stopAt <= 0 && startAt <= 0) + vars.Add("FIRSTDISPLAYED", new String(form("%d", (pageNumber - 1) * matchesPerPage + 1))); + else + vars.Add("FIRSTDISPLAYED", + new String(form("%d", startAt >= 0 ? startAt : 1))); if (nPages > 1) vars.Add("PAGEHEADER", new String(config["page_list_header"])); else @@ -437,7 +464,11 @@ Display::setVariables(int pageNumber, Li i = pageNumber * matchesPerPage; if (i > nMatches) i = nMatches; - vars.Add("LASTDISPLAYED", new String(form("%d", i))); + + if (stopAt <= 0 && startAt <= 0) + vars.Add("LASTDISPLAYED", new String(form("%d", i))); + else + vars.Add("LASTDISPLAYED", new String(form("%d", (stopAt <= nMatches && stopAt > 0) ? stopAt : nMatches))); if (config["script_name"].length() != 0) { vars.Add("CGI", new String(config["script_name"])); @@ -744,8 +775,11 @@ Display::displayNomatch() void Display::displaySyntaxError(const String& message) { - if( config.Boolean("nph") ) cout << "HTTP/1.0 200 OK\r\n"; - cout << "Content-type: text/html\r\n\r\n"; + + if( !config.Boolean("nohead") ) { + if( config.Boolean("nph") ) cout << "HTTP/1.0 200 OK\r\n"; + cout << "Content-type: text/html\r\n\r\n"; + } setVariables(0, 0); vars.Add("SYNTAXERROR", new String(message)); diff -rup htdig-3.2.0b2.orig/htsearch/htsearch.cc htdig-3.2.0b2.new/htsearch/htsearch.cc --- htdig-3.2.0b2.orig/htsearch/htsearch.cc Wed Apr 12 00:53:21 2000 +++ htdig-3.2.0b2.new/htsearch/htsearch.cc Fri Jan 5 18:31:37 2001 @@ -210,7 +210,13 @@ for (int cInd=0; errorMsg == NULL && cIn if (atoi(input["matchesperpage"]) > 0) config.Add("matches_per_page", input["matchesperpage"]); } + if (input.exists("startat") && atoi(input["startat"]) > 0) + config.Add("start_at", input["startat"]); + if (input.exists("stopat") && atoi(input["stopat"]) > 0) + config.Add("stop_at", input["stopat"]); + if (input.exists("nohead")) + config.Add("nohead", input["nohead"]); if (input.exists("page")) pageNumber = atoi(input["page"]); if (input.exists("config"))