SID-02077: How to move the format field for a Search into a Topic variable?
| Status: |
Answered |
TWiki version: |
6.0.1 |
Perl version: |
5.10.1 |
| Category: |
CategorySearch |
Server OS: |
Linux twiki 2.6.32-431 x86_64 GNU/Linux |
Last update: |
10 years ago |
I have a topic that has a series of formatted search for topics that match A.*Foo, B.*Foo, etc. Each of these Searches uses the same format="{long, complicated format}".
I would like to use a Topic variable, * set
SearchFormat = {something}, and some form of %SEARCH{.... <SearchFormat> ...}%, rather than having to maintain the same search format ~50 times when ever a change is made to the output format.
--
Richard Williamson - 2015-06-25
Discussion and Answer
Define a variable:
- Set FOO = some complicated text
Then you can use it:
some complicated text (written as
%FOO%)
As many times you wish:
some complicated text
You can also introduced parameters. See
ParameterizedVariables.
As long as you only use the variable in the one topic, and that topic is not included, define the variable in the topic where you use it. Otherwise, define the variable in
WebPreferences of your web, or site-wide at
Main.TWikiPreferences.
--
Peter Thoeny - 2015-06-25
Hi Peter,
I tried that... many, many different iterations of that.
What is the corresponding syntax to use it inside the SEARCH{...} tag? What I'm getting is (one example of many that I've tried, this is by far the simplest):
(raw)
* Set LOC = | $topic | $pattern(.*?NAMEUSED\s+=\s+[ \r]*([^ \r]+).*) | $pattern(.*?LOCATION\s+=\s+[ \r]*([^ \r]+).*) |
Test: <br/>
%SEARCH{"^[XYZ]" scope="topic" nonoise="on" nototal="on" type="regex" format="$percntLOC$percnt"}%
(result)
Test:
| $topic |
$pattern(.*?NAMEUSED\s+=\s+[ \r]*([^ \r]+).*) |
$pattern(.*?LOCATION\s+=\s+[ \r]*([^ \r]+).*) |
|
$topic |
$pattern(.*?NAMEUSED\s+=\s+[ \r]*([^ \r]+).*) |
$pattern(.*?LOCATION\s+=\s+[ \r]*([^ \r]+).*) |
|
$topic |
$pattern(.*?NAMEUSED\s+=\s+[ \r]*([^ \r]+).*) |
$pattern(.*?LOCATION\s+=\s+[ \r]*([^ \r]+).*) |
|
$topic |
$pattern(.*?NAMEUSED\s+=\s+[ \r]*([^ \r]+).*) |
$pattern(.*?LOCATION\s+=\s+[ \r]*([^ \r]+).*) |
--
Richard Williamson - 2015-06-25
Note that in the result, the output is not in tabular format. What you see ^^^ is a result of the comment being parsed differently from the output of the search format.
I need some sort of calculate or eval or if or ... statement that tells the search module to evaluate the %LOC% once, before evaluating the SEARCH{...}.
--
Richard Williamson - 2015-06-25
Stumbled upon the answer.
- Set LOC = format="| $topic | $pattern(.*?NAMEUSED\s+=\s+[ \r]*([^ \r]+).*) | $pattern(.*?LOCATION\s+=\s+[ \r]*([^ \r]+).*) |"
Test:
%SEARCH{"^[XYZ]" scope="topic" nonoise="on" nototal="on" type="regex" %LOC%}%
Result:
Test:
I guess I was over-thinking it.
--
Richard Williamson - 2015-06-25
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.