Tags:
create new tag
view all tags

SID-02077: How to move the format field for a Search into a Topic variable?

Status: Answered 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:

YochaiKunimotoMeunier in use Ae7001
YolandaLMeichle in use Ae6023
YvonneAlmlof    
ZandraFMcCarty    

I guess I was over-thinking it.

-- Richard Williamson - 2015-06-25

      Change status to:
ALERT! 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.
SupportForm
Status Answered
Title How to move the format field for a Search into a Topic variable?
SupportCategory CategorySearch
TWiki version 6.0.1
Server OS Linux twiki 2.6.32-431 x86_64 GNU/Linux
Web server Apache 2.2.15 (Unix)
Perl version 5.10.1
Browser & version Safari 8.0.7 (MacOS client)
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2015-06-25 - RichardWilliamson
 
  • 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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.