[opencms-dev] make search engine save

Matthias Neher Matthias.Neher at doubleSlash.de
Tue Oct 11 14:01:28 CEST 2005


Hi list,

I have several problems with the opencms search engine according the query
string.If I insert something like " !!test " I'll get an error <<null>>. ("
?test " works)
Can somebody help me avoiding these errors? I'm testing the query string if
it has at least 3 characters. I do not have more tests. My form method is
post.

Her a snipped of my search form:
[...]
if(request.getParameter("query").length() > 2){
  session.setAttribute("query", request.getParameter("query"));
  response.sendRedirect(response.encodeRedirectURL("searcher.jsp"));
[...]

Here is the code of my search.jsp

 <%
//get the query string from a user input
  String query = (String) session.getAttribute("query");
  if(query == null || "".equals(query))
     throw new Exception("empty query is invalid query");

//which result page should be displayed
  int currentPage;
  String pageNumberStr = request.getParameter("page");
  if(pageNumberStr == null || "".equals(pageNumberStr)){
     currentPage = 1;
  } else {
     currentPage = new Integer(pageNumberStr).intValue();
  }

[...]

// How many matches should be displayed
  searcher.setMatchesPerPage(7);
  searcher.setPage(currentPage);

//the minimum query length
  searcher.setQueryLength(3);

//set the search query
  searcher.setQuery(query);
  List results = searcher.getSearchResult();

  int resultsCount = searcher.getSearchResultCount();
  int resultsPerPage = searcher.getMatchesPerPage();

  int pages= resultsCount / resultsPerPage;
  if ((resultsCount % resultsPerPage) != 0) {
     pages++;
  }

%>

It may help if I could set an error page or something like that. Any idea?


thanks for your help

Matthias

-----------------------------------------------------------------

Matthias Neher                     Fon: +49-7541-6047-143

doubleSlash Net-Business GmbH      Fax: +49-7541-6041-111

Müllerstr. 12 B                    Matthias.Neher at doubleSlash.de

D-88045 Friedrichshafen            http://www.doubleSlash.de

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20051011/be2d88fe/attachment.htm>


More information about the opencms-dev mailing list