Tags:
archive_me1Add my vote for this tag create new tag
, view all tags
(Moved from FormattedSearch. This is about how to build a custom search form as an alternative to WebSearch, particularly one that requires two or more webs to be searched.)


Richard, could you give me some hints for the quoting ? I have a more simple case. I want to pass an explicit list of webs to a standard search. I tried to modify the search form this way

...
  <input type="radio" name="web" value="all" /> All webs (not only Salesfr web)
  <input type="radio" name="web" value="Salesfr Salesuk Salessp Salesinter" /> All sales webs
  <input type="radio" name="web" value="Salesfr" /> Salesfr only.
...

but the second option doesn't work. Any clues ? Thanks.

-- JeromeBouvattier - 19 Mar 2002

Probably you just need to put \ in front of the double-quotes above, e.g. \"Salesfr .... For a complete example, see how the double-quotes within the A HREF are protected in http://twiki.org/cgi-bin/view/Test/SidebarSearch?raw=on.

The second option is probably failing because your format= string is ending at ...value=", due to lack of backslashes. Try something like:

% SEARCH{"foobar" web="%INCLUDINGWEB%" regex="on" nosearch="on" nototal="on" format="input type=\"radio\" name=\"web\" value=\"Salesfr Salesuk Salessp Salesinter\" /><br />"}%

-- RichardDonkin - 19 Mar 2002

Richard I think I've not been very clear. I know how to escape chars in an inline search. But my concern is with standard HTML search forms like the one you have in WebSearch. My last code sample was an extract of such a form. The problem with the web param passed in the GET, is that I can't find how to manage a list of webs.

A little sample will be more meaningful :

  • Simple search:
    Topic text (body)     Codev only. All webs (not only Salesfr web) Codev and Support only
    Topic name BookView

In this standard search the option "Codev and Support only" won't work. (I have also tried with a POST).

In fact, my very first question was "Can we have a format param in such a form ?". I didn't manage to make it work.

NB : Maybe we're getting off topic here and should migrate this discussion somewhere else ?

-- JeromeBouvattier - 20 Mar 2002

I see what you're trying to do now... I had a quick look at the code for search and lib/TWiki/Search.pm, and they look like they should handle >1 web being passed. I suggest you put in some writeDebug statements to check what is being passed, and see whether the TWiki::Search::search routine is correctly getting the list of webs. You may also need to update this to handle format parameters.

-- RichardDonkin - 20 Mar 2002

Thank you Richard. At least I tried it in the right way wink . I'll try to fix the search routine like you suggested. However I'm not sure I'll succeed in that task since I don't know anything about Perl. We'll see...

-- JeromeBouvattier - 20 Mar 2002

That is a bug. I checked the log file, it records Codev%20Support if you search for the two webs, it should be Codev Support. That is probably also the reason why the format parameter does not work.

-- PeterThoeny - 20 Mar 2002

I modified the code to unescape the CGI params. I also enabled the support for FormattedSearch related params (namely theTemplate, theHeader and format ) that had been forgotten. It seems to work ok but a strong review is welcomed (see why above wink ). I attached the modified unit.

Note : When using the format parameter in an HTML form (typically in a hidden field), you may need to url-encode some chars in order to produce well formed HTML.

-- JeromeBouvattier - 24 Mar 2002

Thanks Jerome for the fix.

The header and format parameters have already been added to TWikiAlphaRelease, see SearchScriptWithFormattedSearch.

It is not necessary to unescape header and format parameters from URL encoding, this has been taken care of by CGI's $query->param.

However, unescaping is needed for the web string since it is based on the raw query string. I did not want to use a call to CGI::Util::unescape as suggested by Jerome's fix since this undocumented call could change.

Fix record

In search script unescape the web string:

    my $websStr = join ' ',
                  grep { s/^web=(.*)$/$1/ }
                  split(/[&;]/, $query->query_string);
    # need to unescape URL-encoded data since we use the raw query_string
    # suggested by JeromeBouvattier
    $websStr =~ tr/+/ /;       # pluses become spaces
    $websStr =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;  # %20 becomes space

Fixed and in TWikiAlphaRelease.

-- PeterThoeny - 24 Mar 2002

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatEXT search r1 manage 4.9 K 2002-03-25 - 01:30 JeromeBouvattier Multi web and FormattedSearch support
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2002-03-25 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.