Question
I have several searches on my web that are checking if a topic is created within a date range that is submitted by the user as a from, to pair. The search is getting run when the page loads, before any dates are entered, and no results are normally displayed. The from and to dates are being run thru the TIME function to get the serialized version then used in the search. I came accross a topic that was being returned before any dates were submitted. I checked and the variables are in fact starting with some values. I would like to know if there is a way to either delay the search being run until the date range is submitted, or zero the variables until then.
Environment
--
MatthewCardozo - 02 Aug 2006
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
I have not tried this, but you probably can supply a hidden field to enable the search, such as
<input type="hidden" name="p" value="%">. Use it to make a complete SEARCH, such as:
%URLPARAM{ "p" default="<!--" }%SEARCH{....}%URLPARAM{ "p" default="-->" }%
So, when you initially look at the query page, the
p paramter is missing, and the default URL param is used, which comments out the SEARCH, resulting in this output:
<!--SEARCH{....}-->
BTW, could you share with us your date range based query? I think this is something some people may find useful for specific
TWikiApplications.
--
PeterThoeny - 04 Aug 2006
I really like that idea in theory

Alas, it didn't work. I tried a few different ways to make a % but no luck. As for my date range search...I'd be glad to share it. I'm sure it's not the best way to do it, but it works.
%CALC{$SET(fromDate, $TIME(%URLPARAM{fromDate}%)) $SET(toDate, $TIMEADD($TIME(%URLPARAM{toDate}%), 1, day))}%
%SEARCH{"*" scope="text" regex="on" nosearch="on" expandvariables="on" zeroresults="off" format="$percntCALC{$SET(created, $createdate) $SET(createSer, $TIME($GET(created))) $IF($GET(fromDate) < $GET(createSer), $SET(from, 1), $SET(from, 5)) $IF($GET(toDate) > $GET(createSer), $SET(to, 1), $SET(to, 6)) $IF($GET(from) == $GET(to), $SET(show, 1), $SET(show, 0)) $IF($GET(show) == 1, <results formatting here>, <nop>)}$percnt"}%
The fromDate and toDate are pulled from the html form using the jscalendar
--
MatthewCardozo - 04 Aug 2006
oh, the other thing I noticed along the way with those conditional results, is that if you use the format:
$IF(this, <formatted results>, <nop>)
you can't use commas in your formatted results, like from formfields. Switching the
<formatted results>
and the
<nop>
, and reversing your logic accordingly, bybasses that problem.
--
MatthewCardozo - 04 Aug 2006
Thanks for sharing your query.
I just tested out the delayed search, it works. See
Sandbox.DelayedSearch.
--
PeterThoeny - 05 Aug 2006
Well darn. There must have been something else going on with my search that was messing it up then. I came up with another possible way to do this as well. One page with the html form and a hidden field containing the name of the page with the search. The page with the html form would also include a
%INCLUDE{%URLPARAM{searchpage}%}% I haven't tried it yet. But the idea seems sound, to me
I'll mess with the URLPARAM for the % a little more to see if i can't figure out why mine wasn't working.
--
MatthewCardozo - 05 Aug 2006
I actually tried copying the
DelayedSearch over to my TWiki but was unable to get it to work. I'm still looking in to what might be preventing it from working. Any ideas would be appreciated.
--
MatthewCardozo - 07 Aug 2006
Hmm, not sure. Are you really running TWiki 4? Also, check the query string after submitting a query, it should be
q=SearchedStuff&p=%25 (that is, the percent sign should be URL encoded as
%25.
--
PeterThoeny - 07 Aug 2006
Just what I needed. Yippee.
--
VickiBrown - 19 Dec 2007
I found another way of accomplishing this...
We actually have a page now that has five or six different searches defined. Based on the users input, we want to run one or two of them, but not all.
In this case we defined the searches in user variables without the opening and closing %'s. When the page is reloaded with the users input, we use the
%IF{...}% to add either opening % or an html comment. We do the same at the end of the variable to get the closing % or html comment....
- #Set USERSEARCH = SEARCH{"search" type="" nonoise="on" format=".."}
%IF{"defined uservar" then="%" else="<!--"}%%USERSEARCH%%IF{"defined uservar" then="%" else="-->"}%
We do an
%IF{...}% line for each of the searches, allowing us to show and expand the searches as needed.
Hope this help someone.
--
MatthewCardozo - 24 Oct 2008